26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $module =
'bookcal';
43 public $element =
'booking';
48 public $table_element =
'bookcal_booking';
54 public $ismultientitymanaged = 0;
59 public $isextrafieldmanaged = 1;
64 public $picto =
'fa-file';
67 const STATUS_DRAFT = 0;
68 const STATUS_VALIDATED = 1;
69 const STATUS_CANCELED = 9;
104 public $fields=array(
105 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>1,
'notnull'=>1,
'visible'=>0,
'noteditable'=>
'1',
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
106 'ref' => array(
'type'=>
'varchar(128)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>1.2,
'notnull'=>1,
'visible'=>1,
'index'=>1,
'searchall'=>1,
'validate'=>
'1',
'comment'=>
"Reference of object"),
107 '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',
'help'=>
"LinkToThirparty",
'validate'=>
'1',),
108 'fk_project' => array(
'type'=>
'integer:Project:projet/class/project.class.php:1',
'label'=>
'Project',
'picto'=>
'project',
'enabled'=>
'$conf->project->enabled',
'position'=>52,
'notnull'=>-1,
'visible'=>-1,
'index'=>1,
'css'=>
'maxwidth500 widthcentpercentminusxx',
'validate'=>
'1',),
109 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>
'1',
'position'=>60,
'notnull'=>0,
'visible'=>3,
'validate'=>
'1',),
110 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>
'1',
'position'=>61,
'notnull'=>0,
'visible'=>0,
'cssview'=>
'wordbreak',
'validate'=>
'1',),
111 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>
'1',
'position'=>62,
'notnull'=>0,
'visible'=>0,
'cssview'=>
'wordbreak',
'validate'=>
'1',),
112 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>500,
'notnull'=>1,
'visible'=>-2,),
113 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>
'1',
'position'=>501,
'notnull'=>0,
'visible'=>-2,),
114 'fk_user_creat' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>
'1',
'position'=>510,
'notnull'=>-1,
'visible'=>-2,),
115 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'picto'=>
'user',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>-2,),
116 'last_main_doc' => array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>
'1',
'position'=>600,
'notnull'=>0,
'visible'=>0,),
117 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>-1,
'visible'=>-2,),
118 'model_pdf' => array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>
'1',
'position'=>1010,
'notnull'=>-1,
'visible'=>0,),
119 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'enabled'=>
'1',
'position'=>2000,
'notnull'=>1,
'visible'=>1,
'index'=>1,
'arrayofkeyval'=>array(
'0'=>
'Draft',
'1'=>
'Validated',
'9'=>
'Canceled'),
'validate'=>
'1',),
120 'firstname' => array(
'type'=>
'varchar(128)',
'label'=>
'firstname',
'enabled'=>
'1',
'position'=>2,
'notnull'=>1,
'visible'=>-1,),
121 'lastname' => array(
'type'=>
'varchar(128)',
'label'=>
'lastname',
'enabled'=>
'1',
'position'=>3,
'notnull'=>1,
'visible'=>-1,),
122 'email' => array(
'type'=>
'varchar(128)',
'label'=>
'email',
'enabled'=>
'1',
'position'=>4,
'notnull'=>1,
'visible'=>-1,),
123 'start' => array(
'type'=>
'datetime',
'label'=>
'Start Hour',
'enabled'=>
'1',
'position'=>5,
'notnull'=>1,
'visible'=>-1,),
124 'duration' => array(
'type'=>
'integer',
'label'=>
'Duration',
'enabled'=>
'1',
'position'=>6,
'notnull'=>1,
'visible'=>-1,),
125 'fk_bookcal_availability' => array(
'type'=>
'integer:Availabilities:bookcal/class/availabilities.class.php',
'label'=>
'AvailabilityId',
'enabled'=>
'1',
'position'=>49,
'notnull'=>1,
'visible'=>-1,),
133 public $note_private;
134 public $date_creation;
136 public $fk_user_creat;
137 public $fk_user_modif;
138 public $last_main_doc;
147 public $fk_bookcal_availability;
194 global $conf, $langs;
198 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid']) && !empty($this->fields[
'ref'])) {
199 $this->fields[
'rowid'][
'visible'] = 0;
201 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
202 $this->fields[
'entity'][
'enabled'] = 0;
212 foreach ($this->fields as $key => $val) {
213 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
214 unset($this->fields[$key]);
219 if (is_object($langs)) {
220 foreach ($this->fields as $key => $val) {
221 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
222 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
223 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
243 return $resultcreate;
255 global $langs, $extrafields;
260 $object =
new self($this->db);
265 $result = $object->fetchCommon($fromid);
266 if ($result > 0 && !empty($object->table_element_line)) {
267 $object->fetchLines();
276 unset($object->fk_user_creat);
277 unset($object->import_key);
280 if (property_exists($object,
'ref')) {
281 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
283 if (property_exists($object,
'label')) {
284 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
286 if (property_exists($object,
'status')) {
287 $object->status = self::STATUS_DRAFT;
289 if (property_exists($object,
'date_creation')) {
290 $object->date_creation =
dol_now();
292 if (property_exists($object,
'date_modification')) {
293 $object->date_modification =
null;
297 if (is_array($object->array_options) && count($object->array_options) > 0) {
298 $extrafields->fetch_name_optionals_label($this->table_element);
299 foreach ($object->array_options as $key => $option) {
300 $shortkey = preg_replace(
'/options_/',
'', $key);
301 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
304 unset($object->array_options[$key]);
310 $object->context[
'createfromclone'] =
'createfromclone';
311 $result = $object->createCommon($user);
314 $this->error = $object->error;
315 $this->errors = $object->errors;
327 if (!empty($object->socid) && property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
334 unset($object->context[
'createfromclone']);
341 $this->db->rollback();
353 public function fetch($id, $ref =
null)
356 if ($result > 0 && !empty($this->table_element_line)) {
369 $this->lines = array();
387 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
397 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
398 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
399 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
401 $sql .=
" WHERE 1 = 1";
405 if (count($filter) > 0) {
406 foreach ($filter as $key => $value) {
407 if ($key ==
't.rowid') {
408 $sqlwhere[] = $key.
" = ".((int) $value);
409 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
410 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
411 } elseif ($key ==
'customsql') {
412 $sqlwhere[] = $value;
413 } elseif (strpos($value,
'%') ===
false) {
414 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
416 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
420 if (count($sqlwhere) > 0) {
421 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
424 if (!empty($sortfield)) {
425 $sql .= $this->db->order($sortfield, $sortorder);
427 if (!empty($limit)) {
428 $sql .= $this->db->plimit($limit, $offset);
431 $resql = $this->db->query(
$sql);
433 $num = $this->db->num_rows($resql);
435 while ($i < ($limit ? min($limit, $num) : $num)) {
436 $obj = $this->db->fetch_object($resql);
438 $record =
new self($this->db);
439 $record->setVarsFromFetchObj($obj);
441 $records[$record->id] = $record;
445 $this->db->free($resql);
449 $this->errors[] =
'Error '.$this->db->lasterror();
450 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
475 public function delete(
User $user, $notrigger =
false)
491 if ($this->status < 0) {
492 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
509 global $conf, $langs;
511 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
516 if ($this->status == self::STATUS_VALIDATED) {
517 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
534 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
539 $this->newref = $num;
543 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
544 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
545 $sql .=
" status = ".self::STATUS_VALIDATED;
546 if (!empty($this->fields[
'date_validation'])) {
547 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
549 if (!empty($this->fields[
'fk_user_valid'])) {
550 $sql .=
", fk_user_valid = ".((int) $user->id);
552 $sql .=
" WHERE rowid = ".((int) $this->
id);
554 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
555 $resql = $this->db->query(
$sql);
558 $this->error = $this->db->lasterror();
562 if (!$error && !$notrigger) {
564 $result = $this->
call_trigger(
'BOOKING_VALIDATE', $user);
573 $this->oldref = $this->ref;
576 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
578 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'booking/".$this->db->escape($this->newref).
"'";
579 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'booking/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
580 $resql = $this->db->query(
$sql);
582 $error++; $this->error = $this->db->lasterror();
588 $dirsource = $conf->bookcal->dir_output.
'/booking/'.$oldref;
589 $dirdest = $conf->bookcal->dir_output.
'/booking/'.$newref;
590 if (!$error && file_exists($dirsource)) {
591 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
593 if (@rename($dirsource, $dirdest)) {
596 $listoffiles =
dol_dir_list($conf->bookcal->dir_output.
'/booking/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
597 foreach ($listoffiles as $fileentry) {
598 $dirsource = $fileentry[
'name'];
599 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
600 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
601 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
602 @rename($dirsource, $dirdest);
612 $this->status = self::STATUS_VALIDATED;
619 $this->db->rollback();
635 if ($this->status <= self::STATUS_DRAFT) {
646 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'BOOKING_UNVALIDATE');
656 public function cancel($user, $notrigger = 0)
659 if ($this->status != self::STATUS_VALIDATED) {
670 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'BOOKING_CANCEL');
680 public function reopen($user, $notrigger = 0)
683 if ($this->status != self::STATUS_CANCELED) {
694 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'BOOKING_REOPEN');
707 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
709 global $conf, $langs, $hookmanager;
711 if (!empty($conf->dol_no_mouse_hover)) {
717 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Booking").
'</u>';
718 if (isset($this->status)) {
719 $label .=
' '.$this->getLibStatut(5);
722 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
724 $url =
dol_buildpath(
'/bookcal/booking_card.php', 1).
'?id='.$this->id;
726 if ($option !=
'nolink') {
728 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
729 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
730 $add_save_lastsearch_values = 1;
732 if ($url && $add_save_lastsearch_values) {
733 $url .=
'&save_lastsearch_values=1';
738 if (empty($notooltip)) {
739 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
740 $label = $langs->trans(
"ShowBooking");
741 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
743 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
744 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
746 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
749 if ($option ==
'nolink' || empty($url)) {
750 $linkstart =
'<span';
752 $linkstart =
'<a href="'.$url.
'"';
754 $linkstart .= $linkclose.
'>';
755 if ($option ==
'nolink' || empty($url)) {
756 $linkend =
'</span>';
761 $result .= $linkstart;
763 if (empty($this->showphoto_on_popup)) {
765 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
769 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
771 list($class, $module) = explode(
'@', $this->picto);
774 $filename = $filearray[0][
'name'];
775 if (!empty($filename)) {
776 $pospoint = strpos($filearray[0][
'name'],
'.');
778 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
780 $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>';
782 $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>';
787 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
792 if ($withpicto != 2) {
793 $result .= $this->ref;
799 global $action, $hookmanager;
800 $hookmanager->initHooks(array(
'bookingdao'));
801 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
802 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
804 $result = $hookmanager->resPrint;
806 $result .= $hookmanager->resPrint;
820 return $this->
LibStatut($this->status, $mode);
831 return $this->
LibStatut($this->status, $mode);
845 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
848 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
849 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
850 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
851 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
852 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
853 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
856 $statusType =
'status'.$status;
858 if ($status == self::STATUS_CANCELED) {
859 $statusType =
'status6';
862 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
873 $sql =
"SELECT rowid,";
874 $sql .=
" date_creation as datec, tms as datem,";
875 $sql .=
" fk_user_creat, fk_user_modif";
876 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
877 $sql .=
" WHERE t.rowid = ".((int) $id);
879 $result = $this->db->query(
$sql);
881 if ($this->db->num_rows($result)) {
882 $obj = $this->db->fetch_object($result);
884 $this->
id = $obj->rowid;
886 $this->user_creation_id = $obj->fk_user_creat;
887 $this->user_modification_id = $obj->fk_user_modif;
888 if (!empty($obj->fk_user_valid)) {
889 $this->user_validation_id = $obj->fk_user_valid;
891 $this->date_creation = $this->db->jdate($obj->datec);
892 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
893 if (!empty($obj->datev)) {
894 $this->date_validation = empty($obj->datev) ?
'' : $this->db->jdate($obj->datev);
898 $this->db->free($result);
926 $this->lines = array();
929 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_booking = '.((
int) $this->
id)));
931 if (is_numeric($result)) {
932 $this->error = $objectline->error;
933 $this->errors = $objectline->errors;
936 $this->lines = $result;
948 global $langs, $conf;
949 $langs->load(
"agenda");
951 if (empty($conf->global->BOOKCAL_BOOKING_ADDON)) {
952 $conf->global->BOOKCAL_BOOKING_ADDON =
'mod_booking_standard';
955 if (!empty($conf->global->BOOKCAL_BOOKING_ADDON)) {
958 $file = $conf->global->BOOKCAL_BOOKING_ADDON.
".php";
959 $classname = $conf->global->BOOKCAL_BOOKING_ADDON;
962 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
963 foreach ($dirmodels as $reldir) {
967 $mybool |= @include_once $dir.$file;
970 if ($mybool ===
false) {
975 if (class_exists($classname)) {
976 $obj =
new $classname();
977 $numref = $obj->getNextValue($this);
979 if ($numref !=
'' && $numref !=
'-1') {
982 $this->error = $obj->error;
987 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
991 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1007 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1009 global $conf, $langs;
1012 $includedocgeneration = 0;
1014 $langs->load(
"agenda");
1017 $modele =
'standard_booking';
1019 if (!empty($this->model_pdf)) {
1020 $modele = $this->model_pdf;
1021 } elseif (!empty($conf->global->BOOKING_ADDON_PDF)) {
1022 $modele = $conf->global->BOOKING_ADDON_PDF;
1026 $modelpath =
"core/modules/bookcal/doc/";
1028 if ($includedocgeneration && !empty($modele)) {
1029 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1044 global $conf, $langs;
1060 $this->db->commit();
1067 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1080 public $isextrafieldmanaged = 0;