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 );
128 public $rowid;
132 public $entity;
136 public $ref;
140 public $label;
144 public $type;
148 public $visibility;
152 public $fk_soc;
156 public $fk_project;
160 public $description;
164 public $note_public;
168 public $note_private;
172 public $fk_user_creat;
176 public $fk_user_modif;
180 public $import_key;
184 public $status;
185 // END MODULEBUILDER PROPERTIES
186
187
193 public function __construct(DoliDB $db)
194 {
195 global $langs, $user;
196
197 $this->db = $db;
198
199 $this->ismultientitymanaged = 1;
200 $this->isextrafieldmanaged = 1;
201
202 if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
203 $this->fields['rowid']['visible'] = 0;
204 }
205 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
206 $this->fields['entity']['enabled'] = 0;
207 }
208
209 // Example to show how to set values of fields definition dynamically
210 /*if ($user->hasRight('bookcal', 'calendar', 'read')) {
211 $this->fields['myfield']['visible'] = 1;
212 $this->fields['myfield']['noteditable'] = 0;
213 }*/
214 $this->fields['visibility']['default'] = $user->id;
215
216 // Unset fields that are disabled
217 foreach ($this->fields as $key => $val) {
218 if (isset($val['enabled']) && empty($val['enabled'])) {
219 unset($this->fields[$key]);
220 }
221 }
222
223 // Translate some data of arrayofkeyval
224 if (is_object($langs)) {
225 foreach ($this->fields as $key => $val) {
226 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
227 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
228 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
229 }
230 }
231 }
232 }
233 }
234
242 public function create(User $user, $notrigger = 0)
243 {
244 $resultcreate = $this->createCommon($user, $notrigger);
245
246 //$resultvalidate = $this->validate($user, $notrigger);
247
248 return $resultcreate;
249 }
250
258 public function createFromClone(User $user, $fromid)
259 {
260 global $langs, $extrafields;
261 $error = 0;
262
263 dol_syslog(__METHOD__, LOG_DEBUG);
264
265 $object = new self($this->db);
266
267 $this->db->begin();
268
269 // Load source object
270 $result = $object->fetchCommon($fromid);
271 if ($result > 0 && !empty($object->table_element_line)) {
272 $object->fetchLines();
273 }
274
275 // get lines so they will be cloned
276 //foreach($this->lines as $line)
277 // $line->fetch_optionals();
278
279 // Reset some properties
280 unset($object->id);
281 unset($object->fk_user_creat);
282 unset($object->import_key);
283
284 // Clear fields
285 if (property_exists($object, 'ref')) {
286 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
287 }
288 if (property_exists($object, 'label')) {
289 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
290 }
291 if (property_exists($object, 'status')) {
292 $object->status = self::STATUS_DRAFT;
293 }
294 if (property_exists($object, 'date_creation')) {
295 $object->date_creation = dol_now();
296 }
297 if (property_exists($object, 'date_modification')) {
298 $object->date_modification = null;
299 }
300 // ...
301 // Clear extrafields that are unique
302 if (is_array($object->array_options) && count($object->array_options) > 0) {
303 $extrafields->fetch_name_optionals_label($this->table_element);
304 foreach ($object->array_options as $key => $option) {
305 $shortkey = preg_replace('/options_/', '', $key);
306 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
307 //var_dump($key);
308 //var_dump($clonedObj->array_options[$key]); exit;
309 unset($object->array_options[$key]);
310 }
311 }
312 }
313
314 // Create clone
315 $object->context['createfromclone'] = 'createfromclone';
316 $result = $object->createCommon($user);
317 if ($result < 0) {
318 $error++;
320 }
321
322 if (!$error) {
323 // copy internal contacts
324 if ($this->copy_linked_contact($object, 'internal') < 0) {
325 $error++;
326 }
327 }
328
329 if (!$error) {
330 // copy external contacts if same company
331 if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
332 if ($this->copy_linked_contact($object, 'external') < 0) {
333 $error++;
334 }
335 }
336 }
337
338 unset($object->context['createfromclone']);
339
340 // End
341 if (!$error) {
342 $this->db->commit();
343 return $object;
344 } else {
345 $this->db->rollback();
346 return -1;
347 }
348 }
349
357 public function fetch($id, $ref = null)
358 {
359 $result = $this->fetchCommon($id, $ref);
360 if ($result > 0 && !empty($this->table_element_line)) {
361 $this->fetchLines();
362 }
363 return $result;
364 }
365
371 public function fetchLines()
372 {
373 $this->lines = array();
374
375 $result = $this->fetchLinesCommon();
376 return $result;
377 }
378
379
392 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
393 {
394 dol_syslog(__METHOD__, LOG_DEBUG);
395
396 $records = array();
397
398 $sql = "SELECT ";
399 $sql .= $this->getFieldList('t');
400 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
401 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
402 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
403 } else {
404 $sql .= " WHERE 1 = 1";
405 }
406
407 // Manage filter
408 $errormessage = '';
409 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
410 if ($errormessage) {
411 $this->errors[] = $errormessage;
412 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
413 return -1;
414 }
415
416 if (!empty($sortfield)) {
417 $sql .= $this->db->order($sortfield, $sortorder);
418 }
419 if (!empty($limit)) {
420 $sql .= $this->db->plimit($limit, $offset);
421 }
422
423 $resql = $this->db->query($sql);
424 if ($resql) {
425 $num = $this->db->num_rows($resql);
426 $i = 0;
427 while ($i < ($limit ? min($limit, $num) : $num)) {
428 $obj = $this->db->fetch_object($resql);
429
430 $record = new self($this->db);
431 $record->setVarsFromFetchObj($obj);
432
433 $records[$record->id] = $record;
434
435 $i++;
436 }
437 $this->db->free($resql);
438
439 return $records;
440 } else {
441 $this->errors[] = 'Error '.$this->db->lasterror();
442 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
443
444 return -1;
445 }
446 }
447
455 public function update(User $user, $notrigger = 0)
456 {
457 return $this->updateCommon($user, $notrigger);
458 }
459
467 public function delete(User $user, $notrigger = 0)
468 {
469 return $this->deleteCommon($user, $notrigger);
470 //return $this->deleteCommon($user, $notrigger, 1);
471 }
472
481 public function deleteLine(User $user, $idline, $notrigger = 0)
482 {
483 if ($this->status < 0) {
484 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
485 return -2;
486 }
487
488 return $this->deleteLineCommon($user, $idline, $notrigger);
489 }
490
491
499 public function validate($user, $notrigger = 0)
500 {
501 global $conf;
502
503 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
504
505 $error = 0;
506
507 // Protection
508 if ($this->status == self::STATUS_VALIDATED) {
509 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
510 return 0;
511 }
512
513 $now = dol_now();
514
515 $this->db->begin();
516
517 // Define new ref
518 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
519 $num = $this->getNextNumRef();
520 } else {
521 $num = $this->ref;
522 }
523 $this->newref = $num;
524
525 if (!empty($num)) {
526 // Validate
527 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
528 $sql .= " SET ref = '".$this->db->escape($num)."',";
529 $sql .= " status = ".self::STATUS_VALIDATED;
530 if (!empty($this->fields['date_validation'])) {
531 $sql .= ", date_validation = '".$this->db->idate($now)."'";
532 }
533 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
534 $sql .= ", fk_user_valid = ".((int) $user->id);
535 }
536 $sql .= " WHERE rowid = ".((int) $this->id);
537
538 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
539 $resql = $this->db->query($sql);
540 if (!$resql) {
541 dol_print_error($this->db);
542 $this->error = $this->db->lasterror();
543 $error++;
544 }
545
546 if (!$error && !$notrigger) {
547 // Call trigger
548 $result = $this->call_trigger('MYOBJECT_VALIDATE', $user);
549 if ($result < 0) {
550 $error++;
551 }
552 // End call triggers
553 }
554 }
555
556 if (!$error) {
557 $this->oldref = $this->ref;
558
559 // Rename directory if dir was a temporary ref
560 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
561 // Now we rename also files into index
562 $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)."'";
563 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'calendar/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
564 $resql = $this->db->query($sql);
565 if (!$resql) {
566 $error++;
567 $this->error = $this->db->lasterror();
568 }
569 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'calendar/".$this->db->escape($this->newref)."'";
570 $sql .= " WHERE filepath = 'calendar/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
571 $resql = $this->db->query($sql);
572 if (!$resql) {
573 $error++;
574 $this->error = $this->db->lasterror();
575 }
576
577 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
578 $oldref = dol_sanitizeFileName($this->ref);
579 $newref = dol_sanitizeFileName($num);
580 $dirsource = $conf->bookcal->dir_output.'/calendar/'.$oldref;
581 $dirdest = $conf->bookcal->dir_output.'/calendar/'.$newref;
582 if (!$error && file_exists($dirsource)) {
583 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
584
585 if (@rename($dirsource, $dirdest)) {
586 dol_syslog("Rename ok");
587 // Rename docs starting with $oldref with $newref
588 $listoffiles = dol_dir_list($conf->bookcal->dir_output.'/calendar/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
589 foreach ($listoffiles as $fileentry) {
590 $dirsource = $fileentry['name'];
591 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
592 $dirsource = $fileentry['path'].'/'.$dirsource;
593 $dirdest = $fileentry['path'].'/'.$dirdest;
594 @rename($dirsource, $dirdest);
595 }
596 }
597 }
598 }
599 }
600
601 // Set new ref and current status
602 if (!$error) {
603 $this->ref = $num;
604 $this->status = self::STATUS_VALIDATED;
605 }
606
607 if (!$error) {
608 $this->db->commit();
609 return 1;
610 } else {
611 $this->db->rollback();
612 return -1;
613 }
614 }
615
616
624 public function setDraft($user, $notrigger = 0)
625 {
626 // Protection
627 if ($this->status <= self::STATUS_DRAFT) {
628 return 0;
629 }
630
631 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MYOBJECT_UNVALIDATE');
632 }
633
641 public function cancel($user, $notrigger = 0)
642 {
643 // Protection
644 if ($this->status != self::STATUS_VALIDATED) {
645 return 0;
646 }
647
648 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MYOBJECT_CANCEL');
649 }
650
658 public function reopen($user, $notrigger = 0)
659 {
660 // Protection
661 if ($this->status == self::STATUS_VALIDATED) {
662 return 0;
663 }
664
665 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MYOBJECT_REOPEN');
666 }
667
675 public function getTooltipContentArray($params)
676 {
677 global $langs;
678
679 $datas = [];
680
681 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
682 return ['optimize' => $langs->trans("ShowCalendar")];
683 }
684 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Calendar").'</u>';
685 if (isset($this->status)) {
686 $datas['picto'] .= ' '.$this->getLibStatut(5);
687 }
688 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
689
690 return $datas;
691 }
692
703 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
704 {
705 global $conf, $langs, $hookmanager;
706
707 if (!empty($conf->dol_no_mouse_hover)) {
708 $notooltip = 1; // Force disable tooltips
709 }
710
711 $result = '';
712 $params = [
713 'id' => $this->id,
714 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
715 'option' => $option,
716 ];
717 $classfortooltip = 'classfortooltip';
718 $dataparams = '';
719 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
720 $classfortooltip = 'classforajaxtooltip';
721 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
722 $label = '';
723 } else {
724 $label = implode($this->getTooltipContentArray($params));
725 }
726
727 $url = dol_buildpath('/bookcal/calendar_card.php', 1).'?id='.$this->id;
728
729 if ($option !== 'nolink') {
730 // Add param to save lastsearch_values or not
731 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
732 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
733 $add_save_lastsearch_values = 1;
734 }
735 if ($url && $add_save_lastsearch_values) {
736 $url .= '&save_lastsearch_values=1';
737 }
738 }
739
740 $linkclose = '';
741 if (empty($notooltip)) {
742 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
743 $label = $langs->trans("ShowCalendar");
744 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
745 }
746 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
747 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
748 } else {
749 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
750 }
751
752 if ($option == 'nolink' || empty($url)) {
753 $linkstart = '<span';
754 } else {
755 $linkstart = '<a href="'.$url.'"';
756 }
757 $linkstart .= $linkclose.'>';
758 if ($option == 'nolink' || empty($url)) {
759 $linkend = '</span>';
760 } else {
761 $linkend = '</a>';
762 }
763
764 $result .= $linkstart;
765
766 if (empty($this->showphoto_on_popup)) {
767 if ($withpicto) {
768 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
769 }
770 } else {
771 if ($withpicto) {
772 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
773
774 list($class, $module) = explode('@', $this->picto);
775 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
776 $filearray = dol_dir_list($upload_dir, "files");
777 $filename = $filearray[0]['name'];
778 if (!empty($filename)) {
779 $pospoint = strpos($filearray[0]['name'], '.');
780
781 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
782 if (!getDolGlobalInt(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
783 $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>';
784 } else {
785 $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>';
786 }
787
788 $result .= '</div>';
789 } else {
790 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
791 }
792 }
793 }
794
795 if ($withpicto != 2) {
796 $result .= $this->ref;
797 }
798
799 $result .= $linkend;
800 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
801
802 global $action, $hookmanager;
803 $hookmanager->initHooks(array($this->element.'dao'));
804 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
805 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
806 if ($reshook > 0) {
807 $result = $hookmanager->resPrint;
808 } else {
809 $result .= $hookmanager->resPrint;
810 }
811
812 return $result;
813 }
814
822 public function getKanbanView($option = '', $arraydata = null)
823 {
824 global $conf, $langs;
825
826 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
827
828 $return = '<div class="box-flex-item box-flex-grow-zero">';
829 $return .= '<div class="info-box info-box-sm">';
830 $return .= '<span class="info-box-icon bg-infobox-action">';
831 $return .= img_picto('', $this->picto);
832 $return .= '</span>';
833 $return .= '<div class="info-box-content">';
834 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
835 if ($selected >= 0) {
836 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
837 }
838 if (property_exists($this, 'label')) {
839 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
840 }
841 if (property_exists($this, 'amount')) {
842 $return .= '<br>';
843 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
844 }
845 if (method_exists($this, 'getLibStatut')) {
846 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
847 }
848 $return .= '</div>';
849 $return .= '</div>';
850 $return .= '</div>';
851
852 return $return;
853 }
854
861 public function getLabelStatus($mode = 0)
862 {
863 return $this->LibStatut($this->status, $mode);
864 }
865
872 public function getLibStatut($mode = 0)
873 {
874 return $this->LibStatut($this->status, $mode);
875 }
876
877 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
885 public function LibStatut($status, $mode = 0)
886 {
887 // phpcs:enable
888 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
889 global $langs;
890
891 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
892 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
893 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
894 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
895 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
896 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
897 }
898
899 $statusType = 'status'.$status;
900 if ($status == self::STATUS_VALIDATED) {
901 $statusType = 'status4';
902 }
903 if ($status == self::STATUS_CANCELED) {
904 $statusType = 'status6';
905 }
906
907 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
908 }
909
916 public function info($id)
917 {
918 $sql = "SELECT rowid,";
919 $sql .= " date_creation as datec, tms as datem,";
920 $sql .= " fk_user_creat, fk_user_modif";
921 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
922 $sql .= " WHERE t.rowid = ".((int) $id);
923
924 $result = $this->db->query($sql);
925 if ($result) {
926 if ($this->db->num_rows($result)) {
927 $obj = $this->db->fetch_object($result);
928
929 $this->id = $obj->rowid;
930
931 $this->user_creation_id = $obj->fk_user_creat;
932 $this->user_modification_id = $obj->fk_user_modif;
933 $this->date_creation = $this->db->jdate($obj->datec);
934 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
935 }
936
937 $this->db->free($result);
938 } else {
939 dol_print_error($this->db);
940 }
941 }
942
949 public function initAsSpecimen()
950 {
951 // Set here init that are not commonf fields
952 // $this->property1 = ...
953 // $this->property2 = ...
954
955 return $this->initAsSpecimenCommon();
956 }
957
963 public function getLinesArray()
964 {
965 $this->lines = array();
966
967 $objectline = new CalendarLine($this->db);
968 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_calendar:=:'.((int) $this->id).')');
969
970 if (is_numeric($result)) {
971 $this->setErrorsFromObject($objectline);
972 return $result;
973 } else {
974 $this->lines = $result;
975 return $this->lines;
976 }
977 }
978
984 public function getNextNumRef()
985 {
986 global $langs, $conf;
987 $langs->load("agenda");
988
989 if (getDolGlobalString('BOOKCAL_MYOBJECT_ADDON')) {
990 $conf->global->BOOKCAL_MYOBJECT_ADDON = 'mod_calendar_standard';
991 }
992
993 if (getDolGlobalString('BOOKCAL_MYOBJECT_ADDON')) {
994 $mybool = false;
995
996 $file = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON').".php";
997 $classname = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON');
998
999 // Include file with class
1000 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1001 foreach ($dirmodels as $reldir) {
1002 $dir = dol_buildpath($reldir."core/modules/bookcal/");
1003
1004 // Load file with numbering class (if found)
1005 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1006 }
1007
1008 if (!$mybool) {
1009 dol_print_error(null, "Failed to include file ".$file);
1010 return '';
1011 }
1012
1013 if (class_exists($classname)) {
1014 $obj = new $classname();
1015 '@phan-var-force CommonNumRefGenerator $obj';
1016
1017 $numref = $obj->getNextValue($this);
1018
1019 if ($numref != '' && $numref != '-1') {
1020 return $numref;
1021 } else {
1022 $this->error = $obj->error;
1023 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1024 return "";
1025 }
1026 } else {
1027 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1028 return "";
1029 }
1030 } else {
1031 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1032 return "";
1033 }
1034 }
1035
1047 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1048 {
1049 global $conf, $langs;
1050
1051 $result = 0;
1052 $includedocgeneration = 0;
1053
1054 $langs->load("agenda");
1055
1056 if (!dol_strlen($modele)) {
1057 $modele = 'standard_calendar';
1058
1059 if (!empty($this->model_pdf)) {
1060 $modele = $this->model_pdf;
1061 } elseif (getDolGlobalString('MYOBJECT_ADDON_PDF')) {
1062 $modele = getDolGlobalString('MYOBJECT_ADDON_PDF');
1063 }
1064 }
1065
1066 $modelpath = "core/modules/bookcal/doc/";
1067
1068 if ($includedocgeneration && !empty($modele)) {
1069 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1070 }
1071
1072 return $result;
1073 }
1074
1082 public function doScheduledJob()
1083 {
1084 //global $conf, $langs;
1085
1086 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1087
1088 $error = 0;
1089 $this->output = '';
1090 $this->error = '';
1091
1092 dol_syslog(__METHOD__, LOG_DEBUG);
1093
1094 $now = dol_now();
1095
1096 $this->db->begin();
1097
1098 // ...
1099
1100 $this->db->commit();
1101
1102 return $error;
1103 }
1104}
1105
1106
1107require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1108
1113{
1114 // To complete with content of an object CalendarLine
1115 // We should have a field rowid, fk_calendar and position
1116
1117
1123 public function __construct(DoliDB $db)
1124 {
1125 $this->db = $db;
1126
1127 $this->isextrafieldmanaged = 0;
1128 }
1129}
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:634
$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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.