dolibarr 19.0.3
timespent.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
4 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
30
35{
39 public $module = 'timespent';
40
44 public $element = 'timespent';
45
49 public $table_element = 'element_time';
50
55 public $ismultientitymanaged = 0;
56
60 public $isextrafieldmanaged = 0;
61
65 public $picto = 'fa-file';
66
67
68 const STATUS_DRAFT = 0;
69 const STATUS_VALIDATED = 1;
70 const STATUS_CANCELED = 9;
71
72
112 // BEGIN MODULEBUILDER PROPERTIES
116 public $fields=array(
117 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
118 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>17, 'notnull'=>0, 'visible'=>-2,),
119 'import_key' => array('type'=>'varchar(14)', 'label'=>'import_key', 'enabled'=>'1', 'position'=>15, 'notnull'=>0, 'visible'=>-1,),
120 'fk_element' => array('type'=>'integer', 'label'=>'fk_element', 'enabled'=>'1', 'position'=>2, 'notnull'=>1, 'visible'=>-1,),
121 'elementtype' => array('type'=>'varchar(32)', 'label'=>'elementtype', 'enabled'=>'1', 'position'=>3, 'notnull'=>1, 'visible'=>-1,),
122 'element_date' => array('type'=>'date', 'label'=>'element_date', 'enabled'=>'1', 'position'=>4, 'notnull'=>0, 'visible'=>-1,),
123 'element_datehour' => array('type'=>'datetime', 'label'=>'element_datehour', 'enabled'=>'1', 'position'=>5, 'notnull'=>0, 'visible'=>-1,),
124 'element_date_withhour' => array('type'=>'integer', 'label'=>'element_date_withhour', 'enabled'=>'1', 'position'=>6, 'notnull'=>0, 'visible'=>-1,),
125 'element_duration' => array('type'=>'double', 'label'=>'element_duration', 'enabled'=>'1', 'position'=>7, 'notnull'=>0, 'visible'=>-1,),
126 'fk_product' => array('type'=>'integer', 'label'=>'fk_product', 'enabled'=>'1', 'position'=>8, 'notnull'=>0, 'visible'=>-1,),
127 'fk_user' => array('type'=>'integer', 'label'=>'fk_user', 'enabled'=>'1', 'position'=>9, 'notnull'=>0, 'visible'=>-1,),
128 'thm' => array('type'=>'double(24,8)', 'label'=>'thm', 'enabled'=>'1', 'position'=>10, 'notnull'=>0, 'visible'=>-1,),
129 'invoice_id' => array('type'=>'integer', 'label'=>'invoice_id', 'enabled'=>'1', 'position'=>11, 'notnull'=>0, 'visible'=>-1, 'default'=>'NULL',),
130 'invoice_line_id' => array('type'=>'integer', 'label'=>'invoice_line_id', 'enabled'=>'1', 'position'=>12, 'notnull'=>0, 'visible'=>-1, 'default'=>'NULL',),
131 'intervention_id' => array('type'=>'integer', 'label'=>'intervention_id', 'enabled'=>'1', 'position'=>13, 'notnull'=>0, 'visible'=>-1, 'default'=>'NULL',),
132 'intervention_line_id' => array('type'=>'integer', 'label'=>'intervention_line_id', 'enabled'=>'1', 'position'=>14, 'notnull'=>0, 'visible'=>-1, 'default'=>'NULL',),
133 'datec' => array('type'=>'datetime', 'label'=>'datec', 'enabled'=>'1', 'position'=>16, 'notnull'=>0, 'visible'=>-1,),
134 'note' => array('type'=>'text', 'label'=>'note', 'enabled'=>'1', 'position'=>18, 'notnull'=>0, 'visible'=>-1,),
135 );
136 public $rowid;
137 public $tms;
138 public $import_key;
139 public $fk_element;
140 public $elementtype;
141 public $element_date;
142 public $element_datehour;
143 public $element_date_withhour;
144 public $element_duration;
145 public $fk_product;
146 public $fk_user;
147 public $thm;
148 public $invoice_id;
149 public $invoice_line_id;
150 public $intervention_id;
151 public $intervention_line_id;
152 public $datec;
153 public $note;
154 // END MODULEBUILDER PROPERTIES
155
161 public function __construct(DoliDB $db)
162 {
163 global $conf, $langs;
164
165 $this->db = $db;
166
167 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
168 $this->fields['rowid']['visible'] = 0;
169 }
170 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
171 $this->fields['entity']['enabled'] = 0;
172 }
173
174 // Example to show how to set values of fields definition dynamically
175 /*if ($user->rights->timespent->timespent->read) {
176 $this->fields['myfield']['visible'] = 1;
177 $this->fields['myfield']['noteditable'] = 0;
178 }*/
179
180 // Unset fields that are disabled
181 foreach ($this->fields as $key => $val) {
182 if (isset($val['enabled']) && empty($val['enabled'])) {
183 unset($this->fields[$key]);
184 }
185 }
186
187 // Translate some data of arrayofkeyval
188 if (is_object($langs)) {
189 foreach ($this->fields as $key => $val) {
190 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
191 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
192 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
193 }
194 }
195 }
196 }
197 }
198
206 public function create(User $user, $notrigger = false)
207 {
208 $resultcreate = $this->createCommon($user, $notrigger);
209
210 //$resultvalidate = $this->validate($user, $notrigger);
211
212 return $resultcreate;
213 }
214
222 public function createFromClone(User $user, $fromid)
223 {
224 global $langs, $extrafields;
225 $error = 0;
226
227 dol_syslog(__METHOD__, LOG_DEBUG);
228
229 $object = new self($this->db);
230
231 $this->db->begin();
232
233 // Load source object
234 $result = $object->fetchCommon($fromid);
235
236 // Reset some properties
237 unset($object->id);
238 unset($object->fk_user_creat);
239 unset($object->import_key);
240
241 // Clear fields
242 if (property_exists($object, 'ref')) {
243 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
244 }
245 if (property_exists($object, 'label')) {
246 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
247 }
248 if (property_exists($object, 'status')) {
249 $object->status = self::STATUS_DRAFT;
250 }
251 if (property_exists($object, 'date_creation')) {
252 $object->date_creation = dol_now();
253 }
254 if (property_exists($object, 'date_modification')) {
255 $object->date_modification = null;
256 }
257 // ...
258 // Clear extrafields that are unique
259 if (is_array($object->array_options) && count($object->array_options) > 0) {
260 $extrafields->fetch_name_optionals_label($this->table_element);
261 foreach ($object->array_options as $key => $option) {
262 $shortkey = preg_replace('/options_/', '', $key);
263 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
264 //var_dump($key);
265 //var_dump($clonedObj->array_options[$key]); exit;
266 unset($object->array_options[$key]);
267 }
268 }
269 }
270
271 // Create clone
272 $object->context['createfromclone'] = 'createfromclone';
273 $result = $object->createCommon($user);
274 if ($result < 0) {
275 $error++;
276 $this->error = $object->error;
277 $this->errors = $object->errors;
278 }
279
280 if (!$error) {
281 // copy internal contacts
282 if ($this->copy_linked_contact($object, 'internal') < 0) {
283 $error++;
284 }
285 }
286
287 if (!$error) {
288 // copy external contacts if same company
289 if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
290 if ($this->copy_linked_contact($object, 'external') < 0) {
291 $error++;
292 }
293 }
294 }
295
296 unset($object->context['createfromclone']);
297
298 // End
299 if (!$error) {
300 $this->db->commit();
301 return $object;
302 } else {
303 $this->db->rollback();
304 return -1;
305 }
306 }
307
315 public function fetch($id, $ref = null)
316 {
317 $result = $this->fetchCommon($id, $ref);
318
319 return $result;
320 }
321
333 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
334 {
335 global $conf;
336
337 dol_syslog(__METHOD__, LOG_DEBUG);
338
339 $records = array();
340
341 $sql = "SELECT ";
342 $sql .= $this->getFieldList('t');
343 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
344 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
345 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
346 } else {
347 $sql .= " WHERE 1 = 1";
348 }
349 // Manage filter
350 $sqlwhere = array();
351 if (count($filter) > 0) {
352 foreach ($filter as $key => $value) {
353 if ($key == 't.rowid') {
354 $sqlwhere[] = $key." = ".((int) $value);
355 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
356 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
357 } elseif ($key == 'customsql') {
358 $sqlwhere[] = $value;
359 } elseif (strpos($value, '%') === false) {
360 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
361 } else {
362 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
363 }
364 }
365 }
366 if (count($sqlwhere) > 0) {
367 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
368 }
369
370 if (!empty($sortfield)) {
371 $sql .= $this->db->order($sortfield, $sortorder);
372 }
373 if (!empty($limit)) {
374 $sql .= $this->db->plimit($limit, $offset);
375 }
376
377 $resql = $this->db->query($sql);
378 if ($resql) {
379 $num = $this->db->num_rows($resql);
380 $i = 0;
381 while ($i < ($limit ? min($limit, $num) : $num)) {
382 $obj = $this->db->fetch_object($resql);
383
384 $record = new self($this->db);
385 $record->setVarsFromFetchObj($obj);
386
387 $records[$record->id] = $record;
388
389 $i++;
390 }
391 $this->db->free($resql);
392
393 return $records;
394 } else {
395 $this->errors[] = 'Error '.$this->db->lasterror();
396 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
397
398 return -1;
399 }
400 }
401
409 public function update(User $user, $notrigger = false)
410 {
411 return $this->updateCommon($user, $notrigger);
412 }
413
421 public function delete(User $user, $notrigger = false)
422 {
423 return $this->deleteCommon($user, $notrigger);
424 //return $this->deleteCommon($user, $notrigger, 1);
425 }
426
435 public function deleteLine(User $user, $idline, $notrigger = false)
436 {
437 if ($this->status < 0) {
438 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
439 return -2;
440 }
441
442 return $this->deleteLineCommon($user, $idline, $notrigger);
443 }
444
445
453 public function validate($user, $notrigger = 0)
454 {
455 global $conf, $langs;
456
457 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
458
459 $error = 0;
460
461 // Protection
462 if ($this->status == self::STATUS_VALIDATED) {
463 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
464 return 0;
465 }
466
467 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->write))
468 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->timespent_advance->validate))))
469 {
470 $this->error='NotEnoughPermissions';
471 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
472 return -1;
473 }*/
474
475 $now = dol_now();
476
477 $this->db->begin();
478
479 // Define new ref
480 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
481 $num = $this->getNextNumRef();
482 } else {
483 $num = $this->ref;
484 }
485 $this->newref = $num;
486
487 if (!empty($num)) {
488 // Validate
489 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
490 $sql .= " SET ref = '".$this->db->escape($num)."',";
491 $sql .= " status = ".self::STATUS_VALIDATED;
492 if (!empty($this->fields['date_validation'])) {
493 $sql .= ", date_validation = '".$this->db->idate($now)."'";
494 }
495 if (!empty($this->fields['fk_user_valid'])) {
496 $sql .= ", fk_user_valid = ".((int) $user->id);
497 }
498 $sql .= " WHERE rowid = ".((int) $this->id);
499
500 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
501 $resql = $this->db->query($sql);
502 if (!$resql) {
503 dol_print_error($this->db);
504 $this->error = $this->db->lasterror();
505 $error++;
506 }
507
508 if (!$error && !$notrigger) {
509 // Call trigger
510 $result = $this->call_trigger('timespent_VALIDATE', $user);
511 if ($result < 0) {
512 $error++;
513 }
514 // End call triggers
515 }
516 }
517
518 if (!$error) {
519 $this->oldref = $this->ref;
520
521 // Rename directory if dir was a temporary ref
522 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
523 // Now we rename also files into index
524 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'timespent/".$this->db->escape($this->newref)."'";
525 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'timespent/".$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 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'timespent/".$this->db->escape($this->newref)."'";
532 $sql .= " WHERE filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
533 $resql = $this->db->query($sql);
534 if (!$resql) {
535 $error++;
536 $this->error = $this->db->lasterror();
537 }
538
539 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
540 $oldref = dol_sanitizeFileName($this->ref);
541 $newref = dol_sanitizeFileName($num);
542 $dirsource = $conf->timespent->dir_output.'/timespent/'.$oldref;
543 $dirdest = $conf->timespent->dir_output.'/timespent/'.$newref;
544 if (!$error && file_exists($dirsource)) {
545 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
546
547 if (@rename($dirsource, $dirdest)) {
548 dol_syslog("Rename ok");
549 // Rename docs starting with $oldref with $newref
550 $listoffiles = dol_dir_list($conf->timespent->dir_output.'/timespent/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
551 foreach ($listoffiles as $fileentry) {
552 $dirsource = $fileentry['name'];
553 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
554 $dirsource = $fileentry['path'].'/'.$dirsource;
555 $dirdest = $fileentry['path'].'/'.$dirdest;
556 @rename($dirsource, $dirdest);
557 }
558 }
559 }
560 }
561 }
562
563 // Set new ref and current status
564 if (!$error) {
565 $this->ref = $num;
566 $this->status = self::STATUS_VALIDATED;
567 }
568
569 if (!$error) {
570 $this->db->commit();
571 return 1;
572 } else {
573 $this->db->rollback();
574 return -1;
575 }
576 }
577
578
586 public function setDraft($user, $notrigger = 0)
587 {
588 // Protection
589 if ($this->status <= self::STATUS_DRAFT) {
590 return 0;
591 }
592
593 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
594 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
595 {
596 $this->error='Permission denied';
597 return -1;
598 }*/
599
600 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'timespent_UNVALIDATE');
601 }
602
610 public function cancel($user, $notrigger = 0)
611 {
612 // Protection
613 if ($this->status != self::STATUS_VALIDATED) {
614 return 0;
615 }
616
617 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
618 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
619 {
620 $this->error='Permission denied';
621 return -1;
622 }*/
623
624 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'timespent_CANCEL');
625 }
626
634 public function reopen($user, $notrigger = 0)
635 {
636 // Protection
637 if ($this->status == self::STATUS_VALIDATED) {
638 return 0;
639 }
640
641 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
642 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
643 {
644 $this->error='Permission denied';
645 return -1;
646 }*/
647
648 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'timespent_REOPEN');
649 }
650
657 public function getTooltipContentArray($params)
658 {
659 global $conf, $langs, $user;
660
661 $datas = [];
662
663 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
664 return ['optimize' => $langs->trans("ShowTimeSpent")];
665 }
666 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("TimeSpent").'</u>';
667 if (isset($this->status)) {
668 $datas['picto'] .= ' '.$this->getLibStatut(5);
669 }
670 $datas['ref'] .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
671
672 return $datas;
673 }
674
685 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
686 {
687 global $conf, $langs, $hookmanager;
688
689 if (!empty($conf->dol_no_mouse_hover)) {
690 $notooltip = 1; // Force disable tooltips
691 }
692
693 $result = '';
694 $params = [
695 'id' => $this->id,
696 'objecttype' => $this->element,
697 'option' => $option,
698 ];
699 $classfortooltip = 'classfortooltip';
700 $dataparams = '';
701 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
702 $classfortooltip = 'classforajaxtooltip';
703 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
704 $label = '';
705 } else {
706 $label = implode($this->getTooltipContentArray($params));
707 }
708
709 $url = dol_buildpath('/timespent/timespent_card.php', 1).'?id='.$this->id;
710
711 if ($option != 'nolink') {
712 // Add param to save lastsearch_values or not
713 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
714 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
715 $add_save_lastsearch_values = 1;
716 }
717 if ($url && $add_save_lastsearch_values) {
718 $url .= '&save_lastsearch_values=1';
719 }
720 }
721
722 $linkclose = '';
723 if (empty($notooltip)) {
724 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
725 $label = $langs->trans("ShowTimeSpent");
726 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
727 }
728 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
729 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
730 } else {
731 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
732 }
733
734 if ($option == 'nolink' || empty($url)) {
735 $linkstart = '<span';
736 } else {
737 $linkstart = '<a href="'.$url.'"';
738 }
739 $linkstart .= $linkclose.'>';
740 if ($option == 'nolink' || empty($url)) {
741 $linkend = '</span>';
742 } else {
743 $linkend = '</a>';
744 }
745
746 $result .= $linkstart;
747
748 if (empty($this->showphoto_on_popup)) {
749 if ($withpicto) {
750 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
751 }
752 } else {
753 if ($withpicto) {
754 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
755
756 list($class, $module) = explode('@', $this->picto);
757 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
758 $filearray = dol_dir_list($upload_dir, "files");
759 $filename = $filearray[0]['name'];
760 if (!empty($filename)) {
761 $pospoint = strpos($filearray[0]['name'], '.');
762
763 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
764 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
765 $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>';
766 } else {
767 $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>';
768 }
769
770 $result .= '</div>';
771 } else {
772 $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);
773 }
774 }
775 }
776
777 if ($withpicto != 2) {
778 $result .= $this->ref;
779 }
780
781 $result .= $linkend;
782 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
783
784 global $action, $hookmanager;
785 $hookmanager->initHooks(array($this->element.'dao'));
786 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
787 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
788 if ($reshook > 0) {
789 $result = $hookmanager->resPrint;
790 } else {
791 $result .= $hookmanager->resPrint;
792 }
793
794 return $result;
795 }
796
804 public function getKanbanView($option = '', $arraydata = null)
805 {
806 global $conf, $langs;
807
808 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
809
810 $return = '<div class="box-flex-item box-flex-grow-zero">';
811 $return .= '<div class="info-box info-box-sm">';
812 $return .= '<span class="info-box-icon bg-infobox-action">';
813 $return .= img_picto('', $this->picto);
814 $return .= '</span>';
815 $return .= '<div class="info-box-content">';
816 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
817 if ($selected >= 0) {
818 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
819 }
820 if (property_exists($this, 'label')) {
821 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
822 }
823 if (property_exists($this, 'amount')) {
824 $return .= '<br>';
825 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
826 }
827 if (method_exists($this, 'getLibStatut')) {
828 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(5).'</div>';
829 }
830 $return .= '</div>';
831 $return .= '</div>';
832 $return .= '</div>';
833
834 return $return;
835 }
836
843 public function getLabelStatus($mode = 0)
844 {
845 return $this->LibStatut($this->status, $mode);
846 }
847
854 public function getLibStatut($mode = 0)
855 {
856 return $this->LibStatut($this->status, $mode);
857 }
858
859 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
867 public function LibStatut($status, $mode = 0)
868 {
869 // phpcs:enable
870 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
871 global $langs;
872 //$langs->load("timespent@timespent");
873 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
874 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
875 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
876 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
877 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
878 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
879 }
880
881 $statusType = 'status'.$status;
882 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
883 if ($status == self::STATUS_CANCELED) {
884 $statusType = 'status6';
885 }
886
887 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
888 }
889
896 public function info($id)
897 {
898 $sql = "SELECT rowid,";
899 $sql .= " date_creation as datec, tms as datem,";
900 $sql .= " fk_user_creat, fk_user_modif";
901 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
902 $sql .= " WHERE t.rowid = ".((int) $id);
903
904 $result = $this->db->query($sql);
905 if ($result) {
906 if ($this->db->num_rows($result)) {
907 $obj = $this->db->fetch_object($result);
908
909 $this->id = $obj->rowid;
910
911 $this->user_creation_id = $obj->fk_user_creat;
912 $this->user_modification_id = $obj->fk_user_modif;
913 $this->date_creation = $this->db->jdate($obj->datec);
914 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
915 }
916
917 $this->db->free($result);
918 } else {
919 dol_print_error($this->db);
920 }
921 }
922
929 public function initAsSpecimen()
930 {
931 // Set here init that are not commonf fields
932 // $this->property1 = ...
933 // $this->property2 = ...
934
935 $this->initAsSpecimenCommon();
936 }
937
943 public function getNextNumRef()
944 {
945 global $langs, $conf;
946 $langs->load("timespent@timespent");
947
948 if (!getDolGlobalString('TIMESPENT_timespent_ADDON')) {
949 $conf->global->TIMESPENT_timespent_ADDON = 'mod_timespent_standard';
950 }
951
952 if (getDolGlobalString('TIMESPENT_timespent_ADDON')) {
953 $mybool = false;
954
955 $file = getDolGlobalString('TIMESPENT_timespent_ADDON') . ".php";
956 $classname = $conf->global->TIMESPENT_timespent_ADDON;
957
958 // Include file with class
959 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
960 foreach ($dirmodels as $reldir) {
961 $dir = dol_buildpath($reldir."core/modules/timespent/");
962
963 // Load file with numbering class (if found)
964 $mybool |= @include_once $dir.$file;
965 }
966
967 if ($mybool === false) {
968 dol_print_error('', "Failed to include file ".$file);
969 return '';
970 }
971
972 if (class_exists($classname)) {
973 $obj = new $classname();
974 $numref = $obj->getNextValue($this);
975
976 if ($numref != '' && $numref != '-1') {
977 return $numref;
978 } else {
979 $this->error = $obj->error;
980 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
981 return "";
982 }
983 } else {
984 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
985 return "";
986 }
987 } else {
988 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
989 return "";
990 }
991 }
992
1004 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1005 {
1006 global $conf, $langs;
1007
1008 $result = 0;
1009 $includedocgeneration = 0;
1010
1011 $langs->load("timespent@timespent");
1012
1013 if (!dol_strlen($modele)) {
1014 $modele = 'standard_timespent';
1015
1016 if (!empty($this->model_pdf)) {
1017 $modele = $this->model_pdf;
1018 } elseif (getDolGlobalString('timespent_ADDON_PDF')) {
1019 $modele = $conf->global->timespent_ADDON_PDF;
1020 }
1021 }
1022
1023 $modelpath = "core/modules/timespent/doc/";
1024
1025 if ($includedocgeneration && !empty($modele)) {
1026 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1027 }
1028
1029 return $result;
1030 }
1031}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in 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.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for TimeSpent.
validate($user, $notrigger=0)
Validate object.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
fetch($id, $ref=null)
Load object in memory from the database.
setDraft($user, $notrigger=0)
Set draft status.
getTooltipContentArray($params)
getTooltipContentArray
cancel($user, $notrigger=0)
Set cancel status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
getLabelStatus($mode=0)
Return the label of the status.
__construct(DoliDB $db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
reopen($user, $notrigger=0)
Set back to validated status.
createFromClone(User $user, $fromid)
Clone an object into another one.
info($id)
Load the info information in the object.
LibStatut($status, $mode=0)
Return the status.
update(User $user, $notrigger=false)
Update object into database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
create(User $user, $notrigger=false)
Create object into database.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
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.