27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $module =
'bookcal';
44 public $element =
'calendar';
49 public $table_element =
'bookcal_calendar';
55 public $ismultientitymanaged = 0;
60 public $isextrafieldmanaged = 1;
65 public $picto =
'fa-file';
68 const STATUS_DRAFT = 0;
69 const STATUS_VALIDATED = 1;
70 const STATUS_CANCELED = 9;
116 public $fields=array(
117 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>1,
'notnull'=>1,
'visible'=>0,
'noteditable'=>
'1',
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
118 'ref' => array(
'type'=>
'varchar(128)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>20,
'notnull'=>1,
'visible'=>1,
'index'=>1,
'searchall'=>1,
'showoncombobox'=>
'1',
'validate'=>
'1',
'comment'=>
"Reference of object"),
119 'label' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>
'1',
'position'=>30,
'notnull'=>0,
'visible'=>1,
'alwayseditable'=>
'1',
'searchall'=>1,
'css'=>
'minwidth300',
'cssview'=>
'wordbreak',
'help'=>
"Help text",
'showoncombobox'=>
'2',
'validate'=>
'1',),
120 'fk_soc' => array(
'type'=>
'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))',
'label'=>
'ThirdParty',
'picto'=>
'company',
'enabled'=>
'isModEnabled("societe")',
'position'=>50,
'notnull'=>-1,
'visible'=>1,
'index'=>1,
'css'=>
'maxwidth500 widthcentpercentminusxx',
'csslist'=>
'tdoverflowmax150',
'help'=>
"OrganizationEventLinkToThirdParty",
'validate'=>
'1',),
121 'fk_project' => array(
'type'=>
'integer:Project:projet/class/project.class.php:1',
'label'=>
'Project',
'picto'=>
'project',
'enabled'=>
'isModEnabled("project")',
'position'=>52,
'notnull'=>-1,
'visible'=>-1,
'index'=>1,
'css'=>
'maxwidth500 widthcentpercentminusxx',
'csslist'=>
'tdoverflowmax150',
'validate'=>
'1',),
122 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>
'1',
'position'=>60,
'notnull'=>0,
'visible'=>3,
'validate'=>
'1',),
123 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>
'1',
'position'=>61,
'notnull'=>0,
'visible'=>0,
'cssview'=>
'wordbreak',
'validate'=>
'1',),
124 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>
'1',
'position'=>62,
'notnull'=>0,
'visible'=>0,
'cssview'=>
'wordbreak',
'validate'=>
'1',),
125 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>500,
'notnull'=>1,
'visible'=>-2,),
126 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>
'1',
'position'=>501,
'notnull'=>0,
'visible'=>-2,),
127 'fk_user_creat' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'picto'=>
'user',
'enabled'=>
'1',
'position'=>510,
'notnull'=>1,
'visible'=>-2,
'foreignkey'=>
'user.rowid',
'csslist'=>
'tdoverflowmax150',),
128 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'picto'=>
'user',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>-2,
'csslist'=>
'tdoverflowmax150',),
129 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>-1,
'visible'=>-2,),
130 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'enabled'=>
'1',
'position'=>2000,
'notnull'=>1,
'visible'=>1,
'index'=>1,
'arrayofkeyval'=>array(
'0'=>
'Brouillon',
'1'=>
'Validé',
'9'=>
'Annulé'),
'validate'=>
'1',),
139 public $note_private;
140 public $date_creation;
142 public $fk_user_creat;
143 public $fk_user_modif;
192 global $conf, $langs;
196 if (!
getDolGlobalInt(
'MAIN_SHOW_TECHNICAL_ID') && isset($this->fields[
'rowid']) && !empty($this->fields[
'ref'])) {
197 $this->fields[
'rowid'][
'visible'] = 0;
199 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
200 $this->fields[
'entity'][
'enabled'] = 0;
210 foreach ($this->fields as $key => $val) {
211 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
212 unset($this->fields[$key]);
217 if (is_object($langs)) {
218 foreach ($this->fields as $key => $val) {
219 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
220 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
221 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
241 return $resultcreate;
253 global $langs, $extrafields;
258 $object =
new self($this->db);
263 $result = $object->fetchCommon($fromid);
264 if ($result > 0 && !empty($object->table_element_line)) {
265 $object->fetchLines();
274 unset($object->fk_user_creat);
275 unset($object->import_key);
278 if (property_exists($object,
'ref')) {
279 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
281 if (property_exists($object,
'label')) {
282 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
284 if (property_exists($object,
'status')) {
285 $object->status = self::STATUS_DRAFT;
287 if (property_exists($object,
'date_creation')) {
288 $object->date_creation =
dol_now();
290 if (property_exists($object,
'date_modification')) {
291 $object->date_modification =
null;
295 if (is_array($object->array_options) && count($object->array_options) > 0) {
296 $extrafields->fetch_name_optionals_label($this->table_element);
297 foreach ($object->array_options as $key => $option) {
298 $shortkey = preg_replace(
'/options_/',
'', $key);
299 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
302 unset($object->array_options[$key]);
308 $object->context[
'createfromclone'] =
'createfromclone';
309 $result = $object->createCommon($user);
324 if (!empty($object->socid) && property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
331 unset($object->context[
'createfromclone']);
338 $this->db->rollback();
350 public function fetch($id, $ref =
null)
353 if ($result > 0 && !empty($this->table_element_line)) {
366 $this->lines = array();
384 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
394 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
395 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
396 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
398 $sql .=
" WHERE 1 = 1";
402 if (count($filter) > 0) {
403 foreach ($filter as $key => $value) {
404 if ($key ==
't.rowid') {
405 $sqlwhere[] = $key.
" = ".((int) $value);
406 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
407 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
408 } elseif ($key ==
'customsql') {
409 $sqlwhere[] = $value;
410 } elseif (strpos($value,
'%') ===
false) {
411 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
413 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
417 if (count($sqlwhere) > 0) {
418 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
421 if (!empty($sortfield)) {
422 $sql .= $this->db->order($sortfield, $sortorder);
424 if (!empty($limit)) {
425 $sql .= $this->db->plimit($limit, $offset);
428 $resql = $this->db->query(
$sql);
430 $num = $this->db->num_rows($resql);
432 while ($i < ($limit ? min($limit, $num) : $num)) {
433 $obj = $this->db->fetch_object($resql);
435 $record =
new self($this->db);
436 $record->setVarsFromFetchObj($obj);
438 $records[$record->id] = $record;
442 $this->db->free($resql);
446 $this->errors[] =
'Error '.$this->db->lasterror();
447 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
472 public function delete(
User $user, $notrigger =
false)
488 if ($this->status < 0) {
489 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
506 global $conf, $langs;
508 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
513 if ($this->status == self::STATUS_VALIDATED) {
514 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
531 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
536 $this->newref = $num;
540 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
541 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
542 $sql .=
" status = ".self::STATUS_VALIDATED;
543 if (!empty($this->fields[
'date_validation'])) {
544 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
546 if (!empty($this->fields[
'fk_user_valid'])) {
547 $sql .=
", fk_user_valid = ".((int) $user->id);
549 $sql .=
" WHERE rowid = ".((int) $this->
id);
551 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
552 $resql = $this->db->query(
$sql);
555 $this->error = $this->db->lasterror();
559 if (!$error && !$notrigger) {
561 $result = $this->
call_trigger(
'MYOBJECT_VALIDATE', $user);
570 $this->oldref = $this->ref;
573 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
575 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'calendar/".$this->db->escape($this->newref).
"'";
576 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'calendar/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
577 $resql = $this->db->query(
$sql);
579 $error++; $this->error = $this->db->lasterror();
585 $dirsource = $conf->bookcal->dir_output.
'/calendar/'.$oldref;
586 $dirdest = $conf->bookcal->dir_output.
'/calendar/'.$newref;
587 if (!$error && file_exists($dirsource)) {
588 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
590 if (@rename($dirsource, $dirdest)) {
593 $listoffiles =
dol_dir_list($conf->bookcal->dir_output.
'/calendar/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
594 foreach ($listoffiles as $fileentry) {
595 $dirsource = $fileentry[
'name'];
596 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
597 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
598 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
599 @rename($dirsource, $dirdest);
609 $this->status = self::STATUS_VALIDATED;
616 $this->db->rollback();
632 if ($this->status <= self::STATUS_DRAFT) {
643 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'MYOBJECT_UNVALIDATE');
653 public function cancel($user, $notrigger = 0)
656 if ($this->status != self::STATUS_VALIDATED) {
667 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'MYOBJECT_CANCEL');
677 public function reopen($user, $notrigger = 0)
680 if ($this->status == self::STATUS_VALIDATED) {
691 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'MYOBJECT_REOPEN');
703 global $conf, $langs;
708 return [
'optimize' => $langs->trans(
"ShowCalendar")];
710 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Calendar").
'</u>';
711 if (isset($this->status)) {
712 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
714 $datas[
'ref'] .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
729 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
731 global $conf, $langs, $hookmanager;
733 if (!empty($conf->dol_no_mouse_hover)) {
740 'objecttype' => $this->element.($this->module ?
'@'.$this->module :
''),
743 $classfortooltip =
'classfortooltip';
746 $classfortooltip =
'classforajaxtooltip';
747 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
753 $url =
dol_buildpath(
'/bookcal/calendar_card.php', 1).
'?id='.$this->id;
755 if ($option !==
'nolink') {
757 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
758 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
759 $add_save_lastsearch_values = 1;
761 if ($url && $add_save_lastsearch_values) {
762 $url .=
'&save_lastsearch_values=1';
767 if (empty($notooltip)) {
769 $label = $langs->trans(
"ShowCalendar");
770 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
772 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
773 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
775 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
778 if ($option ==
'nolink' || empty($url)) {
779 $linkstart =
'<span';
781 $linkstart =
'<a href="'.$url.
'"';
783 $linkstart .= $linkclose.
'>';
784 if ($option ==
'nolink' || empty($url)) {
785 $linkend =
'</span>';
790 $result .= $linkstart;
792 if (empty($this->showphoto_on_popup)) {
794 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
798 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
800 list($class, $module) = explode(
'@', $this->picto);
803 $filename = $filearray[0][
'name'];
804 if (!empty($filename)) {
805 $pospoint = strpos($filearray[0][
'name'],
'.');
807 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
808 if (!
getDolGlobalInt(strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS')) {
809 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.
'" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div></div>';
811 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div>';
816 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
821 if ($withpicto != 2) {
822 $result .= $this->ref;
828 global $action, $hookmanager;
829 $hookmanager->initHooks(array($this->element.
'dao'));
830 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
831 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
833 $result = $hookmanager->resPrint;
835 $result .= $hookmanager->resPrint;
850 global $conf, $langs;
852 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
854 $return =
'<div class="box-flex-item box-flex-grow-zero">';
855 $return .=
'<div class="info-box info-box-sm">';
856 $return .=
'<span class="info-box-icon bg-infobox-action">';
858 $return .=
'</span>';
859 $return .=
'<div class="info-box-content">';
860 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
861 if ($selected >= 0) {
862 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
864 if (property_exists($this,
'label')) {
865 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
867 if (property_exists($this,
'amount')) {
869 $return .=
'<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span>';
871 if (method_exists($this,
'getLibStatut')) {
872 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
889 return $this->
LibStatut($this->status, $mode);
900 return $this->
LibStatut($this->status, $mode);
914 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
917 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
918 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
919 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
920 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
921 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
922 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
925 $statusType =
'status'.$status;
927 if ($status == self::STATUS_CANCELED) {
928 $statusType =
'status6';
931 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
942 $sql =
"SELECT rowid,";
943 $sql .=
" date_creation as datec, tms as datem,";
944 $sql .=
" fk_user_creat, fk_user_modif";
945 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
946 $sql .=
" WHERE t.rowid = ".((int) $id);
948 $result = $this->db->query(
$sql);
950 if ($this->db->num_rows($result)) {
951 $obj = $this->db->fetch_object($result);
953 $this->
id = $obj->rowid;
955 $this->user_creation_id = $obj->fk_user_creat;
956 $this->user_modification_id = $obj->fk_user_modif;
957 if (!empty($obj->fk_user_valid)) {
958 $this->user_validation_id = $obj->fk_user_valid;
960 $this->date_creation = $this->db->jdate($obj->datec);
961 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
962 if (!empty($obj->datev)) {
963 $this->date_validation = empty($obj->datev) ?
'' : $this->db->jdate($obj->datev);
967 $this->db->free($result);
995 $this->lines = array();
998 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_calendar = '.((
int) $this->
id)));
1000 if (is_numeric($result)) {
1004 $this->lines = $result;
1005 return $this->lines;
1016 global $langs, $conf;
1017 $langs->load(
"bookcal@bookcal");
1020 $conf->global->BOOKCAL_MYOBJECT_ADDON =
'mod_calendar_standard';
1030 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1031 foreach ($dirmodels as $reldir) {
1035 $mybool |= @include_once $dir.$file;
1038 if ($mybool ===
false) {
1043 if (class_exists($classname)) {
1044 $obj =
new $classname();
1045 $numref = $obj->getNextValue($this);
1047 if ($numref !=
'' && $numref !=
'-1') {
1050 $this->error = $obj->error;
1055 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
1059 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1075 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1077 global $conf, $langs;
1080 $includedocgeneration = 0;
1082 $langs->load(
"bookcal@bookcal");
1085 $modele =
'standard_calendar';
1087 if (!empty($this->model_pdf)) {
1088 $modele = $this->model_pdf;
1094 $modelpath =
"core/modules/bookcal/doc/";
1096 if ($includedocgeneration && !empty($modele)) {
1097 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1128 $this->db->commit();
1135 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1148 public $isextrafieldmanaged = 0;