dolibarr  19.0.0-dev
calendar.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
4  * Copyright (C) 2023 Alice Adminson <aadminson@example.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 // Put here all includes required by your class file
27 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
29 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
30 
34 class Calendar extends CommonObject
35 {
39  public $module = 'bookcal';
40 
44  public $element = 'calendar';
45 
49  public $table_element = 'bookcal_calendar';
50 
55  public $ismultientitymanaged = 0;
56 
60  public $isextrafieldmanaged = 1;
61 
65  public $picto = 'fa-file';
66 
67 
68  const STATUS_DRAFT = 0;
69  const STATUS_VALIDATED = 1;
70  const STATUS_CANCELED = 9;
71 
72 
112  // BEGIN MODULEBUILDER PROPERTIES
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&eacute;', '9'=>'Annul&eacute;'), 'validate'=>'1',),
131  );
132  public $rowid;
133  public $ref;
134  public $label;
135  public $fk_soc;
136  public $fk_project;
137  public $description;
138  public $note_public;
139  public $note_private;
140  public $date_creation;
141  public $tms;
142  public $fk_user_creat;
143  public $fk_user_modif;
144  public $import_key;
145  public $status;
146  // END MODULEBUILDER PROPERTIES
147 
148 
149  // If this object has a subtable with lines
150 
151  // /**
152  // * @var string Name of subtable line
153  // */
154  // public $table_element_line = 'bookcal_calendarline';
155 
156  // /**
157  // * @var string Field with ID of parent key if this object has a parent
158  // */
159  // public $fk_element = 'fk_calendar';
160 
161  // /**
162  // * @var string Name of subtable class that manage subtable lines
163  // */
164  // public $class_element_line = 'Calendarline';
165 
166  // /**
167  // * @var array List of child tables. To test if we can delete object.
168  // */
169  // protected $childtables = array('mychildtable' => array('name'=>'Calendar', 'fk_element'=>'fk_calendar'));
170 
171  // /**
172  // * @var array List of child tables. To know object to delete on cascade.
173  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
174  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
175  // */
176  // protected $childtablesoncascade = array('bookcal_calendardet');
177 
178  // /**
179  // * @var CalendarLine[] Array of subtable lines
180  // */
181  // public $lines = array();
182 
183 
184 
190  public function __construct(DoliDB $db)
191  {
192  global $conf, $langs;
193 
194  $this->db = $db;
195 
196  if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
197  $this->fields['rowid']['visible'] = 0;
198  }
199  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
200  $this->fields['entity']['enabled'] = 0;
201  }
202 
203  // Example to show how to set values of fields definition dynamically
204  /*if ($user->hasRight('bookcal', 'calendar', 'read')) {
205  $this->fields['myfield']['visible'] = 1;
206  $this->fields['myfield']['noteditable'] = 0;
207  }*/
208 
209  // Unset fields that are disabled
210  foreach ($this->fields as $key => $val) {
211  if (isset($val['enabled']) && empty($val['enabled'])) {
212  unset($this->fields[$key]);
213  }
214  }
215 
216  // Translate some data of arrayofkeyval
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);
222  }
223  }
224  }
225  }
226  }
227 
235  public function create(User $user, $notrigger = false)
236  {
237  $resultcreate = $this->createCommon($user, $notrigger);
238 
239  //$resultvalidate = $this->validate($user, $notrigger);
240 
241  return $resultcreate;
242  }
243 
251  public function createFromClone(User $user, $fromid)
252  {
253  global $langs, $extrafields;
254  $error = 0;
255 
256  dol_syslog(__METHOD__, LOG_DEBUG);
257 
258  $object = new self($this->db);
259 
260  $this->db->begin();
261 
262  // Load source object
263  $result = $object->fetchCommon($fromid);
264  if ($result > 0 && !empty($object->table_element_line)) {
265  $object->fetchLines();
266  }
267 
268  // get lines so they will be clone
269  //foreach($this->lines as $line)
270  // $line->fetch_optionals();
271 
272  // Reset some properties
273  unset($object->id);
274  unset($object->fk_user_creat);
275  unset($object->import_key);
276 
277  // Clear fields
278  if (property_exists($object, 'ref')) {
279  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
280  }
281  if (property_exists($object, 'label')) {
282  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
283  }
284  if (property_exists($object, 'status')) {
285  $object->status = self::STATUS_DRAFT;
286  }
287  if (property_exists($object, 'date_creation')) {
288  $object->date_creation = dol_now();
289  }
290  if (property_exists($object, 'date_modification')) {
291  $object->date_modification = null;
292  }
293  // ...
294  // Clear extrafields that are unique
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])) {
300  //var_dump($key);
301  //var_dump($clonedObj->array_options[$key]); exit;
302  unset($object->array_options[$key]);
303  }
304  }
305  }
306 
307  // Create clone
308  $object->context['createfromclone'] = 'createfromclone';
309  $result = $object->createCommon($user);
310  if ($result < 0) {
311  $error++;
312  $this->setErrorsFromObject($object);
313  }
314 
315  if (!$error) {
316  // copy internal contacts
317  if ($this->copy_linked_contact($object, 'internal') < 0) {
318  $error++;
319  }
320  }
321 
322  if (!$error) {
323  // copy external contacts if same company
324  if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
325  if ($this->copy_linked_contact($object, 'external') < 0) {
326  $error++;
327  }
328  }
329  }
330 
331  unset($object->context['createfromclone']);
332 
333  // End
334  if (!$error) {
335  $this->db->commit();
336  return $object;
337  } else {
338  $this->db->rollback();
339  return -1;
340  }
341  }
342 
350  public function fetch($id, $ref = null)
351  {
352  $result = $this->fetchCommon($id, $ref);
353  if ($result > 0 && !empty($this->table_element_line)) {
354  $this->fetchLines();
355  }
356  return $result;
357  }
358 
364  public function fetchLines()
365  {
366  $this->lines = array();
367 
368  $result = $this->fetchLinesCommon();
369  return $result;
370  }
371 
372 
384  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
385  {
386  global $conf;
387 
388  dol_syslog(__METHOD__, LOG_DEBUG);
389 
390  $records = array();
391 
392  $sql = "SELECT ";
393  $sql .= $this->getFieldList('t');
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).")";
397  } else {
398  $sql .= " WHERE 1 = 1";
399  }
400  // Manage filter
401  $sqlwhere = array();
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)).")";
412  } else {
413  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
414  }
415  }
416  }
417  if (count($sqlwhere) > 0) {
418  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
419  }
420 
421  if (!empty($sortfield)) {
422  $sql .= $this->db->order($sortfield, $sortorder);
423  }
424  if (!empty($limit)) {
425  $sql .= $this->db->plimit($limit, $offset);
426  }
427 
428  $resql = $this->db->query($sql);
429  if ($resql) {
430  $num = $this->db->num_rows($resql);
431  $i = 0;
432  while ($i < ($limit ? min($limit, $num) : $num)) {
433  $obj = $this->db->fetch_object($resql);
434 
435  $record = new self($this->db);
436  $record->setVarsFromFetchObj($obj);
437 
438  $records[$record->id] = $record;
439 
440  $i++;
441  }
442  $this->db->free($resql);
443 
444  return $records;
445  } else {
446  $this->errors[] = 'Error '.$this->db->lasterror();
447  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
448 
449  return -1;
450  }
451  }
452 
460  public function update(User $user, $notrigger = false)
461  {
462  return $this->updateCommon($user, $notrigger);
463  }
464 
472  public function delete(User $user, $notrigger = false)
473  {
474  return $this->deleteCommon($user, $notrigger);
475  //return $this->deleteCommon($user, $notrigger, 1);
476  }
477 
486  public function deleteLine(User $user, $idline, $notrigger = false)
487  {
488  if ($this->status < 0) {
489  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
490  return -2;
491  }
492 
493  return $this->deleteLineCommon($user, $idline, $notrigger);
494  }
495 
496 
504  public function validate($user, $notrigger = 0)
505  {
506  global $conf, $langs;
507 
508  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
509 
510  $error = 0;
511 
512  // Protection
513  if ($this->status == self::STATUS_VALIDATED) {
514  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
515  return 0;
516  }
517 
518  /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->calendar->write))
519  || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->calendar->calendar_advance->validate))))
520  {
521  $this->error='NotEnoughPermissions';
522  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
523  return -1;
524  }*/
525 
526  $now = dol_now();
527 
528  $this->db->begin();
529 
530  // Define new ref
531  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
532  $num = $this->getNextNumRef();
533  } else {
534  $num = $this->ref;
535  }
536  $this->newref = $num;
537 
538  if (!empty($num)) {
539  // Validate
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)."'";
545  }
546  if (!empty($this->fields['fk_user_valid'])) {
547  $sql .= ", fk_user_valid = ".((int) $user->id);
548  }
549  $sql .= " WHERE rowid = ".((int) $this->id);
550 
551  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
552  $resql = $this->db->query($sql);
553  if (!$resql) {
554  dol_print_error($this->db);
555  $this->error = $this->db->lasterror();
556  $error++;
557  }
558 
559  if (!$error && !$notrigger) {
560  // Call trigger
561  $result = $this->call_trigger('MYOBJECT_VALIDATE', $user);
562  if ($result < 0) {
563  $error++;
564  }
565  // End call triggers
566  }
567  }
568 
569  if (!$error) {
570  $this->oldref = $this->ref;
571 
572  // Rename directory if dir was a temporary ref
573  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
574  // Now we rename also files into index
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);
578  if (!$resql) {
579  $error++; $this->error = $this->db->lasterror();
580  }
581 
582  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
583  $oldref = dol_sanitizeFileName($this->ref);
584  $newref = dol_sanitizeFileName($num);
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);
589 
590  if (@rename($dirsource, $dirdest)) {
591  dol_syslog("Rename ok");
592  // Rename docs starting with $oldref with $newref
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);
600  }
601  }
602  }
603  }
604  }
605 
606  // Set new ref and current status
607  if (!$error) {
608  $this->ref = $num;
609  $this->status = self::STATUS_VALIDATED;
610  }
611 
612  if (!$error) {
613  $this->db->commit();
614  return 1;
615  } else {
616  $this->db->rollback();
617  return -1;
618  }
619  }
620 
621 
629  public function setDraft($user, $notrigger = 0)
630  {
631  // Protection
632  if ($this->status <= self::STATUS_DRAFT) {
633  return 0;
634  }
635 
636  /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->write))
637  || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->bookcal_advance->validate))))
638  {
639  $this->error='Permission denied';
640  return -1;
641  }*/
642 
643  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MYOBJECT_UNVALIDATE');
644  }
645 
653  public function cancel($user, $notrigger = 0)
654  {
655  // Protection
656  if ($this->status != self::STATUS_VALIDATED) {
657  return 0;
658  }
659 
660  /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->write))
661  || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->bookcal_advance->validate))))
662  {
663  $this->error='Permission denied';
664  return -1;
665  }*/
666 
667  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MYOBJECT_CANCEL');
668  }
669 
677  public function reopen($user, $notrigger = 0)
678  {
679  // Protection
680  if ($this->status == self::STATUS_VALIDATED) {
681  return 0;
682  }
683 
684  /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->write))
685  || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->bookcal->bookcal_advance->validate))))
686  {
687  $this->error='Permission denied';
688  return -1;
689  }*/
690 
691  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MYOBJECT_REOPEN');
692  }
693 
701  public function getTooltipContentArray($params)
702  {
703  global $conf, $langs;
704 
705  $datas = [];
706 
707  if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
708  return ['optimize' => $langs->trans("ShowCalendar")];
709  }
710  $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Calendar").'</u>';
711  if (isset($this->status)) {
712  $datas['picto'] .= ' '.$this->getLibStatut(5);
713  }
714  $datas['ref'] .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
715 
716  return $datas;
717  }
718 
729  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
730  {
731  global $conf, $langs, $hookmanager;
732 
733  if (!empty($conf->dol_no_mouse_hover)) {
734  $notooltip = 1; // Force disable tooltips
735  }
736 
737  $result = '';
738  $params = [
739  'id' => $this->id,
740  'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
741  'option' => $option,
742  ];
743  $classfortooltip = 'classfortooltip';
744  $dataparams = '';
745  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
746  $classfortooltip = 'classforajaxtooltip';
747  $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
748  $label = '';
749  } else {
750  $label = implode($this->getTooltipContentArray($params));
751  }
752 
753  $url = dol_buildpath('/bookcal/calendar_card.php', 1).'?id='.$this->id;
754 
755  if ($option !== 'nolink') {
756  // Add param to save lastsearch_values or not
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;
760  }
761  if ($url && $add_save_lastsearch_values) {
762  $url .= '&save_lastsearch_values=1';
763  }
764  }
765 
766  $linkclose = '';
767  if (empty($notooltip)) {
768  if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
769  $label = $langs->trans("ShowCalendar");
770  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
771  }
772  $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
773  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
774  } else {
775  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
776  }
777 
778  if ($option == 'nolink' || empty($url)) {
779  $linkstart = '<span';
780  } else {
781  $linkstart = '<a href="'.$url.'"';
782  }
783  $linkstart .= $linkclose.'>';
784  if ($option == 'nolink' || empty($url)) {
785  $linkend = '</span>';
786  } else {
787  $linkend = '</a>';
788  }
789 
790  $result .= $linkstart;
791 
792  if (empty($this->showphoto_on_popup)) {
793  if ($withpicto) {
794  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
795  }
796  } else {
797  if ($withpicto) {
798  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
799 
800  list($class, $module) = explode('@', $this->picto);
801  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
802  $filearray = dol_dir_list($upload_dir, "files");
803  $filename = $filearray[0]['name'];
804  if (!empty($filename)) {
805  $pospoint = strpos($filearray[0]['name'], '.');
806 
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>';
810  } else {
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>';
812  }
813 
814  $result .= '</div>';
815  } else {
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);
817  }
818  }
819  }
820 
821  if ($withpicto != 2) {
822  $result .= $this->ref;
823  }
824 
825  $result .= $linkend;
826  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
827 
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); // Note that $action and $object may have been modified by some hooks
832  if ($reshook > 0) {
833  $result = $hookmanager->resPrint;
834  } else {
835  $result .= $hookmanager->resPrint;
836  }
837 
838  return $result;
839  }
840 
848  public function getKanbanView($option = '', $arraydata = null)
849  {
850  global $conf, $langs;
851 
852  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
853 
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">';
857  $return .= img_picto('', $this->picto);
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"' : '').'>';
863  }
864  if (property_exists($this, 'label')) {
865  $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
866  }
867  if (property_exists($this, 'amount')) {
868  $return .= '<br>';
869  $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
870  }
871  if (method_exists($this, 'getLibStatut')) {
872  $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
873  }
874  $return .= '</div>';
875  $return .= '</div>';
876  $return .= '</div>';
877 
878  return $return;
879  }
880 
887  public function getLabelStatus($mode = 0)
888  {
889  return $this->LibStatut($this->status, $mode);
890  }
891 
898  public function getLibStatut($mode = 0)
899  {
900  return $this->LibStatut($this->status, $mode);
901  }
902 
903  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
911  public function LibStatut($status, $mode = 0)
912  {
913  // phpcs:enable
914  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
915  global $langs;
916  //$langs->load("bookcal@bookcal");
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');
923  }
924 
925  $statusType = 'status'.$status;
926  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
927  if ($status == self::STATUS_CANCELED) {
928  $statusType = 'status6';
929  }
930 
931  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
932  }
933 
940  public function info($id)
941  {
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);
947 
948  $result = $this->db->query($sql);
949  if ($result) {
950  if ($this->db->num_rows($result)) {
951  $obj = $this->db->fetch_object($result);
952 
953  $this->id = $obj->rowid;
954 
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;
959  }
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);
964  }
965  }
966 
967  $this->db->free($result);
968  } else {
969  dol_print_error($this->db);
970  }
971  }
972 
979  public function initAsSpecimen()
980  {
981  // Set here init that are not commonf fields
982  // $this->property1 = ...
983  // $this->property2 = ...
984 
985  $this->initAsSpecimenCommon();
986  }
987 
993  public function getLinesArray()
994  {
995  $this->lines = array();
996 
997  $objectline = new CalendarLine($this->db);
998  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_calendar = '.((int) $this->id)));
999 
1000  if (is_numeric($result)) {
1001  $this->setErrorsFromObject($objectline);
1002  return $result;
1003  } else {
1004  $this->lines = $result;
1005  return $this->lines;
1006  }
1007  }
1008 
1014  public function getNextNumRef()
1015  {
1016  global $langs, $conf;
1017  $langs->load("bookcal@bookcal");
1018 
1019  if (empty(getDolGlobalString('BOOKCAL_MYOBJECT_ADDON'))) {
1020  $conf->global->BOOKCAL_MYOBJECT_ADDON = 'mod_calendar_standard';
1021  }
1022 
1023  if (!empty(getDolGlobalString('BOOKCAL_MYOBJECT_ADDON'))) {
1024  $mybool = false;
1025 
1026  $file = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON').".php";
1027  $classname = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON');
1028 
1029  // Include file with class
1030  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1031  foreach ($dirmodels as $reldir) {
1032  $dir = dol_buildpath($reldir."core/modules/bookcal/");
1033 
1034  // Load file with numbering class (if found)
1035  $mybool |= @include_once $dir.$file;
1036  }
1037 
1038  if ($mybool === false) {
1039  dol_print_error('', "Failed to include file ".$file);
1040  return '';
1041  }
1042 
1043  if (class_exists($classname)) {
1044  $obj = new $classname();
1045  $numref = $obj->getNextValue($this);
1046 
1047  if ($numref != '' && $numref != '-1') {
1048  return $numref;
1049  } else {
1050  $this->error = $obj->error;
1051  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1052  return "";
1053  }
1054  } else {
1055  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1056  return "";
1057  }
1058  } else {
1059  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1060  return "";
1061  }
1062  }
1063 
1075  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1076  {
1077  global $conf, $langs;
1078 
1079  $result = 0;
1080  $includedocgeneration = 0;
1081 
1082  $langs->load("bookcal@bookcal");
1083 
1084  if (!dol_strlen($modele)) {
1085  $modele = 'standard_calendar';
1086 
1087  if (!empty($this->model_pdf)) {
1088  $modele = $this->model_pdf;
1089  } elseif (getDolGlobalString('MYOBJECT_ADDON_PDF')) {
1090  $modele = getDolGlobalString('MYOBJECT_ADDON_PDF');
1091  }
1092  }
1093 
1094  $modelpath = "core/modules/bookcal/doc/";
1095 
1096  if ($includedocgeneration && !empty($modele)) {
1097  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1098  }
1099 
1100  return $result;
1101  }
1102 
1110  public function doScheduledJob()
1111  {
1112  //global $conf, $langs;
1113 
1114  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1115 
1116  $error = 0;
1117  $this->output = '';
1118  $this->error = '';
1119 
1120  dol_syslog(__METHOD__, LOG_DEBUG);
1121 
1122  $now = dol_now();
1123 
1124  $this->db->begin();
1125 
1126  // ...
1127 
1128  $this->db->commit();
1129 
1130  return $error;
1131  }
1132 }
1133 
1134 
1135 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1136 
1141 {
1142  // To complete with content of an object CalendarLine
1143  // We should have a field rowid, fk_calendar and position
1144 
1148  public $isextrafieldmanaged = 0;
1149 
1155  public function __construct(DoliDB $db)
1156  {
1157  $this->db = $db;
1158  }
1159 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9605
Calendar\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: calendar.class.php:350
Calendar\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: calendar.class.php:653
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9883
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9395
Calendar\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: calendar.class.php:1075
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1323
Calendar\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: calendar.class.php:486
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1132
Calendar\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: calendar.class.php:979
Calendar\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: calendar.class.php:384
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
CommonObject\setErrorsFromObject
setErrorsFromObject($object)
setErrorsFromObject
Definition: commonobject.class.php:743
Calendar\__construct
__construct(DoliDB $db)
Constructor.
Definition: calendar.class.php:190
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1158
Calendar\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: calendar.class.php:1110
dol_dir_list
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
Calendar\create
create(User $user, $notrigger=false)
Create object into database.
Definition: calendar.class.php:235
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9451
Calendar
Class for Calendar.
Definition: calendar.class.php:34
CommonObject\initAsSpecimenCommon
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: commonobject.class.php:9933
CommonObjectLine
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Definition: commonobjectline.class.php:32
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
CalendarLine\__construct
__construct(DoliDB $db)
Constructor.
Definition: calendar.class.php:1155
Calendar\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: calendar.class.php:729
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
CommonObject\commonGenerateDocument
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Definition: commonobject.class.php:5381
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9228
Calendar\getKanbanView
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
Definition: calendar.class.php:848
Calendar\getLinesArray
getLinesArray()
Create an array of lines.
Definition: calendar.class.php:993
Calendar\getLabelStatus
getLabelStatus($mode=0)
Return the label of the status.
Definition: calendar.class.php:887
Calendar\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: calendar.class.php:251
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
Calendar\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: calendar.class.php:677
Calendar\getTooltipContentArray
getTooltipContentArray($params)
getTooltipContentArray
Definition: calendar.class.php:701
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9501
$sql
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_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3997
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
ref
$object ref
Definition: info.php:78
getDolGlobalString
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:142
User
Class to manage Dolibarr users.
Definition: user.class.php:47
Calendar\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: calendar.class.php:1014
Calendar\LibStatut
LibStatut($status, $mode=0)
Return the label of a given status.
Definition: calendar.class.php:911
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10967
Calendar\update
update(User $user, $notrigger=false)
Update object into database.
Definition: calendar.class.php:460
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4473
Calendar\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: calendar.class.php:629
Calendar\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: calendar.class.php:364
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3056
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9821
CalendarLine
Class CalendarLine.
Definition: calendar.class.php:1140
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5790
Calendar\validate
validate($user, $notrigger=0)
Validate object.
Definition: calendar.class.php:504
Calendar\info
info($id)
Load the info information in the object.
Definition: calendar.class.php:940
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9180
Calendar\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: calendar.class.php:898