dolibarr 21.0.0-alpha
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-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2023 Alice Adminson <aadminson@example.com>
5 * Copyright (C) 2024 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//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31
36{
40 public $module = 'bookcal';
41
45 public $element = 'calendar';
46
50 public $table_element = 'bookcal_calendar';
51
55 public $picto = 'fa-calendar-check';
56
57
58 const STATUS_DRAFT = 0;
59 const STATUS_VALIDATED = 1;
60 const STATUS_CANCELED = 9;
61
62
102 // BEGIN MODULEBUILDER PROPERTIES
106 public $fields = array(
107 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'right', 'comment' => "Id"),
108 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 40, 'index' => 1),
109 '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'),
110 '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,),
111 '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',),
112 'type' => array('type' => 'integer', 'label' => 'Type', 'enabled' => 1, 'position' => 42, 'notnull' => 1, 'visible' => 1, 'arrayofkeyval' => array('0' => 'Customer', '1' => 'Supplier', '3' => 'Other'),),
113 '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,),
114 '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,),
115 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 3, 'validate' => 1,),
116 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,),
117 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,),
118 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
119 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
120 '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',),
121 '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',),
122 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
123 '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,),
124 );
125 public $rowid;
126 public $entity;
127 public $ref;
128 public $label;
129 public $type;
130 public $visibility;
131 public $fk_soc;
132 public $fk_project;
133 public $description;
134 public $note_public;
135 public $note_private;
136 public $fk_user_creat;
137 public $fk_user_modif;
138 public $import_key;
139 public $status;
140 // END MODULEBUILDER PROPERTIES
141
142
148 public function __construct(DoliDB $db)
149 {
150 global $langs, $user;
151
152 $this->db = $db;
153
154 $this->ismultientitymanaged = 1;
155 $this->isextrafieldmanaged = 1;
156
157 if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
158 $this->fields['rowid']['visible'] = 0;
159 }
160 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
161 $this->fields['entity']['enabled'] = 0;
162 }
163
164 // Example to show how to set values of fields definition dynamically
165 /*if ($user->hasRight('bookcal', 'calendar', 'read')) {
166 $this->fields['myfield']['visible'] = 1;
167 $this->fields['myfield']['noteditable'] = 0;
168 }*/
169 $this->fields['visibility']['default'] = $user->id;
170
171 // Unset fields that are disabled
172 foreach ($this->fields as $key => $val) {
173 if (isset($val['enabled']) && empty($val['enabled'])) {
174 unset($this->fields[$key]);
175 }
176 }
177
178 // Translate some data of arrayofkeyval
179 if (is_object($langs)) {
180 foreach ($this->fields as $key => $val) {
181 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
182 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
183 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
184 }
185 }
186 }
187 }
188 }
189
197 public function create(User $user, $notrigger = 0)
198 {
199 $resultcreate = $this->createCommon($user, $notrigger);
200
201 //$resultvalidate = $this->validate($user, $notrigger);
202
203 return $resultcreate;
204 }
205
213 public function createFromClone(User $user, $fromid)
214 {
215 global $langs, $extrafields;
216 $error = 0;
217
218 dol_syslog(__METHOD__, LOG_DEBUG);
219
220 $object = new self($this->db);
221
222 $this->db->begin();
223
224 // Load source object
225 $result = $object->fetchCommon($fromid);
226 if ($result > 0 && !empty($object->table_element_line)) {
227 $object->fetchLines();
228 }
229
230 // get lines so they will be clone
231 //foreach($this->lines as $line)
232 // $line->fetch_optionals();
233
234 // Reset some properties
235 unset($object->id);
236 unset($object->fk_user_creat);
237 unset($object->import_key);
238
239 // Clear fields
240 if (property_exists($object, 'ref')) {
241 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
242 }
243 if (property_exists($object, 'label')) {
244 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
245 }
246 if (property_exists($object, 'status')) {
247 $object->status = self::STATUS_DRAFT;
248 }
249 if (property_exists($object, 'date_creation')) {
250 $object->date_creation = dol_now();
251 }
252 if (property_exists($object, 'date_modification')) {
253 $object->date_modification = null;
254 }
255 // ...
256 // Clear extrafields that are unique
257 if (is_array($object->array_options) && count($object->array_options) > 0) {
258 $extrafields->fetch_name_optionals_label($this->table_element);
259 foreach ($object->array_options as $key => $option) {
260 $shortkey = preg_replace('/options_/', '', $key);
261 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
262 //var_dump($key);
263 //var_dump($clonedObj->array_options[$key]); exit;
264 unset($object->array_options[$key]);
265 }
266 }
267 }
268
269 // Create clone
270 $object->context['createfromclone'] = 'createfromclone';
271 $result = $object->createCommon($user);
272 if ($result < 0) {
273 $error++;
275 }
276
277 if (!$error) {
278 // copy internal contacts
279 if ($this->copy_linked_contact($object, 'internal') < 0) {
280 $error++;
281 }
282 }
283
284 if (!$error) {
285 // copy external contacts if same company
286 if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
287 if ($this->copy_linked_contact($object, 'external') < 0) {
288 $error++;
289 }
290 }
291 }
292
293 unset($object->context['createfromclone']);
294
295 // End
296 if (!$error) {
297 $this->db->commit();
298 return $object;
299 } else {
300 $this->db->rollback();
301 return -1;
302 }
303 }
304
312 public function fetch($id, $ref = null)
313 {
314 $result = $this->fetchCommon($id, $ref);
315 if ($result > 0 && !empty($this->table_element_line)) {
316 $this->fetchLines();
317 }
318 return $result;
319 }
320
326 public function fetchLines()
327 {
328 $this->lines = array();
329
330 $result = $this->fetchLinesCommon();
331 return $result;
332 }
333
334
347 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
348 {
349 dol_syslog(__METHOD__, LOG_DEBUG);
350
351 $records = array();
352
353 $sql = "SELECT ";
354 $sql .= $this->getFieldList('t');
355 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
356 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
357 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
358 } else {
359 $sql .= " WHERE 1 = 1";
360 }
361
362 // Manage filter
363 $errormessage = '';
364 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
365 if ($errormessage) {
366 $this->errors[] = $errormessage;
367 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
368 return -1;
369 }
370
371 if (!empty($sortfield)) {
372 $sql .= $this->db->order($sortfield, $sortorder);
373 }
374 if (!empty($limit)) {
375 $sql .= $this->db->plimit($limit, $offset);
376 }
377
378 $resql = $this->db->query($sql);
379 if ($resql) {
380 $num = $this->db->num_rows($resql);
381 $i = 0;
382 while ($i < ($limit ? min($limit, $num) : $num)) {
383 $obj = $this->db->fetch_object($resql);
384
385 $record = new self($this->db);
386 $record->setVarsFromFetchObj($obj);
387
388 $records[$record->id] = $record;
389
390 $i++;
391 }
392 $this->db->free($resql);
393
394 return $records;
395 } else {
396 $this->errors[] = 'Error '.$this->db->lasterror();
397 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
398
399 return -1;
400 }
401 }
402
410 public function update(User $user, $notrigger = 0)
411 {
412 return $this->updateCommon($user, $notrigger);
413 }
414
422 public function delete(User $user, $notrigger = 0)
423 {
424 return $this->deleteCommon($user, $notrigger);
425 //return $this->deleteCommon($user, $notrigger, 1);
426 }
427
436 public function deleteLine(User $user, $idline, $notrigger = 0)
437 {
438 if ($this->status < 0) {
439 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
440 return -2;
441 }
442
443 return $this->deleteLineCommon($user, $idline, $notrigger);
444 }
445
446
454 public function validate($user, $notrigger = 0)
455 {
456 global $conf;
457
458 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
459
460 $error = 0;
461
462 // Protection
463 if ($this->status == self::STATUS_VALIDATED) {
464 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
465 return 0;
466 }
467
468 $now = dol_now();
469
470 $this->db->begin();
471
472 // Define new ref
473 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
474 $num = $this->getNextNumRef();
475 } else {
476 $num = $this->ref;
477 }
478 $this->newref = $num;
479
480 if (!empty($num)) {
481 // Validate
482 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
483 $sql .= " SET ref = '".$this->db->escape($num)."',";
484 $sql .= " status = ".self::STATUS_VALIDATED;
485 if (!empty($this->fields['date_validation'])) {
486 $sql .= ", date_validation = '".$this->db->idate($now)."'";
487 }
488 if (!empty($this->fields['fk_user_valid'])) {
489 $sql .= ", fk_user_valid = ".((int) $user->id);
490 }
491 $sql .= " WHERE rowid = ".((int) $this->id);
492
493 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
494 $resql = $this->db->query($sql);
495 if (!$resql) {
496 dol_print_error($this->db);
497 $this->error = $this->db->lasterror();
498 $error++;
499 }
500
501 if (!$error && !$notrigger) {
502 // Call trigger
503 $result = $this->call_trigger('MYOBJECT_VALIDATE', $user);
504 if ($result < 0) {
505 $error++;
506 }
507 // End call triggers
508 }
509 }
510
511 if (!$error) {
512 $this->oldref = $this->ref;
513
514 // Rename directory if dir was a temporary ref
515 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
516 // Now we rename also files into index
517 $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)."'";
518 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'calendar/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
519 $resql = $this->db->query($sql);
520 if (!$resql) {
521 $error++;
522 $this->error = $this->db->lasterror();
523 }
524 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'calendar/".$this->db->escape($this->newref)."'";
525 $sql .= " WHERE filepath = 'calendar/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
526 $resql = $this->db->query($sql);
527 if (!$resql) {
528 $error++;
529 $this->error = $this->db->lasterror();
530 }
531
532 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
533 $oldref = dol_sanitizeFileName($this->ref);
534 $newref = dol_sanitizeFileName($num);
535 $dirsource = $conf->bookcal->dir_output.'/calendar/'.$oldref;
536 $dirdest = $conf->bookcal->dir_output.'/calendar/'.$newref;
537 if (!$error && file_exists($dirsource)) {
538 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
539
540 if (@rename($dirsource, $dirdest)) {
541 dol_syslog("Rename ok");
542 // Rename docs starting with $oldref with $newref
543 $listoffiles = dol_dir_list($conf->bookcal->dir_output.'/calendar/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
544 foreach ($listoffiles as $fileentry) {
545 $dirsource = $fileentry['name'];
546 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
547 $dirsource = $fileentry['path'].'/'.$dirsource;
548 $dirdest = $fileentry['path'].'/'.$dirdest;
549 @rename($dirsource, $dirdest);
550 }
551 }
552 }
553 }
554 }
555
556 // Set new ref and current status
557 if (!$error) {
558 $this->ref = $num;
559 $this->status = self::STATUS_VALIDATED;
560 }
561
562 if (!$error) {
563 $this->db->commit();
564 return 1;
565 } else {
566 $this->db->rollback();
567 return -1;
568 }
569 }
570
571
579 public function setDraft($user, $notrigger = 0)
580 {
581 // Protection
582 if ($this->status <= self::STATUS_DRAFT) {
583 return 0;
584 }
585
586 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MYOBJECT_UNVALIDATE');
587 }
588
596 public function cancel($user, $notrigger = 0)
597 {
598 // Protection
599 if ($this->status != self::STATUS_VALIDATED) {
600 return 0;
601 }
602
603 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MYOBJECT_CANCEL');
604 }
605
613 public function reopen($user, $notrigger = 0)
614 {
615 // Protection
616 if ($this->status == self::STATUS_VALIDATED) {
617 return 0;
618 }
619
620 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MYOBJECT_REOPEN');
621 }
622
630 public function getTooltipContentArray($params)
631 {
632 global $langs;
633
634 $datas = [];
635
636 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
637 return ['optimize' => $langs->trans("ShowCalendar")];
638 }
639 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Calendar").'</u>';
640 if (isset($this->status)) {
641 $datas['picto'] .= ' '.$this->getLibStatut(5);
642 }
643 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
644
645 return $datas;
646 }
647
658 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
659 {
660 global $conf, $langs, $hookmanager;
661
662 if (!empty($conf->dol_no_mouse_hover)) {
663 $notooltip = 1; // Force disable tooltips
664 }
665
666 $result = '';
667 $params = [
668 'id' => $this->id,
669 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
670 'option' => $option,
671 ];
672 $classfortooltip = 'classfortooltip';
673 $dataparams = '';
674 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
675 $classfortooltip = 'classforajaxtooltip';
676 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
677 $label = '';
678 } else {
679 $label = implode($this->getTooltipContentArray($params));
680 }
681
682 $url = dol_buildpath('/bookcal/calendar_card.php', 1).'?id='.$this->id;
683
684 if ($option !== 'nolink') {
685 // Add param to save lastsearch_values or not
686 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
687 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
688 $add_save_lastsearch_values = 1;
689 }
690 if ($url && $add_save_lastsearch_values) {
691 $url .= '&save_lastsearch_values=1';
692 }
693 }
694
695 $linkclose = '';
696 if (empty($notooltip)) {
697 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
698 $label = $langs->trans("ShowCalendar");
699 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
700 }
701 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
702 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
703 } else {
704 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
705 }
706
707 if ($option == 'nolink' || empty($url)) {
708 $linkstart = '<span';
709 } else {
710 $linkstart = '<a href="'.$url.'"';
711 }
712 $linkstart .= $linkclose.'>';
713 if ($option == 'nolink' || empty($url)) {
714 $linkend = '</span>';
715 } else {
716 $linkend = '</a>';
717 }
718
719 $result .= $linkstart;
720
721 if (empty($this->showphoto_on_popup)) {
722 if ($withpicto) {
723 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
724 }
725 } else {
726 if ($withpicto) {
727 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
728
729 list($class, $module) = explode('@', $this->picto);
730 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
731 $filearray = dol_dir_list($upload_dir, "files");
732 $filename = $filearray[0]['name'];
733 if (!empty($filename)) {
734 $pospoint = strpos($filearray[0]['name'], '.');
735
736 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
737 if (!getDolGlobalInt(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
738 $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>';
739 } else {
740 $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>';
741 }
742
743 $result .= '</div>';
744 } else {
745 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
746 }
747 }
748 }
749
750 if ($withpicto != 2) {
751 $result .= $this->ref;
752 }
753
754 $result .= $linkend;
755 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
756
757 global $action, $hookmanager;
758 $hookmanager->initHooks(array($this->element.'dao'));
759 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
760 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
761 if ($reshook > 0) {
762 $result = $hookmanager->resPrint;
763 } else {
764 $result .= $hookmanager->resPrint;
765 }
766
767 return $result;
768 }
769
777 public function getKanbanView($option = '', $arraydata = null)
778 {
779 global $conf, $langs;
780
781 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
782
783 $return = '<div class="box-flex-item box-flex-grow-zero">';
784 $return .= '<div class="info-box info-box-sm">';
785 $return .= '<span class="info-box-icon bg-infobox-action">';
786 $return .= img_picto('', $this->picto);
787 $return .= '</span>';
788 $return .= '<div class="info-box-content">';
789 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
790 if ($selected >= 0) {
791 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
792 }
793 if (property_exists($this, 'label')) {
794 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
795 }
796 if (property_exists($this, 'amount')) {
797 $return .= '<br>';
798 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
799 }
800 if (method_exists($this, 'getLibStatut')) {
801 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
802 }
803 $return .= '</div>';
804 $return .= '</div>';
805 $return .= '</div>';
806
807 return $return;
808 }
809
816 public function getLabelStatus($mode = 0)
817 {
818 return $this->LibStatut($this->status, $mode);
819 }
820
827 public function getLibStatut($mode = 0)
828 {
829 return $this->LibStatut($this->status, $mode);
830 }
831
832 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
840 public function LibStatut($status, $mode = 0)
841 {
842 // phpcs:enable
843 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
844 global $langs;
845
846 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
847 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
848 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
849 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
850 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
851 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
852 }
853
854 $statusType = 'status'.$status;
855 if ($status == self::STATUS_VALIDATED) {
856 $statusType = 'status4';
857 }
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 $this->date_creation = $this->db->jdate($obj->datec);
889 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
890 }
891
892 $this->db->free($result);
893 } else {
894 dol_print_error($this->db);
895 }
896 }
897
904 public function initAsSpecimen()
905 {
906 // Set here init that are not commonf fields
907 // $this->property1 = ...
908 // $this->property2 = ...
909
910 return $this->initAsSpecimenCommon();
911 }
912
918 public function getLinesArray()
919 {
920 $this->lines = array();
921
922 $objectline = new CalendarLine($this->db);
923 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_calendar:=:'.((int) $this->id).')');
924
925 if (is_numeric($result)) {
926 $this->setErrorsFromObject($objectline);
927 return $result;
928 } else {
929 $this->lines = $result;
930 return $this->lines;
931 }
932 }
933
939 public function getNextNumRef()
940 {
941 global $langs, $conf;
942 $langs->load("agenda");
943
944 if (getDolGlobalString('BOOKCAL_MYOBJECT_ADDON')) {
945 $conf->global->BOOKCAL_MYOBJECT_ADDON = 'mod_calendar_standard';
946 }
947
948 if (getDolGlobalString('BOOKCAL_MYOBJECT_ADDON')) {
949 $mybool = false;
950
951 $file = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON').".php";
952 $classname = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON');
953
954 // Include file with class
955 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
956 foreach ($dirmodels as $reldir) {
957 $dir = dol_buildpath($reldir."core/modules/bookcal/");
958
959 // Load file with numbering class (if found)
960 $mybool = ((bool) @include_once $dir.$file) || $mybool;
961 }
962
963 if ($mybool === false) {
964 dol_print_error(null, "Failed to include file ".$file);
965 return '';
966 }
967
968 if (class_exists($classname)) {
969 $obj = new $classname();
970 $numref = $obj->getNextValue($this);
971
972 if ($numref != '' && $numref != '-1') {
973 return $numref;
974 } else {
975 $this->error = $obj->error;
976 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
977 return "";
978 }
979 } else {
980 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
981 return "";
982 }
983 } else {
984 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
985 return "";
986 }
987 }
988
1000 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1001 {
1002 global $conf, $langs;
1003
1004 $result = 0;
1005 $includedocgeneration = 0;
1006
1007 $langs->load("agenda");
1008
1009 if (!dol_strlen($modele)) {
1010 $modele = 'standard_calendar';
1011
1012 if (!empty($this->model_pdf)) {
1013 $modele = $this->model_pdf;
1014 } elseif (getDolGlobalString('MYOBJECT_ADDON_PDF')) {
1015 $modele = getDolGlobalString('MYOBJECT_ADDON_PDF');
1016 }
1017 }
1018
1019 $modelpath = "core/modules/bookcal/doc/";
1020
1021 if ($includedocgeneration && !empty($modele)) {
1022 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1023 }
1024
1025 return $result;
1026 }
1027
1035 public function doScheduledJob()
1036 {
1037 //global $conf, $langs;
1038
1039 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1040
1041 $error = 0;
1042 $this->output = '';
1043 $this->error = '';
1044
1045 dol_syslog(__METHOD__, LOG_DEBUG);
1046
1047 $now = dol_now();
1048
1049 $this->db->begin();
1050
1051 // ...
1052
1053 $this->db->commit();
1054
1055 return $error;
1056 }
1057}
1058
1059
1060require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1061
1066{
1067 // To complete with content of an object CalendarLine
1068 // We should have a field rowid, fk_calendar and position
1069
1070
1076 public function __construct(DoliDB $db)
1077 {
1078 $this->db = $db;
1079
1080 $this->isextrafieldmanaged = 0;
1081 }
1082}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$object ref
Definition info.php:79
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.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
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.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
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.
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.
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:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.