dolibarr  19.0.0-dev
booking.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2022 Alice Adminson <aadminson@example.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Put here all includes required by your class file
26 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29 
33 class Booking extends CommonObject
34 {
38  public $module = 'bookcal';
39 
43  public $element = 'booking';
44 
48  public $table_element = 'bookcal_booking';
49 
54  public $ismultientitymanaged = 0;
55 
59  public $isextrafieldmanaged = 1;
60 
64  public $picto = 'fa-file';
65 
66 
67  const STATUS_DRAFT = 0;
68  const STATUS_VALIDATED = 1;
69  const STATUS_CANCELED = 9;
70 
71 
100  // BEGIN MODULEBUILDER PROPERTIES
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,),
126  );
127  public $rowid;
128  public $ref;
129  public $fk_soc;
130  public $fk_project;
131  public $description;
132  public $note_public;
133  public $note_private;
134  public $date_creation;
135  public $tms;
136  public $fk_user_creat;
137  public $fk_user_modif;
138  public $last_main_doc;
139  public $import_key;
140  public $model_pdf;
141  public $status;
142  public $firstname;
143  public $lastname;
144  public $email;
145  public $start;
146  public $duration;
147  public $fk_bookcal_availability;
148  // END MODULEBUILDER PROPERTIES
149 
150 
151  // If this object has a subtable with lines
152 
153  // /**
154  // * @var string Name of subtable line
155  // */
156  // public $table_element_line = 'bookcal_bookingline';
157 
158  // /**
159  // * @var string Field with ID of parent key if this object has a parent
160  // */
161  // public $fk_element = 'fk_booking';
162 
163  // /**
164  // * @var string Name of subtable class that manage subtable lines
165  // */
166  // public $class_element_line = 'Bookingline';
167 
168  // /**
169  // * @var array List of child tables. To test if we can delete object.
170  // */
171  // protected $childtables = array();
172 
173  // /**
174  // * @var array List of child tables. To know object to delete on cascade.
175  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
176  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
177  // */
178  // protected $childtablesoncascade = array('bookcal_bookingdet');
179 
180  // /**
181  // * @var BookingLine[] Array of subtable lines
182  // */
183  // public $lines = array();
184 
185 
186 
192  public function __construct(DoliDB $db)
193  {
194  global $conf, $langs;
195 
196  $this->db = $db;
197 
198  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
199  $this->fields['rowid']['visible'] = 0;
200  }
201  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
202  $this->fields['entity']['enabled'] = 0;
203  }
204 
205  // Example to show how to set values of fields definition dynamically
206  /*if ($user->rights->bookcal->booking->read) {
207  $this->fields['myfield']['visible'] = 1;
208  $this->fields['myfield']['noteditable'] = 0;
209  }*/
210 
211  // Unset fields that are disabled
212  foreach ($this->fields as $key => $val) {
213  if (isset($val['enabled']) && empty($val['enabled'])) {
214  unset($this->fields[$key]);
215  }
216  }
217 
218  // Translate some data of arrayofkeyval
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);
224  }
225  }
226  }
227  }
228  }
229 
237  public function create(User $user, $notrigger = false)
238  {
239  $resultcreate = $this->createCommon($user, $notrigger);
240 
241  //$resultvalidate = $this->validate($user, $notrigger);
242 
243  return $resultcreate;
244  }
245 
253  public function createFromClone(User $user, $fromid)
254  {
255  global $langs, $extrafields;
256  $error = 0;
257 
258  dol_syslog(__METHOD__, LOG_DEBUG);
259 
260  $object = new self($this->db);
261 
262  $this->db->begin();
263 
264  // Load source object
265  $result = $object->fetchCommon($fromid);
266  if ($result > 0 && !empty($object->table_element_line)) {
267  $object->fetchLines();
268  }
269 
270  // get lines so they will be clone
271  //foreach($this->lines as $line)
272  // $line->fetch_optionals();
273 
274  // Reset some properties
275  unset($object->id);
276  unset($object->fk_user_creat);
277  unset($object->import_key);
278 
279  // Clear fields
280  if (property_exists($object, 'ref')) {
281  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
282  }
283  if (property_exists($object, 'label')) {
284  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
285  }
286  if (property_exists($object, 'status')) {
287  $object->status = self::STATUS_DRAFT;
288  }
289  if (property_exists($object, 'date_creation')) {
290  $object->date_creation = dol_now();
291  }
292  if (property_exists($object, 'date_modification')) {
293  $object->date_modification = null;
294  }
295  // ...
296  // Clear extrafields that are unique
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])) {
302  //var_dump($key);
303  //var_dump($clonedObj->array_options[$key]); exit;
304  unset($object->array_options[$key]);
305  }
306  }
307  }
308 
309  // Create clone
310  $object->context['createfromclone'] = 'createfromclone';
311  $result = $object->createCommon($user);
312  if ($result < 0) {
313  $error++;
314  $this->error = $object->error;
315  $this->errors = $object->errors;
316  }
317 
318  if (!$error) {
319  // copy internal contacts
320  if ($this->copy_linked_contact($object, 'internal') < 0) {
321  $error++;
322  }
323  }
324 
325  if (!$error) {
326  // copy external contacts if same company
327  if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
328  if ($this->copy_linked_contact($object, 'external') < 0) {
329  $error++;
330  }
331  }
332  }
333 
334  unset($object->context['createfromclone']);
335 
336  // End
337  if (!$error) {
338  $this->db->commit();
339  return $object;
340  } else {
341  $this->db->rollback();
342  return -1;
343  }
344  }
345 
353  public function fetch($id, $ref = null)
354  {
355  $result = $this->fetchCommon($id, $ref);
356  if ($result > 0 && !empty($this->table_element_line)) {
357  $this->fetchLines();
358  }
359  return $result;
360  }
361 
367  public function fetchLines()
368  {
369  $this->lines = array();
370 
371  $result = $this->fetchLinesCommon();
372  return $result;
373  }
374 
375 
387  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
388  {
389  global $conf;
390 
391  dol_syslog(__METHOD__, LOG_DEBUG);
392 
393  $records = array();
394 
395  $sql = "SELECT ";
396  $sql .= $this->getFieldList('t');
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).")";
400  } else {
401  $sql .= " WHERE 1 = 1";
402  }
403  // Manage filter
404  $sqlwhere = array();
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)).")";
415  } else {
416  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
417  }
418  }
419  }
420  if (count($sqlwhere) > 0) {
421  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
422  }
423 
424  if (!empty($sortfield)) {
425  $sql .= $this->db->order($sortfield, $sortorder);
426  }
427  if (!empty($limit)) {
428  $sql .= $this->db->plimit($limit, $offset);
429  }
430 
431  $resql = $this->db->query($sql);
432  if ($resql) {
433  $num = $this->db->num_rows($resql);
434  $i = 0;
435  while ($i < ($limit ? min($limit, $num) : $num)) {
436  $obj = $this->db->fetch_object($resql);
437 
438  $record = new self($this->db);
439  $record->setVarsFromFetchObj($obj);
440 
441  $records[$record->id] = $record;
442 
443  $i++;
444  }
445  $this->db->free($resql);
446 
447  return $records;
448  } else {
449  $this->errors[] = 'Error '.$this->db->lasterror();
450  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
451 
452  return -1;
453  }
454  }
455 
463  public function update(User $user, $notrigger = false)
464  {
465  return $this->updateCommon($user, $notrigger);
466  }
467 
475  public function delete(User $user, $notrigger = false)
476  {
477  return $this->deleteCommon($user, $notrigger);
478  //return $this->deleteCommon($user, $notrigger, 1);
479  }
480 
489  public function deleteLine(User $user, $idline, $notrigger = false)
490  {
491  if ($this->status < 0) {
492  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
493  return -2;
494  }
495 
496  return $this->deleteLineCommon($user, $idline, $notrigger);
497  }
498 
499 
507  public function validate($user, $notrigger = 0)
508  {
509  global $conf, $langs;
510 
511  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
512 
513  $error = 0;
514 
515  // Protection
516  if ($this->status == self::STATUS_VALIDATED) {
517  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
518  return 0;
519  }
520 
521  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->booking->write))
522  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->booking->booking_advance->validate))))
523  {
524  $this->error='NotEnoughPermissions';
525  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
526  return -1;
527  }*/
528 
529  $now = dol_now();
530 
531  $this->db->begin();
532 
533  // Define new ref
534  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
535  $num = $this->getNextNumRef();
536  } else {
537  $num = $this->ref;
538  }
539  $this->newref = $num;
540 
541  if (!empty($num)) {
542  // Validate
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)."'";
548  }
549  if (!empty($this->fields['fk_user_valid'])) {
550  $sql .= ", fk_user_valid = ".((int) $user->id);
551  }
552  $sql .= " WHERE rowid = ".((int) $this->id);
553 
554  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
555  $resql = $this->db->query($sql);
556  if (!$resql) {
557  dol_print_error($this->db);
558  $this->error = $this->db->lasterror();
559  $error++;
560  }
561 
562  if (!$error && !$notrigger) {
563  // Call trigger
564  $result = $this->call_trigger('BOOKING_VALIDATE', $user);
565  if ($result < 0) {
566  $error++;
567  }
568  // End call triggers
569  }
570  }
571 
572  if (!$error) {
573  $this->oldref = $this->ref;
574 
575  // Rename directory if dir was a temporary ref
576  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
577  // Now we rename also files into index
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);
581  if (!$resql) {
582  $error++; $this->error = $this->db->lasterror();
583  }
584 
585  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
586  $oldref = dol_sanitizeFileName($this->ref);
587  $newref = dol_sanitizeFileName($num);
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);
592 
593  if (@rename($dirsource, $dirdest)) {
594  dol_syslog("Rename ok");
595  // Rename docs starting with $oldref with $newref
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);
603  }
604  }
605  }
606  }
607  }
608 
609  // Set new ref and current status
610  if (!$error) {
611  $this->ref = $num;
612  $this->status = self::STATUS_VALIDATED;
613  }
614 
615  if (!$error) {
616  $this->db->commit();
617  return 1;
618  } else {
619  $this->db->rollback();
620  return -1;
621  }
622  }
623 
624 
632  public function setDraft($user, $notrigger = 0)
633  {
634  // Protection
635  if ($this->status <= self::STATUS_DRAFT) {
636  return 0;
637  }
638 
639  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->write))
640  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->bookcal_advance->validate))))
641  {
642  $this->error='Permission denied';
643  return -1;
644  }*/
645 
646  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'BOOKING_UNVALIDATE');
647  }
648 
656  public function cancel($user, $notrigger = 0)
657  {
658  // Protection
659  if ($this->status != self::STATUS_VALIDATED) {
660  return 0;
661  }
662 
663  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->write))
664  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->bookcal_advance->validate))))
665  {
666  $this->error='Permission denied';
667  return -1;
668  }*/
669 
670  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'BOOKING_CANCEL');
671  }
672 
680  public function reopen($user, $notrigger = 0)
681  {
682  // Protection
683  if ($this->status != self::STATUS_CANCELED) {
684  return 0;
685  }
686 
687  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->write))
688  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->bookcal_advance->validate))))
689  {
690  $this->error='Permission denied';
691  return -1;
692  }*/
693 
694  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'BOOKING_REOPEN');
695  }
696 
707  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
708  {
709  global $conf, $langs, $hookmanager;
710 
711  if (!empty($conf->dol_no_mouse_hover)) {
712  $notooltip = 1; // Force disable tooltips
713  }
714 
715  $result = '';
716 
717  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Booking").'</u>';
718  if (isset($this->status)) {
719  $label .= ' '.$this->getLibStatut(5);
720  }
721  $label .= '<br>';
722  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
723 
724  $url = dol_buildpath('/bookcal/booking_card.php', 1).'?id='.$this->id;
725 
726  if ($option != 'nolink') {
727  // Add param to save lastsearch_values or not
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;
731  }
732  if ($url && $add_save_lastsearch_values) {
733  $url .= '&save_lastsearch_values=1';
734  }
735  }
736 
737  $linkclose = '';
738  if (empty($notooltip)) {
739  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
740  $label = $langs->trans("ShowBooking");
741  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
742  }
743  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
744  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
745  } else {
746  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
747  }
748 
749  if ($option == 'nolink' || empty($url)) {
750  $linkstart = '<span';
751  } else {
752  $linkstart = '<a href="'.$url.'"';
753  }
754  $linkstart .= $linkclose.'>';
755  if ($option == 'nolink' || empty($url)) {
756  $linkend = '</span>';
757  } else {
758  $linkend = '</a>';
759  }
760 
761  $result .= $linkstart;
762 
763  if (empty($this->showphoto_on_popup)) {
764  if ($withpicto) {
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);
766  }
767  } else {
768  if ($withpicto) {
769  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
770 
771  list($class, $module) = explode('@', $this->picto);
772  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
773  $filearray = dol_dir_list($upload_dir, "files");
774  $filename = $filearray[0]['name'];
775  if (!empty($filename)) {
776  $pospoint = strpos($filearray[0]['name'], '.');
777 
778  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
779  if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
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>';
781  } else {
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>';
783  }
784 
785  $result .= '</div>';
786  } else {
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);
788  }
789  }
790  }
791 
792  if ($withpicto != 2) {
793  $result .= $this->ref;
794  }
795 
796  $result .= $linkend;
797  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
798 
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); // Note that $action and $object may have been modified by some hooks
803  if ($reshook > 0) {
804  $result = $hookmanager->resPrint;
805  } else {
806  $result .= $hookmanager->resPrint;
807  }
808 
809  return $result;
810  }
811 
818  public function getLabelStatus($mode = 0)
819  {
820  return $this->LibStatut($this->status, $mode);
821  }
822 
829  public function getLibStatut($mode = 0)
830  {
831  return $this->LibStatut($this->status, $mode);
832  }
833 
834  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
842  public function LibStatut($status, $mode = 0)
843  {
844  // phpcs:enable
845  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
846  global $langs;
847  //$langs->load("agenda");
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');
854  }
855 
856  $statusType = 'status'.$status;
857  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
858  if ($status == self::STATUS_CANCELED) {
859  $statusType = 'status6';
860  }
861 
862  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
863  }
864 
871  public function info($id)
872  {
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);
878 
879  $result = $this->db->query($sql);
880  if ($result) {
881  if ($this->db->num_rows($result)) {
882  $obj = $this->db->fetch_object($result);
883 
884  $this->id = $obj->rowid;
885 
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;
890  }
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);
895  }
896  }
897 
898  $this->db->free($result);
899  } else {
900  dol_print_error($this->db);
901  }
902  }
903 
910  public function initAsSpecimen()
911  {
912  // Set here init that are not commonf fields
913  // $this->property1 = ...
914  // $this->property2 = ...
915 
916  $this->initAsSpecimenCommon();
917  }
918 
924  public function getLinesArray()
925  {
926  $this->lines = array();
927 
928  $objectline = new BookingLine($this->db);
929  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_booking = '.((int) $this->id)));
930 
931  if (is_numeric($result)) {
932  $this->error = $objectline->error;
933  $this->errors = $objectline->errors;
934  return $result;
935  } else {
936  $this->lines = $result;
937  return $this->lines;
938  }
939  }
940 
946  public function getNextNumRef()
947  {
948  global $langs, $conf;
949  $langs->load("agenda");
950 
951  if (empty($conf->global->BOOKCAL_BOOKING_ADDON)) {
952  $conf->global->BOOKCAL_BOOKING_ADDON = 'mod_booking_standard';
953  }
954 
955  if (!empty($conf->global->BOOKCAL_BOOKING_ADDON)) {
956  $mybool = false;
957 
958  $file = $conf->global->BOOKCAL_BOOKING_ADDON.".php";
959  $classname = $conf->global->BOOKCAL_BOOKING_ADDON;
960 
961  // Include file with class
962  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
963  foreach ($dirmodels as $reldir) {
964  $dir = dol_buildpath($reldir."core/modules/bookcal/");
965 
966  // Load file with numbering class (if found)
967  $mybool |= @include_once $dir.$file;
968  }
969 
970  if ($mybool === false) {
971  dol_print_error('', "Failed to include file ".$file);
972  return '';
973  }
974 
975  if (class_exists($classname)) {
976  $obj = new $classname();
977  $numref = $obj->getNextValue($this);
978 
979  if ($numref != '' && $numref != '-1') {
980  return $numref;
981  } else {
982  $this->error = $obj->error;
983  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
984  return "";
985  }
986  } else {
987  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
988  return "";
989  }
990  } else {
991  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
992  return "";
993  }
994  }
995 
1007  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1008  {
1009  global $conf, $langs;
1010 
1011  $result = 0;
1012  $includedocgeneration = 0;
1013 
1014  $langs->load("agenda");
1015 
1016  if (!dol_strlen($modele)) {
1017  $modele = 'standard_booking';
1018 
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;
1023  }
1024  }
1025 
1026  $modelpath = "core/modules/bookcal/doc/";
1027 
1028  if ($includedocgeneration && !empty($modele)) {
1029  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1030  }
1031 
1032  return $result;
1033  }
1034 
1042  public function doScheduledJob()
1043  {
1044  global $conf, $langs;
1045 
1046  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1047 
1048  $error = 0;
1049  $this->output = '';
1050  $this->error = '';
1051 
1052  dol_syslog(__METHOD__, LOG_DEBUG);
1053 
1054  $now = dol_now();
1055 
1056  $this->db->begin();
1057 
1058  // ...
1059 
1060  $this->db->commit();
1061 
1062  return $error;
1063  }
1064 }
1065 
1066 
1067 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1068 
1073 {
1074  // To complete with content of an object BookingLine
1075  // We should have a field rowid, fk_booking and position
1076 
1080  public $isextrafieldmanaged = 0;
1081 
1087  public function __construct(DoliDB $db)
1088  {
1089  $this->db = $db;
1090  }
1091 }
$object ref
Definition: info.php:78
Class for Booking.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
info($id)
Load the info information in the object.
fetchLines()
Load object lines in memory from the database.
validate($user, $notrigger=0)
Validate object.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
setDraft($user, $notrigger=0)
Set draft status.
getLabelStatus($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the status.
fetch($id, $ref=null)
Load object in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
createFromClone(User $user, $fromid)
Clone an object into another one.
update(User $user, $notrigger=false)
Update object into database.
reopen($user, $notrigger=0)
Set back to validated status.
create(User $user, $notrigger=false)
Create object into database.
__construct(DoliDB $db)
Constructor.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
getLinesArray()
Create an array of lines.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
getLibStatut($mode=0)
Return the label of the status.
cancel($user, $notrigger=0)
Set cancel status.
Class BookingLine.
__construct(DoliDB $db)
Constructor.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
getFieldList($alias='')
Function to concat keys of fields.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.