dolibarr 18.0.6
availabilities.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2022 Alice Adminson <aadminson@example.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Put here all includes required by your class file
26require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29
34{
38 public $module = 'bookcal';
39
43 public $element = 'availabilities';
44
48 public $table_element = 'bookcal_availabilities';
49
54 public $ismultientitymanaged = 0;
55
59 public $isextrafieldmanaged = 1;
60
64 public $picto = 'fa-file';
65
66
67 const STATUS_DRAFT = 0;
68 const STATUS_VALIDATED = 1;
69 const STATUS_CANCELED = 9;
70
71
100 // BEGIN MODULEBUILDER PROPERTIES
104 public $fields=array(
105 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
106 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'validate'=>'1', 'comment'=>"Reference of object"),
107 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'help'=>"Help text", 'showoncombobox'=>'2', 'validate'=>'1',),
108 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3, 'validate'=>'1',),
109 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0, 'cssview'=>'wordbreak', 'validate'=>'1',),
110 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0, 'cssview'=>'wordbreak', 'validate'=>'1',),
111 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
112 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
113 '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',),
114 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'picto'=>'user', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
115 'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,),
116 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
117 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
118 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>2000, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '9'=>'Canceled'), 'validate'=>'1',),
119 'start' => array('type'=>'date', 'label'=>'Start Date', 'enabled'=>'1', 'position'=>40, 'notnull'=>1, 'visible'=>1, 'searchall'=>1),
120 'end' => array('type'=>'date', 'label'=>'End Date', 'enabled'=>'1', 'position'=>45, 'notnull'=>1, 'visible'=>1, 'searchall'=>1),
121 'type' => array('type'=>'integer', 'label'=>'Type', 'enabled'=>'1', 'position'=>49, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Customer', '1'=>'Supplier', '2'=>'Else'),),
122 'duration' => array('type'=>'integer', 'label'=>'Duration', 'enabled'=>'1', 'position'=>47, 'notnull'=>1, 'visible'=>1, 'default'=>'30'),
123 'startHour' => array('type'=>'integer', 'label'=>'Start Hour', 'enabled'=>'1', 'position'=>46, 'notnull'=>1, 'visible'=>-1,),
124 'endHour' => array('type'=>'integer', 'label'=>'End Hour', 'enabled'=>'1', 'position'=>46.5, 'notnull'=>1, 'visible'=>-1,),
125 );
126 public $rowid;
127 public $ref;
128 public $label;
129 public $description;
130 public $note_public;
131 public $note_private;
132 public $date_creation;
133 public $tms;
134 public $fk_user_creat;
135 public $fk_user_modif;
136 public $last_main_doc;
137 public $import_key;
138 public $model_pdf;
139 public $status;
140 public $start;
141 public $end;
142 public $type;
143 public $duration;
144 public $startHour;
145 public $endHour;
146 // END MODULEBUILDER PROPERTIES
147
148
149 // If this object has a subtable with lines
150
151 // /**
152 // * @var string Name of subtable line
153 // */
154 // public $table_element_line = 'bookcal_availabilitiesline';
155
156 // /**
157 // * @var string Field with ID of parent key if this object has a parent
158 // */
159 // public $fk_element = 'fk_availabilities';
160
161 // /**
162 // * @var string Name of subtable class that manage subtable lines
163 // */
164 // public $class_element_line = 'Availabilitiesline';
165
166 // /**
167 // * @var array List of child tables. To test if we can delete object.
168 // */
169 // protected $childtables = array();
170
171 // /**
172 // * @var array List of child tables. To know object to delete on cascade.
173 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
174 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
175 // */
176 // protected $childtablesoncascade = array('bookcal_availabilitiesdet');
177
178 // /**
179 // * @var AvailabilitiesLine[] Array of subtable lines
180 // */
181 // public $lines = array();
182
183
184
190 public function __construct(DoliDB $db)
191 {
192 global $conf, $langs;
193
194 $this->db = $db;
195
196 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
197 $this->fields['rowid']['visible'] = 0;
198 }
199 if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
200 $this->fields['entity']['enabled'] = 0;
201 }
202
203 // Example to show how to set values of fields definition dynamically
204 /*if ($user->hasRight('bookcal', 'availabilities', 'read')) {
205 $this->fields['myfield']['visible'] = 1;
206 $this->fields['myfield']['noteditable'] = 0;
207 }*/
208
209 // Unset fields that are disabled
210 foreach ($this->fields as $key => $val) {
211 if (isset($val['enabled']) && empty($val['enabled'])) {
212 unset($this->fields[$key]);
213 }
214 }
215
216 // Translate some data of arrayofkeyval
217 if (is_object($langs)) {
218 foreach ($this->fields as $key => $val) {
219 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
220 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
221 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
222 }
223 }
224 }
225 }
226 }
227
235 public function create(User $user, $notrigger = false)
236 {
237 $resultcreate = $this->createCommon($user, $notrigger);
238
239 //$resultvalidate = $this->validate($user, $notrigger);
240
241 return $resultcreate;
242 }
243
251 public function createFromClone(User $user, $fromid)
252 {
253 global $langs, $extrafields;
254 $error = 0;
255
256 dol_syslog(__METHOD__, LOG_DEBUG);
257
258 $object = new self($this->db);
259
260 $this->db->begin();
261
262 // Load source object
263 $result = $object->fetchCommon($fromid);
264 if ($result > 0 && !empty($object->table_element_line)) {
265 $object->fetchLines();
266 }
267
268 // get lines so they will be clone
269 //foreach($this->lines as $line)
270 // $line->fetch_optionals();
271
272 // Reset some properties
273 unset($object->id);
274 unset($object->fk_user_creat);
275 unset($object->import_key);
276
277 // Clear fields
278 if (property_exists($object, 'ref')) {
279 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
280 }
281 if (property_exists($object, 'label')) {
282 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
283 }
284 if (property_exists($object, 'status')) {
285 $object->status = self::STATUS_DRAFT;
286 }
287 if (property_exists($object, 'date_creation')) {
288 $object->date_creation = dol_now();
289 }
290 if (property_exists($object, 'date_modification')) {
291 $object->date_modification = null;
292 }
293 // ...
294 // Clear extrafields that are unique
295 if (is_array($object->array_options) && count($object->array_options) > 0) {
296 $extrafields->fetch_name_optionals_label($this->table_element);
297 foreach ($object->array_options as $key => $option) {
298 $shortkey = preg_replace('/options_/', '', $key);
299 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
300 //var_dump($key);
301 //var_dump($clonedObj->array_options[$key]); exit;
302 unset($object->array_options[$key]);
303 }
304 }
305 }
306
307 // Create clone
308 $object->context['createfromclone'] = 'createfromclone';
309 $result = $object->createCommon($user);
310 if ($result < 0) {
311 $error++;
312 $this->error = $object->error;
313 $this->errors = $object->errors;
314 }
315
316 if (!$error) {
317 // copy internal contacts
318 if ($this->copy_linked_contact($object, 'internal') < 0) {
319 $error++;
320 }
321 }
322
323 if (!$error) {
324 // copy external contacts if same company
325 if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
326 if ($this->copy_linked_contact($object, 'external') < 0) {
327 $error++;
328 }
329 }
330 }
331
332 unset($object->context['createfromclone']);
333
334 // End
335 if (!$error) {
336 $this->db->commit();
337 return $object;
338 } else {
339 $this->db->rollback();
340 return -1;
341 }
342 }
343
351 public function fetch($id, $ref = null)
352 {
353 $result = $this->fetchCommon($id, $ref);
354 if ($result > 0 && !empty($this->table_element_line)) {
355 $this->fetchLines();
356 }
357 return $result;
358 }
359
365 public function fetchLines()
366 {
367 $this->lines = array();
368
369 $result = $this->fetchLinesCommon();
370 return $result;
371 }
372
373
385 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
386 {
387 global $conf;
388
389 dol_syslog(__METHOD__, LOG_DEBUG);
390
391 $records = array();
392
393 $sql = "SELECT ";
394 $sql .= $this->getFieldList('t');
395 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
396 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
397 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
398 } else {
399 $sql .= " WHERE 1 = 1";
400 }
401 // Manage filter
402 $sqlwhere = array();
403 if (count($filter) > 0) {
404 foreach ($filter as $key => $value) {
405 if ($key == 't.rowid') {
406 $sqlwhere[] = $key." = ".((int) $value);
407 } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
408 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
409 } elseif ($key == 'customsql') {
410 $sqlwhere[] = $value;
411 } elseif (strpos($value, '%') === false) {
412 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
413 } else {
414 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
415 }
416 }
417 }
418 if (count($sqlwhere) > 0) {
419 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
420 }
421
422 if (!empty($sortfield)) {
423 $sql .= $this->db->order($sortfield, $sortorder);
424 }
425 if (!empty($limit)) {
426 $sql .= $this->db->plimit($limit, $offset);
427 }
428
429 $resql = $this->db->query($sql);
430 if ($resql) {
431 $num = $this->db->num_rows($resql);
432 $i = 0;
433 while ($i < ($limit ? min($limit, $num) : $num)) {
434 $obj = $this->db->fetch_object($resql);
435
436 $record = new self($this->db);
437 $record->setVarsFromFetchObj($obj);
438
439 $records[$record->id] = $record;
440
441 $i++;
442 }
443 $this->db->free($resql);
444
445 return $records;
446 } else {
447 $this->errors[] = 'Error '.$this->db->lasterror();
448 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
449
450 return -1;
451 }
452 }
453
461 public function update(User $user, $notrigger = false)
462 {
463 return $this->updateCommon($user, $notrigger);
464 }
465
473 public function delete(User $user, $notrigger = false)
474 {
475 return $this->deleteCommon($user, $notrigger);
476 //return $this->deleteCommon($user, $notrigger, 1);
477 }
478
487 public function deleteLine(User $user, $idline, $notrigger = false)
488 {
489 if ($this->status < 0) {
490 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
491 return -2;
492 }
493
494 return $this->deleteLineCommon($user, $idline, $notrigger);
495 }
496
497
505 public function validate($user, $notrigger = 0)
506 {
507 global $conf, $langs;
508
509 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
510
511 $error = 0;
512
513 // Protection
514 if ($this->status == self::STATUS_VALIDATED) {
515 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
516 return 0;
517 }
518
519 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight('bookcal', 'availabilities', 'write'))
520 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->availabilities->availabilities_advance->validate))))
521 {
522 $this->error='NotEnoughPermissions';
523 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
524 return -1;
525 }*/
526
527 $now = dol_now();
528
529 $this->db->begin();
530
531 // Define new ref
532 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
533 $num = $this->getNextNumRef();
534 } else {
535 $num = $this->ref;
536 }
537 $this->newref = $num;
538
539 if (!empty($num)) {
540 // Validate
541 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
542 $sql .= " SET ref = '".$this->db->escape($num)."',";
543 $sql .= " status = ".self::STATUS_VALIDATED;
544 if (!empty($this->fields['date_validation'])) {
545 $sql .= ", date_validation = '".$this->db->idate($now)."'";
546 }
547 if (!empty($this->fields['fk_user_valid'])) {
548 $sql .= ", fk_user_valid = ".((int) $user->id);
549 }
550 $sql .= " WHERE rowid = ".((int) $this->id);
551
552 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
553 $resql = $this->db->query($sql);
554 if (!$resql) {
555 dol_print_error($this->db);
556 $this->error = $this->db->lasterror();
557 $error++;
558 }
559
560 if (!$error && !$notrigger) {
561 // Call trigger
562 $result = $this->call_trigger('AVAILABILITIES_VALIDATE', $user);
563 if ($result < 0) {
564 $error++;
565 }
566 // End call triggers
567 }
568 }
569
570 if (!$error) {
571 $this->oldref = $this->ref;
572
573 // Rename directory if dir was a temporary ref
574 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
575 // Now we rename also files into index
576 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'availabilities/".$this->db->escape($this->newref)."'";
577 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'availabilities/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
578 $resql = $this->db->query($sql);
579 if (!$resql) {
580 $error++; $this->error = $this->db->lasterror();
581 }
582 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'availabilities/".$this->db->escape($this->newref)."'";
583 $sql .= " WHERE filepath = 'availabilities/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
584 $resql = $this->db->query($sql);
585 if (!$resql) {
586 $error++; $this->error = $this->db->lasterror();
587 }
588
589 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
590 $oldref = dol_sanitizeFileName($this->ref);
591 $newref = dol_sanitizeFileName($num);
592 $dirsource = $conf->bookcal->dir_output.'/availabilities/'.$oldref;
593 $dirdest = $conf->bookcal->dir_output.'/availabilities/'.$newref;
594 if (!$error && file_exists($dirsource)) {
595 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
596
597 if (@rename($dirsource, $dirdest)) {
598 dol_syslog("Rename ok");
599 // Rename docs starting with $oldref with $newref
600 $listoffiles = dol_dir_list($conf->bookcal->dir_output.'/availabilities/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
601 foreach ($listoffiles as $fileentry) {
602 $dirsource = $fileentry['name'];
603 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
604 $dirsource = $fileentry['path'].'/'.$dirsource;
605 $dirdest = $fileentry['path'].'/'.$dirdest;
606 @rename($dirsource, $dirdest);
607 }
608 }
609 }
610 }
611 }
612
613 // Set new ref and current status
614 if (!$error) {
615 $this->ref = $num;
616 $this->status = self::STATUS_VALIDATED;
617 }
618
619 if (!$error) {
620 $this->db->commit();
621 return 1;
622 } else {
623 $this->db->rollback();
624 return -1;
625 }
626 }
627
628
636 public function setDraft($user, $notrigger = 0)
637 {
638 // Protection
639 if ($this->status <= self::STATUS_DRAFT) {
640 return 0;
641 }
642
643 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->write))
644 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->bookcal_advance->validate))))
645 {
646 $this->error='Permission denied';
647 return -1;
648 }*/
649
650 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'AVAILABILITIES_UNVALIDATE');
651 }
652
660 public function cancel($user, $notrigger = 0)
661 {
662 // Protection
663 if ($this->status != self::STATUS_VALIDATED) {
664 return 0;
665 }
666
667 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->write))
668 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->bookcal_advance->validate))))
669 {
670 $this->error='Permission denied';
671 return -1;
672 }*/
673
674 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'AVAILABILITIES_CANCEL');
675 }
676
684 public function reopen($user, $notrigger = 0)
685 {
686 // Protection
687 if ($this->status != self::STATUS_CANCELED) {
688 return 0;
689 }
690
691 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->write))
692 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->bookcal->bookcal_advance->validate))))
693 {
694 $this->error='Permission denied';
695 return -1;
696 }*/
697
698 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'AVAILABILITIES_REOPEN');
699 }
700
711 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
712 {
713 global $conf, $langs, $hookmanager;
714
715 if (!empty($conf->dol_no_mouse_hover)) {
716 $notooltip = 1; // Force disable tooltips
717 }
718
719 $result = '';
720
721 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Availabilities").'</u>';
722 if (isset($this->status)) {
723 $label .= ' '.$this->getLibStatut(5);
724 }
725 $label .= '<br>';
726 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
727
728 $url = dol_buildpath('/bookcal/availabilities_card.php', 1).'?id='.$this->id;
729
730 if ($option != 'nolink') {
731 // Add param to save lastsearch_values or not
732 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
733 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
734 $add_save_lastsearch_values = 1;
735 }
736 if ($url && $add_save_lastsearch_values) {
737 $url .= '&save_lastsearch_values=1';
738 }
739 }
740
741 $linkclose = '';
742 if (empty($notooltip)) {
743 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
744 $label = $langs->trans("ShowAvailabilities");
745 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
746 }
747 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
748 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
749 } else {
750 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
751 }
752
753 if ($option == 'nolink' || empty($url)) {
754 $linkstart = '<span';
755 } else {
756 $linkstart = '<a href="'.$url.'"';
757 }
758 $linkstart .= $linkclose.'>';
759 if ($option == 'nolink' || empty($url)) {
760 $linkend = '</span>';
761 } else {
762 $linkend = '</a>';
763 }
764
765 $result .= $linkstart;
766
767 if (empty($this->showphoto_on_popup)) {
768 if ($withpicto) {
769 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
770 }
771 } else {
772 if ($withpicto) {
773 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
774
775 list($class, $module) = explode('@', $this->picto);
776 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
777 $filearray = dol_dir_list($upload_dir, "files");
778 $filename = $filearray[0]['name'];
779 if (!empty($filename)) {
780 $pospoint = strpos($filearray[0]['name'], '.');
781
782 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
783 if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
784 $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>';
785 } else {
786 $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>';
787 }
788
789 $result .= '</div>';
790 } else {
791 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
792 }
793 }
794 }
795
796 if ($withpicto != 2) {
797 $result .= $this->ref;
798 }
799
800 $result .= $linkend;
801 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
802
803 global $action, $hookmanager;
804 $hookmanager->initHooks(array('availabilitiesdao'));
805 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
806 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
807 if ($reshook > 0) {
808 $result = $hookmanager->resPrint;
809 } else {
810 $result .= $hookmanager->resPrint;
811 }
812
813 return $result;
814 }
815
822 public function getLabelStatus($mode = 0)
823 {
824 return $this->LibStatut($this->status, $mode);
825 }
826
833 public function getLibStatut($mode = 0)
834 {
835 return $this->LibStatut($this->status, $mode);
836 }
837
838 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
846 public function LibStatut($status, $mode = 0)
847 {
848 // phpcs:enable
849 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
850 global $langs;
851 //$langs->load("agenda");
852 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
853 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
854 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
855 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
856 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
857 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
858 }
859
860 $statusType = 'status'.$status;
861 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
862 if ($status == self::STATUS_CANCELED) {
863 $statusType = 'status6';
864 }
865
866 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
867 }
868
875 public function info($id)
876 {
877 $sql = "SELECT rowid,";
878 $sql .= " date_creation as datec, tms as datem,";
879 $sql .= " fk_user_creat, fk_user_modif";
880 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
881 $sql .= " WHERE t.rowid = ".((int) $id);
882
883 $result = $this->db->query($sql);
884 if ($result) {
885 if ($this->db->num_rows($result)) {
886 $obj = $this->db->fetch_object($result);
887
888 $this->id = $obj->rowid;
889
890 $this->user_creation_id = $obj->fk_user_creat;
891 $this->user_modification_id = $obj->fk_user_modif;
892 if (!empty($obj->fk_user_valid)) {
893 $this->user_validation_id = $obj->fk_user_valid;
894 }
895 $this->date_creation = $this->db->jdate($obj->datec);
896 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
897 if (!empty($obj->datev)) {
898 $this->date_validation = empty($obj->datev) ? '' : $this->db->jdate($obj->datev);
899 }
900 }
901
902 $this->db->free($result);
903 } else {
904 dol_print_error($this->db);
905 }
906 }
907
914 public function initAsSpecimen()
915 {
916 // Set here init that are not commonf fields
917 // $this->property1 = ...
918 // $this->property2 = ...
919
920 $this->initAsSpecimenCommon();
921 }
922
928 public function getLinesArray()
929 {
930 $this->lines = array();
931
932 $objectline = new AvailabilitiesLine($this->db);
933 $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_availabilities = '.((int) $this->id)));
934
935 if (is_numeric($result)) {
936 $this->error = $objectline->error;
937 $this->errors = $objectline->errors;
938 return $result;
939 } else {
940 $this->lines = $result;
941 return $this->lines;
942 }
943 }
944
950 public function getNextNumRef()
951 {
952 global $langs, $conf;
953 $langs->load("agenda");
954
955 if (empty($conf->global->BOOKCAL_AVAILABILITIES_ADDON)) {
956 $conf->global->BOOKCAL_AVAILABILITIES_ADDON = 'mod_availabilities_standard';
957 }
958
959 if (!empty($conf->global->BOOKCAL_AVAILABILITIES_ADDON)) {
960 $mybool = false;
961
962 $file = $conf->global->BOOKCAL_AVAILABILITIES_ADDON.".php";
963 $classname = $conf->global->BOOKCAL_AVAILABILITIES_ADDON;
964
965 // Include file with class
966 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
967 foreach ($dirmodels as $reldir) {
968 $dir = dol_buildpath($reldir."core/modules/bookcal/");
969
970 // Load file with numbering class (if found)
971 $mybool |= @include_once $dir.$file;
972 }
973
974 if ($mybool === false) {
975 dol_print_error('', "Failed to include file ".$file);
976 return '';
977 }
978
979 if (class_exists($classname)) {
980 $obj = new $classname();
981 $numref = $obj->getNextValue($this);
982
983 if ($numref != '' && $numref != '-1') {
984 return $numref;
985 } else {
986 $this->error = $obj->error;
987 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
988 return "";
989 }
990 } else {
991 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
992 return "";
993 }
994 } else {
995 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
996 return "";
997 }
998 }
999
1011 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1012 {
1013 global $conf, $langs;
1014
1015 $result = 0;
1016 $includedocgeneration = 0;
1017
1018 $langs->load("agenda");
1019
1020 if (!dol_strlen($modele)) {
1021 $modele = 'standard_availabilities';
1022
1023 if (!empty($this->model_pdf)) {
1024 $modele = $this->model_pdf;
1025 } elseif (!empty($conf->global->AVAILABILITIES_ADDON_PDF)) {
1026 $modele = $conf->global->AVAILABILITIES_ADDON_PDF;
1027 }
1028 }
1029
1030 $modelpath = "core/modules/bookcal/doc/";
1031
1032 if ($includedocgeneration && !empty($modele)) {
1033 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1034 }
1035
1036 return $result;
1037 }
1038
1046 public function doScheduledJob()
1047 {
1048 global $conf, $langs;
1049
1050 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1051
1052 $error = 0;
1053 $this->output = '';
1054 $this->error = '';
1055
1056 dol_syslog(__METHOD__, LOG_DEBUG);
1057
1058 $now = dol_now();
1059
1060 $this->db->begin();
1061
1062 // ...
1063
1064 $this->db->commit();
1065
1066 return $error;
1067 }
1068}
1069
1070
1071require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1072
1077{
1078 // To complete with content of an object AvailabilitiesLine
1079 // We should have a field rowid, fk_availabilities and position
1080
1084 public $isextrafieldmanaged = 0;
1085
1091 public function __construct(DoliDB $db)
1092 {
1093 $this->db = $db;
1094 }
1095}
$object ref
Definition info.php:78
Class for Availabilities.
getLabelStatus($mode=0)
Return the label of the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
fetch($id, $ref=null)
Load object in memory from the database.
fetchLines()
Load object lines in memory from the 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=false)
Delete a line of object in database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
create(User $user, $notrigger=false)
Create object into database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
update(User $user, $notrigger=false)
Update object into database.
getLibStatut($mode=0)
Return the label of the status.
__construct(DoliDB $db)
Constructor.
LibStatut($status, $mode=0)
Return the status.
createFromClone(User $user, $fromid)
Clone an object into another one.
info($id)
Load the info information in the object.
setDraft($user, $notrigger=0)
Set draft status.
validate($user, $notrigger=0)
Validate object.
getLinesArray()
Create an array of lines.
cancel($user, $notrigger=0)
Set cancel status.
reopen($user, $notrigger=0)
Set back to validated status.
Class AvailabilitiesLine.
__construct(DoliDB $db)
Constructor.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.