dolibarr 23.0.3
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-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2023 Alice Adminson <aadminson@example.com>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29
34{
38 public $module = 'bookcal';
39
43 public $element = 'calendar';
44
49 public $TRIGGER_PREFIX = 'CALENDAR';
50
54 public $table_element = 'bookcal_calendar';
55
59 public $picto = 'fa-calendar-check';
60
61
62 const STATUS_DRAFT = 0;
63 const STATUS_VALIDATED = 1;
64 const STATUS_CANCELED = 9;
65
66
106 // BEGIN MODULEBUILDER PROPERTIES
110 public $fields = array(
111 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'right', 'comment' => "Id"),
112 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 40, 'index' => 1),
113 '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", 'css' => 'width100'),
114 '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,),
115 'visibility' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Owner', 'enabled' => 1, 'position' => 40, 'notnull' => 1, 'visible' => 1, 'picto' => 'user', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150',),
116 'type' => array('type' => 'integer', 'label' => 'Type', 'enabled' => 1, 'position' => 42, 'notnull' => 1, 'visible' => 1, 'arrayofkeyval' => array('0' => 'Customer', '1' => 'Supplier', '3' => 'Other'),),
117 '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' => "ThirdPartyBookCalHelp", 'validate' => 1,),
118 '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,),
119 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 3, 'validate' => 1,),
120 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,),
121 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,),
122 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
123 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
124 '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',),
125 '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',),
126 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
127 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'position' => 2000, 'notnull' => 1, 'default' => '0', 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated', '9' => 'Closed'), 'validate' => 1,),
128 );
132 public $rowid;
133
137 public $label;
141 public $type;
145 public $visibility;
149 public $fk_soc;
153 public $description;
154
158 public $fk_user_creat;
162 public $fk_user_modif;
166 public $import_key;
167
168 // END MODULEBUILDER PROPERTIES
169
170
176 public function __construct(DoliDB $db)
177 {
178 global $langs, $user;
179
180 $this->db = $db;
181
182 $this->ismultientitymanaged = 1;
183 $this->isextrafieldmanaged = 1;
184
185 if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
186 $this->fields['rowid']['visible'] = 0;
187 }
188 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
189 $this->fields['entity']['enabled'] = 0;
190 }
191
192 // Example to show how to set values of fields definition dynamically
193 /*if ($user->hasRight('bookcal', 'calendar', 'read')) {
194 $this->fields['myfield']['visible'] = 1;
195 $this->fields['myfield']['noteditable'] = 0;
196 }*/
197 $this->fields['visibility']['default'] = $user->id;
198
199 // Unset fields that are disabled
200 foreach ($this->fields as $key => $val) {
201 if (isset($val['enabled']) && empty($val['enabled'])) {
202 unset($this->fields[$key]);
203 }
204 }
205
206 // Translate some data of arrayofkeyval
207 if (is_object($langs)) {
208 foreach ($this->fields as $key => $val) {
209 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
210 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
211 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
212 }
213 }
214 }
215 }
216 }
217
225 public function create(User $user, $notrigger = 0)
226 {
227 $resultcreate = $this->createCommon($user, $notrigger);
228
229 //$resultvalidate = $this->validate($user, $notrigger);
230
231 return $resultcreate;
232 }
233
241 public function createFromClone(User $user, $fromid)
242 {
243 global $langs, $extrafields;
244 $error = 0;
245
246 dol_syslog(__METHOD__, LOG_DEBUG);
247
248 $object = new self($this->db);
249
250 $this->db->begin();
251
252 // Load source object
253 $result = $object->fetchCommon($fromid);
254 if ($result > 0 && !empty($object->table_element_line)) {
255 $object->fetchLines();
256 }
257
258 // get lines so they will be cloned
259 //foreach($this->lines as $line)
260 // $line->fetch_optionals();
261
262 // Reset some properties
263 unset($object->id);
264 unset($object->fk_user_creat);
265 unset($object->import_key);
266
267 // Clear fields
268 $object->ref = "Copy_Of_".$object->ref;
269 $object->label = $langs->trans("CopyOf")." ".$object->label;
270 $object->status = self::STATUS_DRAFT;
271 $object->date_creation = dol_now();
272 $object->date_modification = null;
273
274 // Clear extrafields that are unique
275 if (is_array($object->array_options) && count($object->array_options) > 0) {
276 $extrafields->fetch_name_optionals_label($this->table_element);
277 foreach ($object->array_options as $key => $option) {
278 $shortkey = preg_replace('/options_/', '', $key);
279 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
280 //var_dump($key);
281 //var_dump($clonedObj->array_options[$key]); exit;
282 unset($object->array_options[$key]);
283 }
284 }
285 }
286
287 // Create clone
288 $object->context['createfromclone'] = 'createfromclone';
289 $result = $object->createCommon($user);
290 if ($result < 0) {
291 $error++;
293 }
294
295 if (!$error) {
296 // copy internal contacts
297 if ($this->copy_linked_contact($object, 'internal') < 0) {
298 $error++;
299 }
300 }
301
302 if (!$error) {
303 // copy external contacts if same company
304 if (!empty($object->fk_soc) && $this->fk_soc == $object->fk_soc) {
305 if ($this->copy_linked_contact($object, 'external') < 0) {
306 $error++;
307 }
308 }
309 }
310
311 unset($object->context['createfromclone']);
312
313 // End
314 if (!$error) {
315 $this->db->commit();
316 return $object;
317 } else {
318 $this->db->rollback();
319 return -1;
320 }
321 }
322
330 public function fetch($id, $ref = null)
331 {
332 $result = $this->fetchCommon($id, $ref);
333 if ($result > 0 && !empty($this->table_element_line)) {
334 $this->fetchLines();
335 }
336 return $result;
337 }
338
344 public function fetchLines()
345 {
346 $this->lines = array();
347
348 $result = $this->fetchLinesCommon();
349 return $result;
350 }
351
352
365 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
366 {
367 dol_syslog(__METHOD__, LOG_DEBUG);
368
369 $records = array();
370
371 $sql = "SELECT ";
372 $sql .= $this->getFieldList('t');
373 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
374 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
375 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
376 } else {
377 $sql .= " WHERE 1 = 1";
378 }
379
380 // Manage filter
381 $errormessage = '';
382 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
383 if ($errormessage) {
384 $this->errors[] = $errormessage;
385 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
386 return -1;
387 }
388
389 if (!empty($sortfield)) {
390 $sql .= $this->db->order($sortfield, $sortorder);
391 }
392 if (!empty($limit)) {
393 $sql .= $this->db->plimit($limit, $offset);
394 }
395
396 $resql = $this->db->query($sql);
397 if ($resql) {
398 $num = $this->db->num_rows($resql);
399 $i = 0;
400 while ($i < ($limit ? min($limit, $num) : $num)) {
401 $obj = $this->db->fetch_object($resql);
402
403 $record = new self($this->db);
404 $record->setVarsFromFetchObj($obj);
405
406 $records[$record->id] = $record;
407
408 $i++;
409 }
410 $this->db->free($resql);
411
412 return $records;
413 } else {
414 $this->errors[] = 'Error '.$this->db->lasterror();
415 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
416
417 return -1;
418 }
419 }
420
428 public function update(User $user, $notrigger = 0)
429 {
430 return $this->updateCommon($user, $notrigger);
431 }
432
440 public function delete(User $user, $notrigger = 0)
441 {
442 return $this->deleteCommon($user, $notrigger);
443 //return $this->deleteCommon($user, $notrigger, 1);
444 }
445
454 public function deleteLine(User $user, $idline, $notrigger = 0)
455 {
456 if ($this->status < 0) {
457 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
458 return -2;
459 }
460
461 return $this->deleteLineCommon($user, $idline, $notrigger);
462 }
463
464
472 public function validate($user, $notrigger = 0)
473 {
474 global $conf;
475
476 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
477
478 $error = 0;
479
480 // Protection
481 if ($this->status == self::STATUS_VALIDATED) {
482 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
483 return 0;
484 }
485
486 $now = dol_now();
487
488 $this->db->begin();
489
490 // Define new ref
491 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
492 $num = $this->getNextNumRef();
493 } else {
494 $num = (string) $this->ref;
495 }
496 $this->newref = $num;
497
498 if (!empty($num)) {
499 // Validate
500 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
501 $sql .= " SET ref = '".$this->db->escape($num)."',";
502 $sql .= " status = ".self::STATUS_VALIDATED;
503 if (!empty($this->fields['date_validation'])) {
504 $sql .= ", date_validation = '".$this->db->idate($now)."'";
505 }
506 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
507 $sql .= ", fk_user_valid = ".((int) $user->id);
508 }
509 $sql .= " WHERE rowid = ".((int) $this->id);
510
511 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
512 $resql = $this->db->query($sql);
513 if (!$resql) {
514 dol_print_error($this->db);
515 $this->error = $this->db->lasterror();
516 $error++;
517 }
518
519 if (!$error && !$notrigger) {
520 // Call trigger
521 $result = $this->call_trigger('CALENDAR_VALIDATE', $user);
522 if ($result < 0) {
523 $error++;
524 }
525 // End call triggers
526 }
527 }
528
529 if (!$error) {
530 $this->oldref = $this->ref;
531
532 // Rename directory if dir was a temporary ref
533 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
534 // Now we rename also files into index
535 $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)."'";
536 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'calendar/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
537 $resql = $this->db->query($sql);
538 if (!$resql) {
539 $error++;
540 $this->error = $this->db->lasterror();
541 }
542 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'calendar/".$this->db->escape($this->newref)."'";
543 $sql .= " WHERE filepath = 'calendar/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
544 $resql = $this->db->query($sql);
545 if (!$resql) {
546 $error++;
547 $this->error = $this->db->lasterror();
548 }
549
550 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
551 $oldref = dol_sanitizeFileName($this->ref);
552 $newref = dol_sanitizeFileName($num);
553 $dirsource = $conf->bookcal->dir_output.'/calendar/'.$oldref;
554 $dirdest = $conf->bookcal->dir_output.'/calendar/'.$newref;
555 if (!$error && file_exists($dirsource)) {
556 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
557
558 if (@rename($dirsource, $dirdest)) {
559 dol_syslog("Rename ok");
560 // Rename docs starting with $oldref with $newref
561 $listoffiles = dol_dir_list($conf->bookcal->dir_output.'/calendar/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
562 foreach ($listoffiles as $fileentry) {
563 $dirsource = $fileentry['name'];
564 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
565 $dirsource = $fileentry['path'].'/'.$dirsource;
566 $dirdest = $fileentry['path'].'/'.$dirdest;
567 @rename($dirsource, $dirdest);
568 }
569 }
570 }
571 }
572 }
573
574 // Set new ref and current status
575 if (!$error) {
576 $this->ref = $num;
577 $this->status = self::STATUS_VALIDATED;
578 }
579
580 if (!$error) {
581 $this->db->commit();
582 return 1;
583 } else {
584 $this->db->rollback();
585 return -1;
586 }
587 }
588
589
597 public function setDraft($user, $notrigger = 0)
598 {
599 // Protection
600 if ($this->status <= self::STATUS_DRAFT) {
601 return 0;
602 }
603
604 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CALENDAR_UNVALIDATE');
605 }
606
614 public function cancel($user, $notrigger = 0)
615 {
616 // Protection
617 if ($this->status != self::STATUS_VALIDATED) {
618 return 0;
619 }
620
621 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CALENDAR_CANCEL');
622 }
623
631 public function reopen($user, $notrigger = 0)
632 {
633 // Protection
634 if ($this->status == self::STATUS_VALIDATED) {
635 return 0;
636 }
637
638 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CALENDAR_REOPEN');
639 }
640
647 public function getTooltipContentArray($params)
648 {
649 global $langs;
650
651 $datas = [];
652
653 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
654 return ['optimize' => $langs->trans("ShowCalendar")];
655 }
656 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Calendar").'</u>';
657 if (isset($this->status)) {
658 $datas['picto'] .= ' '.$this->getLibStatut(5);
659 }
660 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
661
662 return $datas;
663 }
664
675 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
676 {
677 global $conf, $langs, $hookmanager;
678
679 if (!empty($conf->dol_no_mouse_hover)) {
680 $notooltip = 1; // Force disable tooltips
681 }
682
683 $result = '';
684 $params = [
685 'id' => $this->id,
686 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
687 'option' => $option,
688 ];
689 $classfortooltip = 'classfortooltip';
690 $dataparams = '';
691 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
692 $classfortooltip = 'classforajaxtooltip';
693 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
694 $label = '';
695 } else {
696 $label = implode($this->getTooltipContentArray($params));
697 }
698
699 $url = DOL_URL_ROOT . '/bookcal/calendar_card.php?id='.$this->id;
700
701 if ($option !== 'nolink') {
702 // Add param to save lastsearch_values or not
703 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
704 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
705 $add_save_lastsearch_values = 1;
706 }
707 if ($add_save_lastsearch_values) {
708 $url .= '&save_lastsearch_values=1';
709 }
710 }
711
712 $linkclose = '';
713 if (empty($notooltip)) {
714 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
715 $label = $langs->trans("ShowCalendar");
716 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
717 }
718 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
719 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
720 } else {
721 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
722 }
723
724 if ($option == 'nolink') {
725 $linkstart = '<span';
726 } else {
727 $linkstart = '<a href="'.$url.'"';
728 }
729 $linkstart .= $linkclose.'>';
730 if ($option == 'nolink') {
731 $linkend = '</span>';
732 } else {
733 $linkend = '</a>';
734 }
735
736 $result .= $linkstart;
737
738 if (empty($this->showphoto_on_popup)) {
739 if ($withpicto) {
740 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
741 }
742 } else {
743 if ($withpicto) {
744 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
745
746 list($class, $module) = explode('@', $this->picto);
747 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
748 $filearray = dol_dir_list($upload_dir, "files");
749 $filename = $filearray[0]['name'];
750 if (!empty($filename)) {
751 $pospoint = strpos($filearray[0]['name'], '.');
752
753 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
754 if (!getDolGlobalInt(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
755 $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>';
756 } else {
757 $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>';
758 }
759
760 $result .= '</div>';
761 } else {
762 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
763 }
764 }
765 }
766
767 if ($withpicto != 2) {
768 $result .= $this->ref;
769 }
770
771 $result .= $linkend;
772 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
773
774 global $action, $hookmanager;
775 $hookmanager->initHooks(array($this->element.'dao'));
776 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
777 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
778 if ($reshook > 0) {
779 $result = $hookmanager->resPrint;
780 } else {
781 $result .= $hookmanager->resPrint;
782 }
783
784 return $result;
785 }
786
794 public function getKanbanView($option = '', $arraydata = null)
795 {
796 global $conf, $langs;
797
798 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
799
800 $return = '<div class="box-flex-item box-flex-grow-zero">';
801 $return .= '<div class="info-box info-box-sm">';
802 $return .= '<span class="info-box-icon bg-infobox-action">';
803 $return .= img_picto('', $this->picto);
804 $return .= '</span>';
805 $return .= '<div class="info-box-content">';
806 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl() . '</span>';
807 if ($selected >= 0) {
808 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
809 }
810 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
811 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
812 $return .= '</div>';
813 $return .= '</div>';
814 $return .= '</div>';
815
816 return $return;
817 }
818
825 public function getLabelStatus($mode = 0)
826 {
827 return $this->LibStatut($this->status, $mode);
828 }
829
836 public function getLibStatut($mode = 0)
837 {
838 return $this->LibStatut($this->status, $mode);
839 }
840
841 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
849 public function LibStatut($status, $mode = 0)
850 {
851 // phpcs:enable
852 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
853 global $langs;
854
855 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
856 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
857 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
858 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
859 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
860 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
861 }
862
863 $statusType = 'status'.$status;
864 if ($status == self::STATUS_VALIDATED) {
865 $statusType = 'status4';
866 }
867 if ($status == self::STATUS_CANCELED) {
868 $statusType = 'status6';
869 }
870
871 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
872 }
873
880 public function info($id)
881 {
882 $sql = "SELECT rowid,";
883 $sql .= " date_creation as datec, tms as datem,";
884 $sql .= " fk_user_creat, fk_user_modif";
885 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
886 $sql .= " WHERE t.rowid = ".((int) $id);
887
888 $result = $this->db->query($sql);
889 if ($result) {
890 if ($this->db->num_rows($result)) {
891 $obj = $this->db->fetch_object($result);
892
893 $this->id = $obj->rowid;
894
895 $this->user_creation_id = $obj->fk_user_creat;
896 $this->user_modification_id = $obj->fk_user_modif;
897 $this->date_creation = $this->db->jdate($obj->datec);
898 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
899 }
900
901 $this->db->free($result);
902 } else {
903 dol_print_error($this->db);
904 }
905 }
906
913 public function initAsSpecimen()
914 {
915 // Set here init that are not commonf fields
916 // $this->property1 = ...
917 // $this->property2 = ...
918
919 return $this->initAsSpecimenCommon();
920 }
921
927 public function getLinesArray()
928 {
929 $this->lines = array();
930
931 $objectline = new CalendarLine($this->db);
932 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_calendar:=:'.((int) $this->id).')');
933
934 if (is_numeric($result)) {
935 $this->setErrorsFromObject($objectline);
936 return $result;
937 } else {
938 $this->lines = $result;
939 // @phpstan-ignore-next-line
940 return $result; // @phan-suppress-current-line PhanTypeMismatchReturn
941 }
942 }
943
949 public function getNextNumRef()
950 {
951 // Not used
952 return '';
953 }
954
966 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
967 {
968 global $langs;
969
970 $result = 0;
971 /*
972 $langs->load("agenda");
973
974 if (!dol_strlen($modele)) {
975 $modele = 'standard_calendar';
976
977 if (!empty($this->model_pdf)) {
978 $modele = $this->model_pdf;
979 } elseif (getDolGlobalString('CALENDAR_ADDON_PDF')) {
980 $modele = getDolGlobalString('CALENDAR_ADDON_PDF');
981 }
982 }
983
984 $modelpath = "core/modules/bookcal/doc/";
985
986 if (!empty($modele)) {
987 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
988 }
989 */
990 return $result;
991 }
992}
993
994
995require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
996
1001{
1002 // To complete with content of an object CalendarLine
1003 // We should have a field rowid, fk_calendar and position
1004
1005
1011 public function __construct(DoliDB $db)
1012 {
1013 $this->db = $db;
1014
1015 $this->isextrafieldmanaged = 0;
1016 }
1017}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
Class for Calendar.
createFromClone(User $user, $fromid)
Clone an object into another one.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getLinesArray()
Create an array of lines.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
getTooltipContentArray($params)
getTooltipContentArray
getLabelStatus($mode=0)
Return the label of the status.
__construct(DoliDB $db)
Constructor.
setDraft($user, $notrigger=0)
Set draft status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
info($id)
Load the info information in the object.
LibStatut($status, $mode=0)
Return the label of a given status.
validate($user, $notrigger=0)
Validate object.
cancel($user, $notrigger=0)
Set cancel status.
getLibStatut($mode=0)
Return the label of the status.
create(User $user, $notrigger=0)
Create object into database.
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=0)
Delete a line of object in database.
reopen($user, $notrigger=0)
Set back to validated status.
fetch($id, $ref=null)
Load object in memory from the database.
fetchLines()
Load object lines in memory from the database.
update(User $user, $notrigger=0)
Update object into database.
Class CalendarLine.
__construct(DoliDB $db)
Constructor.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into 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.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
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.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_dir_list($utf8_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:64
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.