dolibarr  16.0.5
task.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
5  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
6  * Copyright (C) 2020 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
32 
33 
37 class Task extends CommonObjectLine
38 {
42  public $element = 'project_task';
43 
47  public $table_element = 'projet_task';
48 
52  public $fk_element = 'fk_task';
53 
57  public $picto = 'projecttask';
58 
62  protected $childtables = array(
63  'projet_task_time' => array('name' => 'Task', 'parent' => 'projet_task', 'parentkey' => 'fk_task')
64  );
65 
69  public $fk_task_parent = 0;
70 
74  public $label;
75 
79  public $description;
80 
81  public $duration_effective; // total of time spent on this task
82  public $planned_workload;
83  public $date_c;
84  public $date_start;
85  public $date_end;
86  public $progress;
87 
91  public $datee;
92 
96  public $fk_statut;
97 
98  public $priority;
99 
103  public $fk_user_creat;
104 
108  public $fk_user_valid;
109 
110  public $rang;
111 
112  public $timespent_min_date;
113  public $timespent_max_date;
114  public $timespent_total_duration;
115  public $timespent_total_amount;
116  public $timespent_nblinesnull;
117  public $timespent_nblines;
118  // For detail of lines of timespent record, there is the property ->lines in common
119 
120  // Var used to call method addTimeSpent(). Bad practice.
121  public $timespent_id;
122  public $timespent_duration;
123  public $timespent_old_duration;
124  public $timespent_date;
125  public $timespent_datehour; // More accurate start date (same than timespent_date but includes hours, minutes and seconds)
126  public $timespent_withhour; // 1 = we entered also start hours for timesheet line
127  public $timespent_fk_user;
128  public $timespent_thm;
129  public $timespent_note;
130 
131  public $comments = array();
132 
136  public $budget_amount;
137 
141  public $project_budget_amount;
142 
143  public $oldcopy;
144 
145 
151  public function __construct($db)
152  {
153  $this->db = $db;
154  }
155 
156 
164  public function create($user, $notrigger = 0)
165  {
166  global $conf, $langs;
167 
168  //For the date
169  $now = dol_now();
170 
171  $error = 0;
172 
173  // Clean parameters
174  $this->label = trim($this->label);
175  $this->description = trim($this->description);
176 
177  if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
178  $this->errors[] = $langs->trans('StartDateCannotBeAfterEndDate');
179  return -1;
180  }
181 
182  // Check parameters
183  // Put here code to add control on parameters values
184 
185  // Insert request
186  $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (";
187  $sql .= "entity";
188  $sql .= ", fk_projet";
189  $sql .= ", ref";
190  $sql .= ", fk_task_parent";
191  $sql .= ", label";
192  $sql .= ", description";
193  $sql .= ", datec";
194  $sql .= ", fk_user_creat";
195  $sql .= ", dateo";
196  $sql .= ", datee";
197  $sql .= ", planned_workload";
198  $sql .= ", progress";
199  $sql .= ", budget_amount";
200  $sql .= ") VALUES (";
201  $sql .= (!empty($this->entity) ? (int) $this->entity : (int) $conf->entity);
202  $sql .= ", ".((int) $this->fk_project);
203  $sql .= ", ".(!empty($this->ref) ? "'".$this->db->escape($this->ref)."'" : 'null');
204  $sql .= ", ".((int) $this->fk_task_parent);
205  $sql .= ", '".$this->db->escape($this->label)."'";
206  $sql .= ", '".$this->db->escape($this->description)."'";
207  $sql .= ", '".$this->db->idate($now)."'";
208  $sql .= ", ".((int) $user->id);
209  $sql .= ", ".($this->date_start ? "'".$this->db->idate($this->date_start)."'" : 'null');
210  $sql .= ", ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : 'null');
211  $sql .= ", ".(($this->planned_workload != '' && $this->planned_workload >= 0) ? ((int) $this->planned_workload) : 'null');
212  $sql .= ", ".(($this->progress != '' && $this->progress >= 0) ? ((int) $this->progress) : 'null');
213  $sql .= ", ".(($this->budget_amount != '' && $this->budget_amount >= 0) ? ((int) $this->budget_amount) : 'null');
214  $sql .= ")";
215 
216  $this->db->begin();
217 
218  dol_syslog(get_class($this)."::create", LOG_DEBUG);
219  $resql = $this->db->query($sql);
220  if (!$resql) {
221  $error++; $this->errors[] = "Error ".$this->db->lasterror();
222  }
223 
224  if (!$error) {
225  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
226 
227  if (!$notrigger) {
228  // Call trigger
229  $result = $this->call_trigger('TASK_CREATE', $user);
230  if ($result < 0) {
231  $error++;
232  }
233  // End call triggers
234  }
235  }
236 
237  // Update extrafield
238  if (!$error) {
239  if (!$error) {
240  $result = $this->insertExtraFields();
241  if ($result < 0) {
242  $error++;
243  }
244  }
245  }
246 
247  // Commit or rollback
248  if ($error) {
249  foreach ($this->errors as $errmsg) {
250  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
251  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
252  }
253  $this->db->rollback();
254  return -1 * $error;
255  } else {
256  $this->db->commit();
257  return $this->id;
258  }
259  }
260 
261 
270  public function fetch($id, $ref = '', $loadparentdata = 0)
271  {
272  global $langs, $conf;
273 
274  $sql = "SELECT";
275  $sql .= " t.rowid,";
276  $sql .= " t.ref,";
277  $sql .= " t.entity,";
278  $sql .= " t.fk_projet as fk_project,";
279  $sql .= " t.fk_task_parent,";
280  $sql .= " t.label,";
281  $sql .= " t.description,";
282  $sql .= " t.duration_effective,";
283  $sql .= " t.planned_workload,";
284  $sql .= " t.datec,";
285  $sql .= " t.dateo,";
286  $sql .= " t.datee,";
287  $sql .= " t.fk_user_creat,";
288  $sql .= " t.fk_user_valid,";
289  $sql .= " t.fk_statut,";
290  $sql .= " t.progress,";
291  $sql .= " t.budget_amount,";
292  $sql .= " t.priority,";
293  $sql .= " t.note_private,";
294  $sql .= " t.note_public,";
295  $sql .= " t.rang";
296  if (!empty($loadparentdata)) {
297  $sql .= ", t2.ref as task_parent_ref";
298  $sql .= ", t2.rang as task_parent_position";
299  }
300  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as t";
301  if (!empty($loadparentdata)) {
302  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t2 ON t.fk_task_parent = t2.rowid";
303  }
304  $sql .= " WHERE ";
305  if (!empty($ref)) {
306  $sql .= "entity IN (".getEntity('project').")";
307  $sql .= " AND t.ref = '".$this->db->escape($ref)."'";
308  } else {
309  $sql .= "t.rowid = ".((int) $id);
310  }
311 
312  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
313  $resql = $this->db->query($sql);
314  if ($resql) {
315  $num_rows = $this->db->num_rows($resql);
316 
317  if ($num_rows) {
318  $obj = $this->db->fetch_object($resql);
319 
320  $this->id = $obj->rowid;
321  $this->ref = $obj->ref;
322  $this->entity = $obj->entity;
323  $this->fk_project = $obj->fk_project;
324  $this->fk_task_parent = $obj->fk_task_parent;
325  $this->label = $obj->label;
326  $this->description = $obj->description;
327  $this->duration_effective = $obj->duration_effective;
328  $this->planned_workload = $obj->planned_workload;
329  $this->date_c = $this->db->jdate($obj->datec);
330  $this->date_start = $this->db->jdate($obj->dateo);
331  $this->date_end = $this->db->jdate($obj->datee);
332  $this->fk_user_creat = $obj->fk_user_creat;
333  $this->fk_user_valid = $obj->fk_user_valid;
334  $this->fk_statut = $obj->fk_statut;
335  $this->progress = $obj->progress;
336  $this->budget_amount = $obj->budget_amount;
337  $this->priority = $obj->priority;
338  $this->note_private = $obj->note_private;
339  $this->note_public = $obj->note_public;
340  $this->rang = $obj->rang;
341 
342  if (!empty($loadparentdata)) {
343  $this->task_parent_ref = $obj->task_parent_ref;
344  $this->task_parent_position = $obj->task_parent_position;
345  }
346 
347  // Retrieve all extrafield
348  $this->fetch_optionals();
349  }
350 
351  $this->db->free($resql);
352 
353  if ($num_rows) {
354  return 1;
355  } else {
356  return 0;
357  }
358  } else {
359  $this->error = "Error ".$this->db->lasterror();
360  return -1;
361  }
362  }
363 
364 
372  public function update($user = null, $notrigger = 0)
373  {
374  global $conf, $langs;
375  $error = 0;
376 
377  // Clean parameters
378  if (isset($this->fk_project)) {
379  $this->fk_project = trim($this->fk_project);
380  }
381  if (isset($this->ref)) {
382  $this->ref = trim($this->ref);
383  }
384  if (isset($this->fk_task_parent)) {
385  $this->fk_task_parent = (int) $this->fk_task_parent;
386  }
387  if (isset($this->label)) {
388  $this->label = trim($this->label);
389  }
390  if (isset($this->description)) {
391  $this->description = trim($this->description);
392  }
393  if (isset($this->duration_effective)) {
394  $this->duration_effective = trim($this->duration_effective);
395  }
396  if (isset($this->planned_workload)) {
397  $this->planned_workload = trim($this->planned_workload);
398  }
399  if (isset($this->budget_amount)) {
400  $this->budget_amount = trim($this->budget_amount);
401  }
402 
403  if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
404  $this->errors[] = $langs->trans('StartDateCannotBeAfterEndDate');
405  return -1;
406  }
407 
408  // Check parameters
409  // Put here code to add control on parameters values
410 
411  // Update request
412  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
413  $sql .= " fk_projet=".(isset($this->fk_project) ? $this->fk_project : "null").",";
414  $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "'".$this->db->escape($this->id)."'").",";
415  $sql .= " fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent : "null").",";
416  $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
417  $sql .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").",";
418  $sql .= " duration_effective=".(isset($this->duration_effective) ? $this->duration_effective : "null").",";
419  $sql .= " planned_workload=".((isset($this->planned_workload) && $this->planned_workload != '') ? $this->planned_workload : "null").",";
420  $sql .= " dateo=".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : 'null').",";
421  $sql .= " datee=".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : 'null').",";
422  $sql .= " progress=".(($this->progress != '' && $this->progress >= 0) ? $this->progress : 'null').",";
423  $sql .= " budget_amount=".(($this->budget_amount != '' && $this->budget_amount >= 0) ? $this->budget_amount : 'null').",";
424  $sql .= " rang=".((!empty($this->rang)) ? $this->rang : "0");
425  $sql .= " WHERE rowid=".((int) $this->id);
426 
427  $this->db->begin();
428 
429  dol_syslog(get_class($this)."::update", LOG_DEBUG);
430  $resql = $this->db->query($sql);
431  if (!$resql) {
432  $error++; $this->errors[] = "Error ".$this->db->lasterror();
433  }
434 
435  // Update extrafield
436  if (!$error) {
437  $result = $this->insertExtraFields();
438  if ($result < 0) {
439  $error++;
440  }
441  }
442 
443  if (!$error && !empty($conf->global->PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE)) {
444  // Close the parent project if it is open (validated) and its tasks are 100% completed
445  $project = new Project($this->db);
446  if ($project->fetch($this->fk_project) > 0) {
447  if ($project->statut == Project::STATUS_VALIDATED) {
448  $project->getLinesArray(null); // this method does not return <= 0 if fails
449  $projectCompleted = array_reduce(
450  $project->lines,
451  function ($allTasksCompleted, $task) {
452  return $allTasksCompleted && $task->progress >= 100;
453  },
454  1
455  );
456  if ($projectCompleted) {
457  if ($project->setClose($user) <= 0) {
458  $error++;
459  }
460  }
461  }
462  } else {
463  $error++;
464  }
465  if ($error) {
466  $this->errors[] = $project->error;
467  }
468  }
469 
470  if (!$error) {
471  if (!$notrigger) {
472  // Call trigger
473  $result = $this->call_trigger('TASK_MODIFY', $user);
474  if ($result < 0) {
475  $error++;
476  }
477  // End call triggers
478  }
479  }
480 
481  if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
482  // We remove directory
483  if ($conf->project->dir_output) {
484  $project = new Project($this->db);
485  $project->fetch($this->fk_project);
486 
487  $olddir = $conf->project->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($this->oldcopy->ref);
488  $newdir = $conf->project->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($this->ref);
489  if (file_exists($olddir)) {
490  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
491  $res = dol_move_dir($olddir, $newdir);
492  if (!$res) {
493  $langs->load("errors");
494  $this->error = $langs->trans('ErrorFailToRenameDir', $olddir, $newdir);
495  $error++;
496  }
497  }
498  }
499  }
500 
501  // Commit or rollback
502  if ($error) {
503  foreach ($this->errors as $errmsg) {
504  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
505  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
506  }
507  $this->db->rollback();
508  return -1 * $error;
509  } else {
510  $this->db->commit();
511  return 1;
512  }
513  }
514 
515 
523  public function delete($user, $notrigger = 0)
524  {
525 
526  global $conf, $langs;
527  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
528 
529  $error = 0;
530 
531  $this->db->begin();
532 
533  if ($this->hasChildren() > 0) {
534  dol_syslog(get_class($this)."::delete Can't delete record as it has some sub tasks", LOG_WARNING);
535  $this->error = 'ErrorRecordHasSubTasks';
536  $this->db->rollback();
537  return 0;
538  }
539 
540  $objectisused = $this->isObjectUsed($this->id);
541  if (!empty($objectisused)) {
542  dol_syslog(get_class($this)."::delete Can't delete record as it has some child", LOG_WARNING);
543  $this->error = 'ErrorRecordHasChildren';
544  $this->db->rollback();
545  return 0;
546  }
547 
548  if (!$error) {
549  // Delete linked contacts
550  $res = $this->delete_linked_contact();
551  if ($res < 0) {
552  $this->error = 'ErrorFailToDeleteLinkedContact';
553  //$error++;
554  $this->db->rollback();
555  return 0;
556  }
557  }
558 
559  if (!$error) {
560  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time";
561  $sql .= " WHERE fk_task = ".((int) $this->id);
562 
563  $resql = $this->db->query($sql);
564  if (!$resql) {
565  $error++; $this->errors[] = "Error ".$this->db->lasterror();
566  }
567  }
568 
569  if (!$error) {
570  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_extrafields";
571  $sql .= " WHERE fk_object = ".((int) $this->id);
572 
573  $resql = $this->db->query($sql);
574  if (!$resql) {
575  $error++; $this->errors[] = "Error ".$this->db->lasterror();
576  }
577  }
578 
579  if (!$error) {
580  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task";
581  $sql .= " WHERE rowid=".((int) $this->id);
582 
583  $resql = $this->db->query($sql);
584  if (!$resql) {
585  $error++; $this->errors[] = "Error ".$this->db->lasterror();
586  }
587  }
588 
589  if (!$error) {
590  if (!$notrigger) {
591  // Call trigger
592  $result = $this->call_trigger('TASK_DELETE', $user);
593  if ($result < 0) {
594  $error++;
595  }
596  // End call triggers
597  }
598  }
599 
600  // Commit or rollback
601  if ($error) {
602  foreach ($this->errors as $errmsg) {
603  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
604  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
605  }
606  $this->db->rollback();
607  return -1 * $error;
608  } else {
609  //Delete associated link file
610  if ($conf->project->dir_output) {
611  $projectstatic = new Project($this->db);
612  $projectstatic->fetch($this->fk_project);
613 
614  $dir = $conf->project->dir_output."/".dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($this->id);
615  dol_syslog(get_class($this)."::delete dir=".$dir, LOG_DEBUG);
616  if (file_exists($dir)) {
617  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
618  $res = @dol_delete_dir_recursive($dir);
619  if (!$res) {
620  $this->error = 'ErrorFailToDeleteDir';
621  $this->db->rollback();
622  return 0;
623  }
624  }
625  }
626 
627  $this->db->commit();
628 
629  return 1;
630  }
631  }
632 
638  public function hasChildren()
639  {
640  $error = 0;
641  $ret = 0;
642 
643  $sql = "SELECT COUNT(*) as nb";
644  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task";
645  $sql .= " WHERE fk_task_parent = ".((int) $this->id);
646 
647  dol_syslog(get_class($this)."::hasChildren", LOG_DEBUG);
648  $resql = $this->db->query($sql);
649  if (!$resql) {
650  $error++; $this->errors[] = "Error ".$this->db->lasterror();
651  } else {
652  $obj = $this->db->fetch_object($resql);
653  if ($obj) {
654  $ret = $obj->nb;
655  }
656  $this->db->free($resql);
657  }
658 
659  if (!$error) {
660  return $ret;
661  } else {
662  return -1;
663  }
664  }
665 
671  public function hasTimeSpent()
672  {
673  $error = 0;
674  $ret = 0;
675 
676  $sql = "SELECT COUNT(*) as nb";
677  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time";
678  $sql .= " WHERE fk_task = ".((int) $this->id);
679 
680  dol_syslog(get_class($this)."::hasTimeSpent", LOG_DEBUG);
681  $resql = $this->db->query($sql);
682  if (!$resql) {
683  $error++; $this->errors[] = "Error ".$this->db->lasterror();
684  } else {
685  $obj = $this->db->fetch_object($resql);
686  if ($obj) {
687  $ret = $obj->nb;
688  }
689  $this->db->free($resql);
690  }
691 
692  if (!$error) {
693  return $ret;
694  } else {
695  return -1;
696  }
697  }
698 
699 
712  public function getNomUrl($withpicto = 0, $option = '', $mode = 'task', $addlabel = 0, $sep = ' - ', $notooltip = 0, $save_lastsearch_value = -1)
713  {
714  global $conf, $langs, $user;
715 
716  if (!empty($conf->dol_no_mouse_hover)) {
717  $notooltip = 1; // Force disable tooltips
718  }
719 
720  $result = '';
721  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Task").'</u>';
722  if (!empty($this->ref)) {
723  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
724  }
725  if (!empty($this->label)) {
726  $label .= '<br><b>'.$langs->trans('LabelTask').':</b> '.$this->label;
727  }
728  if ($this->date_start || $this->date_end) {
729  $label .= "<br>".get_date_range($this->date_start, $this->date_end, '', $langs, 0);
730  }
731 
732  $url = DOL_URL_ROOT.'/projet/tasks/'.$mode.'.php?id='.$this->id.($option == 'withproject' ? '&withproject=1' : '');
733  // Add param to save lastsearch_values or not
734  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
735  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
736  $add_save_lastsearch_values = 1;
737  }
738  if ($add_save_lastsearch_values) {
739  $url .= '&save_lastsearch_values=1';
740  }
741 
742  $linkclose = '';
743  if (empty($notooltip)) {
744  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
745  $label = $langs->trans("ShowTask");
746  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
747  }
748  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
749  $linkclose .= ' class="classfortooltip nowraponall"';
750  } else {
751  $linkclose .= ' class="nowraponall"';
752  }
753 
754  $linkstart = '<a href="'.$url.'"';
755  $linkstart .= $linkclose.'>';
756  $linkend = '</a>';
757 
758  $picto = 'projecttask';
759 
760  $result .= $linkstart;
761  if ($withpicto) {
762  $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
763  }
764  if ($withpicto != 2) {
765  $result .= $this->ref;
766  }
767  $result .= $linkend;
768  if ($withpicto != 2) {
769  $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
770  }
771 
772  return $result;
773  }
774 
782  public function initAsSpecimen()
783  {
784  $this->id = 0;
785 
786  $this->fk_project = '';
787  $this->ref = 'TK01';
788  $this->fk_task_parent = null;
789  $this->label = 'Specimen task TK01';
790  $this->duration_effective = '';
791  $this->fk_user_creat = null;
792  $this->progress = '25';
793  $this->fk_statut = null;
794  $this->note = 'This is a specimen task not';
795  }
796 
820  public function getTasksArray($usert = null, $userp = null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj = '', $filteronprojstatus = '-1', $morewherefilter = '', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields = array(), $includebilltime = 0, $search_array_options = array(), $loadextras = 0, $loadRoleMode = 1, $sortfield = '', $sortorder = '')
821  {
822  global $conf, $hookmanager;
823 
824  $tasks = array();
825 
826  //print $usert.'-'.$userp.'-'.$projectid.'-'.$socid.'-'.$mode.'<br>';
827 
828  // List of tasks (does not care about permissions. Filtering will be done later)
829  $sql = "SELECT ";
830  if ($filteronprojuser > 0 || $filterontaskuser > 0) {
831  $sql .= " DISTINCT"; // We may get several time the same record if user has several roles on same project/task
832  }
833  $sql .= " p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
834  $sql .= " t.rowid as taskid, t.ref as taskref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut as status,";
835  $sql .= " t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang,";
836  $sql .= " t.description, ";
837  $sql .= " t.budget_amount, ";
838  $sql .= " s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
839  $sql .= " p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount";
840  if (!empty($extrafields->attributes['projet']['label'])) {
841  foreach ($extrafields->attributes['projet']['label'] as $key => $val) {
842  $sql .= ($extrafields->attributes['projet']['type'][$key] != 'separate' ? ",efp.".$key." as options_".$key : '');
843  }
844  }
845  if (!empty($extrafields->attributes['projet_task']['label'])) {
846  foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) {
847  $sql .= ($extrafields->attributes['projet_task']['type'][$key] != 'separate' ? ",efpt.".$key." as options_".$key : '');
848  }
849  }
850  if ($includebilltime) {
851  $sql .= ", SUM(tt.task_duration * ".$this->db->ifsql("invoice_id IS NULL", "1", "0").") as tobill, SUM(tt.task_duration * ".$this->db->ifsql("invoice_id IS NULL", "0", "1").") as billed";
852  }
853 
854  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
855  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
856  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_extrafields as efp ON (p.rowid = efp.fk_object)";
857 
858  if ($mode == 0) {
859  if ($filteronprojuser > 0) {
860  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
861  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
862  }
863  $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
864  if ($includebilltime) {
865  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid";
866  }
867  if ($filterontaskuser > 0) {
868  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec2";
869  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc2";
870  }
871  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
872  $sql .= " WHERE p.entity IN (".getEntity('project').")";
873  $sql .= " AND t.fk_projet = p.rowid";
874  } elseif ($mode == 1) {
875  if ($filteronprojuser > 0) {
876  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
877  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
878  }
879  if ($filterontaskuser > 0) {
880  $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
881  if ($includebilltime) {
882  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid";
883  }
884  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec2";
885  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc2";
886  } else {
887  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t on t.fk_projet = p.rowid";
888  if ($includebilltime) {
889  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid";
890  }
891  }
892  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
893  $sql .= " WHERE p.entity IN (".getEntity('project').")";
894  } else {
895  return 'BadValueForParameterMode';
896  }
897 
898  if ($filteronprojuser > 0) {
899  $sql .= " AND p.rowid = ec.element_id";
900  $sql .= " AND ctc.rowid = ec.fk_c_type_contact";
901  $sql .= " AND ctc.element = 'project'";
902  $sql .= " AND ec.fk_socpeople = ".((int) $filteronprojuser);
903  $sql .= " AND ec.statut = 4";
904  $sql .= " AND ctc.source = 'internal'";
905  }
906  if ($filterontaskuser > 0) {
907  $sql .= " AND t.fk_projet = p.rowid";
908  $sql .= " AND p.rowid = ec2.element_id";
909  $sql .= " AND ctc2.rowid = ec2.fk_c_type_contact";
910  $sql .= " AND ctc2.element = 'project_task'";
911  $sql .= " AND ec2.fk_socpeople = ".((int) $filterontaskuser);
912  $sql .= " AND ec2.statut = 4";
913  $sql .= " AND ctc2.source = 'internal'";
914  }
915  if ($socid) {
916  $sql .= " AND p.fk_soc = ".((int) $socid);
917  }
918  if ($projectid) {
919  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectid).")";
920  }
921  if ($filteronproj) {
922  $sql .= natural_search(array("p.ref", "p.title"), $filteronproj);
923  }
924  if ($filteronprojstatus && $filteronprojstatus != '-1') {
925  $sql .= " AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).")";
926  }
927  if ($morewherefilter) {
928  $sql .= $morewherefilter;
929  }
930  // Add where from extra fields
931  $extrafieldsobjectkey = 'projet_task';
932  $extrafieldsobjectprefix = 'efpt.';
933  global $db; // needed for extrafields_list_search_sql.tpl
934  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
935  // Add where from hooks
936  $parameters = array();
937  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
938  $sql .= $hookmanager->resPrint;
939  if ($includebilltime) {
940  $sql .= " GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
941  $sql .= " t.datec, t.dateo, t.datee, t.tms,";
942  $sql .= " t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
943  $sql .= " t.dateo, t.datee, t.planned_workload, t.rang,";
944  $sql .= " t.description, ";
945  $sql .= " t.budget_amount, ";
946  $sql .= " s.rowid, s.nom, s.email,";
947  $sql .= " p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
948  if (!empty($extrafields->attributes['projet']['label'])) {
949  foreach ($extrafields->attributes['projet']['label'] as $key => $val) {
950  $sql .= ($extrafields->attributes['projet']['type'][$key] != 'separate' ? ",efp.".$key : '');
951  }
952  }
953  if (!empty($extrafields->attributes['projet_task']['label'])) {
954  foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) {
955  $sql .= ($extrafields->attributes['projet_task']['type'][$key] != 'separate' ? ",efpt.".$key : '');
956  }
957  }
958  }
959 
960  if ($sortfield && $sortorder) {
961  $sql .= $this->db->order($sortfield, $sortorder);
962  } else {
963  $sql .= " ORDER BY p.ref, t.rang, t.dateo";
964  }
965 
966  //print $sql;exit;
967  dol_syslog(get_class($this)."::getTasksArray", LOG_DEBUG);
968  $resql = $this->db->query($sql);
969  if ($resql) {
970  $num = $this->db->num_rows($resql);
971  $i = 0;
972  // Loop on each record found, so each couple (project id, task id)
973  while ($i < $num) {
974  $error = 0;
975 
976  $obj = $this->db->fetch_object($resql);
977 
978  if ($loadRoleMode) {
979  if ((!$obj->public) && (is_object($userp))) { // If not public project and we ask a filter on project owned by a user
980  if (!$this->getUserRolesForProjectsOrTasks($userp, 0, $obj->projectid, 0)) {
981  $error++;
982  }
983  }
984  if (is_object($usert)) { // If we ask a filter on a user affected to a task
985  if (!$this->getUserRolesForProjectsOrTasks(0, $usert, $obj->projectid, $obj->taskid)) {
986  $error++;
987  }
988  }
989  }
990 
991  if (!$error) {
992  $tasks[$i] = new Task($this->db);
993  $tasks[$i]->id = $obj->taskid;
994  $tasks[$i]->ref = $obj->taskref;
995  $tasks[$i]->fk_project = $obj->projectid;
996  $tasks[$i]->projectref = $obj->ref;
997  $tasks[$i]->projectlabel = $obj->plabel;
998  $tasks[$i]->projectstatus = $obj->projectstatus;
999 
1000  $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
1001  $tasks[$i]->opp_amount = $obj->opp_amount;
1002  $tasks[$i]->opp_percent = $obj->opp_percent;
1003  $tasks[$i]->budget_amount = $obj->budget_amount;
1004  $tasks[$i]->project_budget_amount = $obj->project_budget_amount;
1005  $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
1006 
1007  $tasks[$i]->label = $obj->label;
1008  $tasks[$i]->description = $obj->description;
1009  $tasks[$i]->fk_parent = $obj->fk_task_parent; // deprecated
1010  $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
1011  $tasks[$i]->duration = $obj->duration_effective;
1012  $tasks[$i]->planned_workload = $obj->planned_workload;
1013 
1014  if ($includebilltime) {
1015  $tasks[$i]->tobill = $obj->tobill;
1016  $tasks[$i]->billed = $obj->billed;
1017  }
1018 
1019  $tasks[$i]->progress = $obj->progress;
1020  $tasks[$i]->fk_statut = $obj->status;
1021  $tasks[$i]->public = $obj->public;
1022  $tasks[$i]->date_start = $this->db->jdate($obj->date_start);
1023  $tasks[$i]->date_end = $this->db->jdate($obj->date_end);
1024  $tasks[$i]->rang = $obj->rang;
1025 
1026  $tasks[$i]->socid = $obj->thirdparty_id; // For backward compatibility
1027  $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
1028  $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
1029  $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
1030 
1031  if (!empty($extrafields->attributes['projet']['label'])) {
1032  foreach ($extrafields->attributes['projet']['label'] as $key => $val) {
1033  if ($extrafields->attributes['projet']['type'][$key] != 'separate') {
1034  $tasks[$i]->{'options_'.$key} = $obj->{'options_'.$key};
1035  }
1036  }
1037  }
1038 
1039  if (!empty($extrafields->attributes['projet_task']['label'])) {
1040  foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) {
1041  if ($extrafields->attributes['projet_task']['type'][$key] != 'separate') {
1042  $tasks[$i]->{'options_'.$key} = $obj->{'options_'.$key};
1043  }
1044  }
1045  }
1046 
1047  if ($loadextras) {
1048  $tasks[$i]->fetch_optionals();
1049  }
1050  }
1051 
1052  $i++;
1053  }
1054  $this->db->free($resql);
1055  } else {
1056  dol_print_error($this->db);
1057  }
1058 
1059  return $tasks;
1060  }
1061 
1072  public function getUserRolesForProjectsOrTasks($userp, $usert, $projectid = '', $taskid = 0, $filteronprojstatus = -1)
1073  {
1074  $arrayroles = array();
1075 
1076  dol_syslog(get_class($this)."::getUserRolesForProjectsOrTasks userp=".is_object($userp)." usert=".is_object($usert)." projectid=".$projectid." taskid=".$taskid);
1077 
1078  // We want role of user for a projet or role of user for a task. Both are not possible.
1079  if (empty($userp) && empty($usert)) {
1080  $this->error = "CallWithWrongParameters";
1081  return -1;
1082  }
1083  if (!empty($userp) && !empty($usert)) {
1084  $this->error = "CallWithWrongParameters";
1085  return -1;
1086  }
1087 
1088  /* Liste des taches et role sur les projets ou taches */
1089  $sql = "SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
1090  if ($userp) {
1091  $sql .= " FROM ".MAIN_DB_PREFIX."projet as pt";
1092  }
1093  if ($usert && $filteronprojstatus > -1) {
1094  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p, ".MAIN_DB_PREFIX."projet_task as pt";
1095  }
1096  if ($usert && $filteronprojstatus <= -1) {
1097  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
1098  }
1099  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
1100  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
1101  $sql .= " WHERE pt.rowid = ec.element_id";
1102  if ($userp && $filteronprojstatus > -1) {
1103  $sql .= " AND pt.fk_statut = ".((int) $filteronprojstatus);
1104  }
1105  if ($usert && $filteronprojstatus > -1) {
1106  $sql .= " AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus);
1107  }
1108  if ($userp) {
1109  $sql .= " AND ctc.element = 'project'";
1110  }
1111  if ($usert) {
1112  $sql .= " AND ctc.element = 'project_task'";
1113  }
1114  $sql .= " AND ctc.rowid = ec.fk_c_type_contact";
1115  if ($userp) {
1116  $sql .= " AND ec.fk_socpeople = ".((int) $userp->id);
1117  }
1118  if ($usert) {
1119  $sql .= " AND ec.fk_socpeople = ".((int) $usert->id);
1120  }
1121  $sql .= " AND ec.statut = 4";
1122  $sql .= " AND ctc.source = 'internal'";
1123  if ($projectid) {
1124  if ($userp) {
1125  $sql .= " AND pt.rowid IN (".$this->db->sanitize($projectid).")";
1126  }
1127  if ($usert) {
1128  $sql .= " AND pt.fk_projet IN (".$this->db->sanitize($projectid).")";
1129  }
1130  }
1131  if ($taskid) {
1132  if ($userp) {
1133  $sql .= " ERROR SHOULD NOT HAPPENS";
1134  }
1135  if ($usert) {
1136  $sql .= " AND pt.rowid = ".((int) $taskid);
1137  }
1138  }
1139  //print $sql;
1140 
1141  dol_syslog(get_class($this)."::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1142  $resql = $this->db->query($sql);
1143  if ($resql) {
1144  $num = $this->db->num_rows($resql);
1145  $i = 0;
1146  while ($i < $num) {
1147  $obj = $this->db->fetch_object($resql);
1148  if (empty($arrayroles[$obj->pid])) {
1149  $arrayroles[$obj->pid] = $obj->code;
1150  } else {
1151  $arrayroles[$obj->pid] .= ','.$obj->code;
1152  }
1153  $i++;
1154  }
1155  $this->db->free($resql);
1156  } else {
1157  dol_print_error($this->db);
1158  }
1159 
1160  return $arrayroles;
1161  }
1162 
1163 
1170  public function getListContactId($source = 'internal')
1171  {
1172  $contactAlreadySelected = array();
1173  $tab = $this->liste_contact(-1, $source);
1174  //var_dump($tab);
1175  $num = count($tab);
1176  $i = 0;
1177  while ($i < $num) {
1178  if ($source == 'thirdparty') {
1179  $contactAlreadySelected[$i] = $tab[$i]['socid'];
1180  } else {
1181  $contactAlreadySelected[$i] = $tab[$i]['id'];
1182  }
1183  $i++;
1184  }
1185  return $contactAlreadySelected;
1186  }
1187 
1188 
1196  public function addTimeSpent($user, $notrigger = 0)
1197  {
1198  global $conf, $langs;
1199 
1200  dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
1201 
1202  $ret = 0;
1203  $now = dol_now();
1204 
1205  // Check parameters
1206  if (!is_object($user)) {
1207  dol_print_error('', "Method addTimeSpent was called with wrong parameter user");
1208  return -1;
1209  }
1210 
1211  // Clean parameters
1212  if (isset($this->timespent_note)) {
1213  $this->timespent_note = trim($this->timespent_note);
1214  }
1215  if (empty($this->timespent_datehour)) {
1216  $this->timespent_datehour = $this->timespent_date;
1217  }
1218 
1219  if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1220  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1221  $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
1222 
1223  if ($this->timespent_date < $restrictBefore) {
1224  $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1225  $this->errors[] = $this->error;
1226  return -1;
1227  }
1228  }
1229 
1230 
1231  $this->db->begin();
1232 
1233  $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (";
1234  $sql .= "fk_task";
1235  $sql .= ", task_date";
1236  $sql .= ", task_datehour";
1237  $sql .= ", task_date_withhour";
1238  $sql .= ", task_duration";
1239  $sql .= ", fk_user";
1240  $sql .= ", note";
1241  $sql .= ", datec";
1242  $sql .= ") VALUES (";
1243  $sql .= ((int) $this->id);
1244  $sql .= ", '".$this->db->idate($this->timespent_date)."'";
1245  $sql .= ", '".$this->db->idate($this->timespent_datehour)."'";
1246  $sql .= ", ".(empty($this->timespent_withhour) ? 0 : 1);
1247  $sql .= ", ".((int) $this->timespent_duration);
1248  $sql .= ", ".((int) $this->timespent_fk_user);
1249  $sql .= ", ".(isset($this->timespent_note) ? "'".$this->db->escape($this->timespent_note)."'" : "null");
1250  $sql .= ", '".$this->db->idate($now)."'";
1251  $sql .= ")";
1252 
1253  $resql = $this->db->query($sql);
1254  if ($resql) {
1255  $tasktime_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time");
1256  $ret = $tasktime_id;
1257  $this->timespent_id = $ret;
1258 
1259  if (!$notrigger) {
1260  // Call trigger
1261  $result = $this->call_trigger('TASK_TIMESPENT_CREATE', $user);
1262  if ($result < 0) {
1263  $ret = -1;
1264  }
1265  // End call triggers
1266  }
1267  } else {
1268  $this->error = $this->db->lasterror();
1269  $ret = -1;
1270  }
1271 
1272  if ($ret > 0) {
1273  // Recalculate amount of time spent for task and update denormalized field
1274  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
1275  $sql .= " SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX."projet_task_time as ptt where ptt.fk_task = ".((int) $this->id).")";
1276  if (isset($this->progress)) {
1277  $sql .= ", progress = ".((float) $this->progress); // Do not overwrite value if not provided
1278  }
1279  $sql .= " WHERE rowid = ".((int) $this->id);
1280 
1281  dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
1282  if (!$this->db->query($sql)) {
1283  $this->error = $this->db->lasterror();
1284  $ret = -2;
1285  }
1286 
1287  // Update hourly rate of this time spent entry
1288  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time";
1289  $sql .= " SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".((int) $this->timespent_fk_user).")"; // set average hour rate of user
1290  $sql .= " WHERE rowid = ".((int) $tasktime_id);
1291 
1292  dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
1293  if (!$this->db->query($sql)) {
1294  $this->error = $this->db->lasterror();
1295  $ret = -2;
1296  }
1297  }
1298 
1299  if ($ret > 0) {
1300  $this->db->commit();
1301  } else {
1302  $this->db->rollback();
1303  }
1304  return $ret;
1305  }
1306 
1313  public function fetchTimeSpentOnTask($morewherefilter = '')
1314  {
1315  global $langs;
1316 
1317  $arrayres = array();
1318 
1319  $sql = "SELECT";
1320  $sql .= " s.rowid as socid,";
1321  $sql .= " s.nom as thirdparty_name,";
1322  $sql .= " s.email as thirdparty_email,";
1323  $sql .= " ptt.rowid,";
1324  $sql .= " ptt.fk_task,";
1325  $sql .= " ptt.task_date,";
1326  $sql .= " ptt.task_datehour,";
1327  $sql .= " ptt.task_date_withhour,";
1328  $sql .= " ptt.task_duration,";
1329  $sql .= " ptt.fk_user,";
1330  $sql .= " ptt.note,";
1331  $sql .= " ptt.thm,";
1332  $sql .= " pt.rowid as task_id,";
1333  $sql .= " pt.ref as task_ref,";
1334  $sql .= " pt.label as task_label,";
1335  $sql .= " p.rowid as project_id,";
1336  $sql .= " p.ref as project_ref,";
1337  $sql .= " p.title as project_label,";
1338  $sql .= " p.public as public";
1339  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as ptt, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet as p";
1340  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
1341  $sql .= " WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1342  $sql .= " AND pt.rowid = ".((int) $this->id);
1343  $sql .= " AND pt.entity IN (".getEntity('project').")";
1344  if ($morewherefilter) {
1345  $sql .= $morewherefilter;
1346  }
1347 
1348  dol_syslog(get_class($this)."::fetchAllTimeSpent", LOG_DEBUG);
1349  $resql = $this->db->query($sql);
1350  if ($resql) {
1351  $num = $this->db->num_rows($resql);
1352 
1353  $i = 0;
1354  while ($i < $num) {
1355  $obj = $this->db->fetch_object($resql);
1356 
1357  $newobj = new stdClass();
1358 
1359  $newobj->socid = $obj->socid;
1360  $newobj->thirdparty_name = $obj->thirdparty_name;
1361  $newobj->thirdparty_email = $obj->thirdparty_email;
1362 
1363  $newobj->fk_project = $obj->project_id;
1364  $newobj->project_ref = $obj->project_ref;
1365  $newobj->project_label = $obj->project_label;
1366  $newobj->public = $obj->project_public;
1367 
1368  $newobj->fk_task = $obj->task_id;
1369  $newobj->task_ref = $obj->task_ref;
1370  $newobj->task_label = $obj->task_label;
1371 
1372  $newobj->timespent_line_id = $obj->rowid;
1373  $newobj->timespent_line_date = $this->db->jdate($obj->task_date);
1374  $newobj->timespent_line_datehour = $this->db->jdate($obj->task_datehour);
1375  $newobj->timespent_line_withhour = $obj->task_date_withhour;
1376  $newobj->timespent_line_duration = $obj->task_duration;
1377  $newobj->timespent_line_fk_user = $obj->fk_user;
1378  $newobj->timespent_line_thm = $obj->thm; // hourly rate
1379  $newobj->timespent_line_note = $obj->note;
1380 
1381  $arrayres[] = $newobj;
1382 
1383  $i++;
1384  }
1385 
1386  $this->db->free($resql);
1387 
1388  $this->lines = $arrayres;
1389  return 1;
1390  } else {
1391  dol_print_error($this->db);
1392  $this->error = "Error ".$this->db->lasterror();
1393  return -1;
1394  }
1395  }
1396 
1397 
1405  public function getSummaryOfTimeSpent($userobj = null, $morewherefilter = '')
1406  {
1407  global $langs;
1408 
1409  if (is_object($userobj)) {
1410  $userid = $userobj->id;
1411  } else {
1412  $userid = $userobj; // old method
1413  }
1414 
1415  $id = $this->id;
1416  if (empty($id) && empty($userid)) {
1417  dol_syslog("getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1418  return -1;
1419  }
1420 
1421  $result = array();
1422 
1423  $sql = "SELECT";
1424  $sql .= " MIN(t.task_datehour) as min_date,";
1425  $sql .= " MAX(t.task_datehour) as max_date,";
1426  $sql .= " SUM(t.task_duration) as total_duration,";
1427  $sql .= " SUM(t.task_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as total_amount,";
1428  $sql .= " COUNT(t.rowid) as nblines,";
1429  $sql .= " SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull";
1430  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
1431  $sql .= " WHERE 1 = 1";
1432  if ($morewherefilter) {
1433  $sql .= $morewherefilter;
1434  }
1435  if ($id > 0) {
1436  $sql .= " AND t.fk_task = ".((int) $id);
1437  }
1438  if ($userid > 0) {
1439  $sql .= " AND t.fk_user = ".((int) $userid);
1440  }
1441 
1442  dol_syslog(get_class($this)."::getSummaryOfTimeSpent", LOG_DEBUG);
1443  $resql = $this->db->query($sql);
1444  if ($resql) {
1445  $obj = $this->db->fetch_object($resql);
1446 
1447  $result['min_date'] = $obj->min_date; // deprecated. use the ->timespent_xxx instead
1448  $result['max_date'] = $obj->max_date; // deprecated. use the ->timespent_xxx instead
1449  $result['total_duration'] = $obj->total_duration; // deprecated. use the ->timespent_xxx instead
1450 
1451  $this->timespent_min_date = $this->db->jdate($obj->min_date);
1452  $this->timespent_max_date = $this->db->jdate($obj->max_date);
1453  $this->timespent_total_duration = $obj->total_duration;
1454  $this->timespent_total_amount = $obj->total_amount;
1455  $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1456  $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1457 
1458  $this->db->free($resql);
1459  } else {
1460  dol_print_error($this->db);
1461  }
1462  return $result;
1463  }
1464 
1473  public function getSumOfAmount($fuser = '', $dates = '', $datee = '')
1474  {
1475  global $langs;
1476 
1477  if (empty($id)) {
1478  $id = $this->id;
1479  }
1480 
1481  $result = array();
1482 
1483  $sql = "SELECT";
1484  $sql .= " SUM(t.task_duration) as nbseconds,";
1485  $sql .= " SUM(t.task_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as amount, SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull";
1486  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
1487  $sql .= " WHERE t.fk_task = ".((int) $id);
1488  if (is_object($fuser) && $fuser->id > 0) {
1489  $sql .= " AND fk_user = ".((int) $fuser->id);
1490  }
1491  if ($dates > 0) {
1492  $datefieldname = "task_datehour";
1493  $sql .= " AND (".$datefieldname." >= '".$this->db->idate($dates)."' OR ".$datefieldname." IS NULL)";
1494  }
1495  if ($datee > 0) {
1496  $datefieldname = "task_datehour";
1497  $sql .= " AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)";
1498  }
1499  //print $sql;
1500 
1501  dol_syslog(get_class($this)."::getSumOfAmount", LOG_DEBUG);
1502  $resql = $this->db->query($sql);
1503  if ($resql) {
1504  $obj = $this->db->fetch_object($resql);
1505 
1506  $result['amount'] = $obj->amount;
1507  $result['nbseconds'] = $obj->nbseconds;
1508  $result['nblinesnull'] = $obj->nblinesnull;
1509 
1510  $this->db->free($resql);
1511  return $result;
1512  } else {
1513  dol_print_error($this->db);
1514  return $result;
1515  }
1516  }
1517 
1524  public function fetchTimeSpent($id)
1525  {
1526  global $langs;
1527 
1528  $sql = "SELECT";
1529  $sql .= " t.rowid,";
1530  $sql .= " t.fk_task,";
1531  $sql .= " t.task_date,";
1532  $sql .= " t.task_datehour,";
1533  $sql .= " t.task_date_withhour,";
1534  $sql .= " t.task_duration,";
1535  $sql .= " t.fk_user,";
1536  $sql .= " t.thm,";
1537  $sql .= " t.note";
1538  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
1539  $sql .= " WHERE t.rowid = ".((int) $id);
1540 
1541  dol_syslog(get_class($this)."::fetchTimeSpent", LOG_DEBUG);
1542  $resql = $this->db->query($sql);
1543  if ($resql) {
1544  if ($this->db->num_rows($resql)) {
1545  $obj = $this->db->fetch_object($resql);
1546 
1547  $this->timespent_id = $obj->rowid;
1548  $this->id = $obj->fk_task;
1549  $this->timespent_date = $this->db->jdate($obj->task_date);
1550  $this->timespent_datehour = $this->db->jdate($obj->task_datehour);
1551  $this->timespent_withhour = $obj->task_date_withhour;
1552  $this->timespent_duration = $obj->task_duration;
1553  $this->timespent_fk_user = $obj->fk_user;
1554  $this->timespent_thm = $obj->thm; // hourly rate
1555  $this->timespent_note = $obj->note;
1556  }
1557 
1558  $this->db->free($resql);
1559 
1560  return 1;
1561  } else {
1562  $this->error = "Error ".$this->db->lasterror();
1563  return -1;
1564  }
1565  }
1566 
1574  public function fetchAllTimeSpent(User $userobj, $morewherefilter = '')
1575  {
1576  global $langs;
1577 
1578  $arrayres = array();
1579 
1580  $sql = "SELECT";
1581  $sql .= " s.rowid as socid,";
1582  $sql .= " s.nom as thirdparty_name,";
1583  $sql .= " s.email as thirdparty_email,";
1584  $sql .= " ptt.rowid,";
1585  $sql .= " ptt.fk_task,";
1586  $sql .= " ptt.task_date,";
1587  $sql .= " ptt.task_datehour,";
1588  $sql .= " ptt.task_date_withhour,";
1589  $sql .= " ptt.task_duration,";
1590  $sql .= " ptt.fk_user,";
1591  $sql .= " ptt.note,";
1592  $sql .= " ptt.thm,";
1593  $sql .= " pt.rowid as task_id,";
1594  $sql .= " pt.ref as task_ref,";
1595  $sql .= " pt.label as task_label,";
1596  $sql .= " p.rowid as project_id,";
1597  $sql .= " p.ref as project_ref,";
1598  $sql .= " p.title as project_label,";
1599  $sql .= " p.public as public";
1600  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as ptt, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet as p";
1601  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
1602  $sql .= " WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1603  $sql .= " AND ptt.fk_user = ".((int) $userobj->id);
1604  $sql .= " AND pt.entity IN (".getEntity('project').")";
1605  if ($morewherefilter) {
1606  $sql .= $morewherefilter;
1607  }
1608 
1609  dol_syslog(get_class($this)."::fetchAllTimeSpent", LOG_DEBUG);
1610  $resql = $this->db->query($sql);
1611  if ($resql) {
1612  $num = $this->db->num_rows($resql);
1613 
1614  $i = 0;
1615  while ($i < $num) {
1616  $obj = $this->db->fetch_object($resql);
1617 
1618  $newobj = new stdClass();
1619 
1620  $newobj->socid = $obj->socid;
1621  $newobj->thirdparty_name = $obj->thirdparty_name;
1622  $newobj->thirdparty_email = $obj->thirdparty_email;
1623 
1624  $newobj->fk_project = $obj->project_id;
1625  $newobj->project_ref = $obj->project_ref;
1626  $newobj->project_label = $obj->project_label;
1627  $newobj->public = $obj->project_public;
1628 
1629  $newobj->fk_task = $obj->task_id;
1630  $newobj->task_ref = $obj->task_ref;
1631  $newobj->task_label = $obj->task_label;
1632 
1633  $newobj->timespent_id = $obj->rowid;
1634  $newobj->timespent_date = $this->db->jdate($obj->task_date);
1635  $newobj->timespent_datehour = $this->db->jdate($obj->task_datehour);
1636  $newobj->timespent_withhour = $obj->task_date_withhour;
1637  $newobj->timespent_duration = $obj->task_duration;
1638  $newobj->timespent_fk_user = $obj->fk_user;
1639  $newobj->timespent_thm = $obj->thm; // hourly rate
1640  $newobj->timespent_note = $obj->note;
1641 
1642  $arrayres[] = $newobj;
1643 
1644  $i++;
1645  }
1646 
1647  $this->db->free($resql);
1648  } else {
1649  dol_print_error($this->db);
1650  $this->error = "Error ".$this->db->lasterror();
1651  return -1;
1652  }
1653 
1654  return $arrayres;
1655  }
1656 
1664  public function updateTimeSpent($user, $notrigger = 0)
1665  {
1666  global $conf, $langs;
1667 
1668  $ret = 0;
1669 
1670  // Check parameters
1671  if ($this->timespent_date == '') {
1672  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Date"));
1673  return -1;
1674  }
1675  if (!($this->timespent_fk_user > 0)) {
1676  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("User"));
1677  return -1;
1678  }
1679 
1680  // Clean parameters
1681  if (empty($this->timespent_datehour)) {
1682  $this->timespent_datehour = $this->timespent_date;
1683  }
1684  if (isset($this->timespent_note)) {
1685  $this->timespent_note = trim($this->timespent_note);
1686  }
1687 
1688  if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1689  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1690  $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
1691 
1692  if ($this->timespent_date < $restrictBefore) {
1693  $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1694  $this->errors[] = $this->error;
1695  return -1;
1696  }
1697  }
1698 
1699  $this->db->begin();
1700 
1701  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET";
1702  $sql .= " task_date = '".$this->db->idate($this->timespent_date)."',";
1703  $sql .= " task_datehour = '".$this->db->idate($this->timespent_datehour)."',";
1704  $sql .= " task_date_withhour = ".(empty($this->timespent_withhour) ? 0 : 1).",";
1705  $sql .= " task_duration = ".((int) $this->timespent_duration).",";
1706  $sql .= " fk_user = ".((int) $this->timespent_fk_user).",";
1707  $sql .= " note = ".(isset($this->timespent_note) ? "'".$this->db->escape($this->timespent_note)."'" : "null");
1708  $sql .= " WHERE rowid = ".((int) $this->timespent_id);
1709 
1710  dol_syslog(get_class($this)."::updateTimeSpent", LOG_DEBUG);
1711  if ($this->db->query($sql)) {
1712  if (!$notrigger) {
1713  // Call trigger
1714  $result = $this->call_trigger('TASK_TIMESPENT_MODIFY', $user);
1715  if ($result < 0) {
1716  $this->db->rollback();
1717  $ret = -1;
1718  } else {
1719  $ret = 1;
1720  }
1721  // End call triggers
1722  } else {
1723  $ret = 1;
1724  }
1725  } else {
1726  $this->error = $this->db->lasterror();
1727  $this->db->rollback();
1728  $ret = -1;
1729  }
1730 
1731  if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration)) {
1732  // Recalculate amount of time spent for task and update denormalized field
1733  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
1734  $sql .= " SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX."projet_task_time as ptt where ptt.fk_task = ".((int) $this->id).")";
1735  if (isset($this->progress)) {
1736  $sql .= ", progress = ".((float) $this->progress); // Do not overwrite value if not provided
1737  }
1738  $sql .= " WHERE rowid = ".((int) $this->id);
1739 
1740  dol_syslog(get_class($this)."::updateTimeSpent", LOG_DEBUG);
1741  if (!$this->db->query($sql)) {
1742  $this->error = $this->db->lasterror();
1743  $this->db->rollback();
1744  $ret = -2;
1745  }
1746 
1747  // Update hourly rate of this time spent entry, but only if it was not set initialy
1748  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time";
1749  $sql .= " SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".((int) $this->timespent_fk_user).")"; // set average hour rate of user
1750  $sql .= " WHERE (thm IS NULL OR thm = 0) AND rowid = ".((int) $this->timespent_id);
1751 
1752  dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
1753  if (!$this->db->query($sql)) {
1754  $this->error = $this->db->lasterror();
1755  $ret = -2;
1756  }
1757  }
1758 
1759  if ($ret >= 0) {
1760  $this->db->commit();
1761  }
1762  return $ret;
1763  }
1764 
1772  public function delTimeSpent($user, $notrigger = 0)
1773  {
1774  global $conf, $langs;
1775 
1776  $error = 0;
1777 
1778  if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1779  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1780  $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
1781 
1782  if ($this->timespent_date < $restrictBefore) {
1783  $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1784  $this->errors[] = $this->error;
1785  return -1;
1786  }
1787  }
1788 
1789  $this->db->begin();
1790 
1791  if (!$notrigger) {
1792  // Call trigger
1793  $result = $this->call_trigger('TASK_TIMESPENT_DELETE', $user);
1794  if ($result < 0) {
1795  $error++;
1796  }
1797  // End call triggers
1798  }
1799 
1800  if (!$error) {
1801  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time";
1802  $sql .= " WHERE rowid = ".((int) $this->timespent_id);
1803 
1804  dol_syslog(get_class($this)."::delTimeSpent", LOG_DEBUG);
1805  $resql = $this->db->query($sql);
1806  if (!$resql) {
1807  $error++; $this->errors[] = "Error ".$this->db->lasterror();
1808  }
1809  }
1810 
1811  if (!$error) {
1812  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
1813  $sql .= " SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? $this->timespent_duration : 0);
1814  $sql .= " WHERE rowid = ".((int) $this->id);
1815 
1816  dol_syslog(get_class($this)."::delTimeSpent", LOG_DEBUG);
1817  if ($this->db->query($sql)) {
1818  $result = 0;
1819  } else {
1820  $this->error = $this->db->lasterror();
1821  $result = -2;
1822  }
1823  }
1824 
1825  // Commit or rollback
1826  if ($error) {
1827  foreach ($this->errors as $errmsg) {
1828  dol_syslog(get_class($this)."::delTimeSpent ".$errmsg, LOG_ERR);
1829  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1830  }
1831  $this->db->rollback();
1832  return -1 * $error;
1833  } else {
1834  $this->db->commit();
1835  return 1;
1836  }
1837  }
1838 
1853  public function createFromClone(User $user, $fromid, $project_id, $parent_task_id, $clone_change_dt = false, $clone_affectation = false, $clone_time = false, $clone_file = false, $clone_note = false, $clone_prog = false)
1854  {
1855  global $langs, $conf;
1856 
1857  $error = 0;
1858 
1859  //Use 00:00 of today if time is use on task.
1860  $now = dol_mktime(0, 0, 0, dol_print_date(dol_now(), '%m'), dol_print_date(dol_now(), '%d'), dol_print_date(dol_now(), '%Y'));
1861 
1862  $datec = $now;
1863 
1864  $clone_task = new Task($this->db);
1865  $origin_task = new Task($this->db);
1866 
1867  $clone_task->context['createfromclone'] = 'createfromclone';
1868 
1869  $this->db->begin();
1870 
1871  // Load source object
1872  $clone_task->fetch($fromid);
1873  $clone_task->fetch_optionals();
1874  //var_dump($clone_task->array_options);exit;
1875 
1876  $origin_task->fetch($fromid);
1877 
1878  $defaultref = '';
1879  $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
1880  if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php")) {
1881  require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
1882  $modTask = new $obj;
1883  $defaultref = $modTask->getNextValue(0, $clone_task);
1884  }
1885 
1886  $ori_project_id = $clone_task->fk_project;
1887 
1888  $clone_task->id = 0;
1889  $clone_task->ref = $defaultref;
1890  $clone_task->fk_project = $project_id;
1891  $clone_task->fk_task_parent = $parent_task_id;
1892  $clone_task->date_c = $datec;
1893  $clone_task->planned_workload = $origin_task->planned_workload;
1894  $clone_task->rang = $origin_task->rang;
1895 
1896  //Manage Task Date
1897  if ($clone_change_dt) {
1898  $projectstatic = new Project($this->db);
1899  $projectstatic->fetch($ori_project_id);
1900 
1901  //Origin project strat date
1902  $orign_project_dt_start = $projectstatic->date_start;
1903 
1904  //Calcultate new task start date with difference between origin proj start date and origin task start date
1905  if (!empty($clone_task->date_start)) {
1906  $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
1907  }
1908 
1909  //Calcultate new task end date with difference between origin proj end date and origin task end date
1910  if (!empty($clone_task->date_end)) {
1911  $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
1912  }
1913  }
1914 
1915  if (!$clone_prog) {
1916  $clone_task->progress = 0;
1917  }
1918 
1919  // Create clone
1920  $result = $clone_task->create($user);
1921 
1922  // Other options
1923  if ($result < 0) {
1924  $this->error = $clone_task->error;
1925  $error++;
1926  }
1927 
1928  // End
1929  if (!$error) {
1930  $clone_task_id = $clone_task->id;
1931  $clone_task_ref = $clone_task->ref;
1932 
1933  //Note Update
1934  if (!$clone_note) {
1935  $clone_task->note_private = '';
1936  $clone_task->note_public = '';
1937  } else {
1938  $this->db->begin();
1939  $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5), '_public');
1940  if ($res < 0) {
1941  $this->error .= $clone_task->error;
1942  $error++;
1943  $this->db->rollback();
1944  } else {
1945  $this->db->commit();
1946  }
1947 
1948  $this->db->begin();
1949  $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5), '_private');
1950  if ($res < 0) {
1951  $this->error .= $clone_task->error;
1952  $error++;
1953  $this->db->rollback();
1954  } else {
1955  $this->db->commit();
1956  }
1957  }
1958 
1959  //Duplicate file
1960  if ($clone_file) {
1961  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1962 
1963  //retrieve project origin ref to know folder to copy
1964  $projectstatic = new Project($this->db);
1965  $projectstatic->fetch($ori_project_id);
1966  $ori_project_ref = $projectstatic->ref;
1967 
1968  if ($ori_project_id != $project_id) {
1969  $projectstatic->fetch($project_id);
1970  $clone_project_ref = $projectstatic->ref;
1971  } else {
1972  $clone_project_ref = $ori_project_ref;
1973  }
1974 
1975  $clone_task_dir = $conf->project->dir_output."/".dol_sanitizeFileName($clone_project_ref)."/".dol_sanitizeFileName($clone_task_ref);
1976  $ori_task_dir = $conf->project->dir_output."/".dol_sanitizeFileName($ori_project_ref)."/".dol_sanitizeFileName($fromid);
1977 
1978  $filearray = dol_dir_list($ori_task_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
1979  foreach ($filearray as $key => $file) {
1980  if (!file_exists($clone_task_dir)) {
1981  if (dol_mkdir($clone_task_dir) < 0) {
1982  $this->error .= $langs->trans('ErrorInternalErrorDetected').':dol_mkdir';
1983  $error++;
1984  }
1985  }
1986 
1987  $rescopy = dol_copy($ori_task_dir.'/'.$file['name'], $clone_task_dir.'/'.$file['name'], 0, 1);
1988  if (is_numeric($rescopy) && $rescopy < 0) {
1989  $this->error .= $langs->trans("ErrorFailToCopyFile", $ori_task_dir.'/'.$file['name'], $clone_task_dir.'/'.$file['name']);
1990  $error++;
1991  }
1992  }
1993  }
1994 
1995  // clone affectation
1996  if ($clone_affectation) {
1997  $origin_task = new Task($this->db);
1998  $origin_task->fetch($fromid);
1999 
2000  foreach (array('internal', 'external') as $source) {
2001  $tab = $origin_task->liste_contact(-1, $source);
2002  $num = count($tab);
2003  $i = 0;
2004  while ($i < $num) {
2005  $clone_task->add_contact($tab[$i]['id'], $tab[$i]['code'], $tab[$i]['source']);
2006  if ($clone_task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
2007  $langs->load("errors");
2008  $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
2009  $error++;
2010  } else {
2011  if ($clone_task->error != '') {
2012  $this->error .= $clone_task->error;
2013  $error++;
2014  }
2015  }
2016  $i++;
2017  }
2018  }
2019  }
2020 
2021  if ($clone_time) {
2022  //TODO clone time of affectation
2023  }
2024  }
2025 
2026  unset($clone_task->context['createfromclone']);
2027 
2028  if (!$error) {
2029  $this->db->commit();
2030  return $clone_task_id;
2031  } else {
2032  $this->db->rollback();
2033  dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : ".$this->error, LOG_ERR);
2034  return -1;
2035  }
2036  }
2037 
2038 
2045  public function getLibStatut($mode = 0)
2046  {
2047  return $this->LibStatut($this->fk_statut, $mode);
2048  }
2049 
2050  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2058  public function LibStatut($status, $mode = 0)
2059  {
2060  // phpcs:enable
2061  global $langs;
2062 
2063  // list of Statut of the task
2064  $this->statuts[0] = 'Draft';
2065  $this->statuts[1] = 'ToDo';
2066  $this->statuts[2] = 'Running';
2067  $this->statuts[3] = 'Finish';
2068  $this->statuts[4] = 'Transfered';
2069  $this->statuts_short[0] = 'Draft';
2070  $this->statuts_short[1] = 'ToDo';
2071  $this->statuts_short[2] = 'Running';
2072  $this->statuts_short[3] = 'Completed';
2073  $this->statuts_short[4] = 'Transfered';
2074 
2075  if ($mode == 0) {
2076  return $langs->trans($this->statuts[$status]);
2077  } elseif ($mode == 1) {
2078  return $langs->trans($this->statuts_short[$status]);
2079  } elseif ($mode == 2) {
2080  if ($status == 0) {
2081  return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]);
2082  } elseif ($status == 1) {
2083  return img_picto($langs->trans($this->statuts_short[$status]), 'statut1').' '.$langs->trans($this->statuts_short[$status]);
2084  } elseif ($status == 2) {
2085  return img_picto($langs->trans($this->statuts_short[$status]), 'statut3').' '.$langs->trans($this->statuts_short[$status]);
2086  } elseif ($status == 3) {
2087  return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]);
2088  } elseif ($status == 4) {
2089  return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]);
2090  } elseif ($status == 5) {
2091  return img_picto($langs->trans($this->statuts_short[$status]), 'statut5').' '.$langs->trans($this->statuts_short[$status]);
2092  }
2093  } elseif ($mode == 3) {
2094  if ($status == 0) {
2095  return img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
2096  } elseif ($status == 1) {
2097  return img_picto($langs->trans($this->statuts_short[$status]), 'statut1');
2098  } elseif ($status == 2) {
2099  return img_picto($langs->trans($this->statuts_short[$status]), 'statut3');
2100  } elseif ($status == 3) {
2101  return img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
2102  } elseif ($status == 4) {
2103  return img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
2104  } elseif ($status == 5) {
2105  return img_picto($langs->trans($this->statuts_short[$status]), 'statut5');
2106  }
2107  } elseif ($mode == 4) {
2108  if ($status == 0) {
2109  return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
2110  } elseif ($status == 1) {
2111  return img_picto($langs->trans($this->statuts_short[$status]), 'statut1').' '.$langs->trans($this->statuts[$status]);
2112  } elseif ($status == 2) {
2113  return img_picto($langs->trans($this->statuts_short[$status]), 'statut3').' '.$langs->trans($this->statuts[$status]);
2114  } elseif ($status == 3) {
2115  return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]);
2116  } elseif ($status == 4) {
2117  return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]);
2118  } elseif ($status == 5) {
2119  return img_picto($langs->trans($this->statuts_short[$status]), 'statut5').' '.$langs->trans($this->statuts[$status]);
2120  }
2121  } elseif ($mode == 5) {
2122  /*if ($status==0) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut0');
2123  elseif ($status==1) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut1');
2124  elseif ($status==2) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut3');
2125  elseif ($status==3) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut6');
2126  elseif ($status==4) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut6');
2127  elseif ($status==5) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut5');
2128  */
2129  //else return $this->progress.' %';
2130  return '&nbsp;';
2131  } elseif ($mode == 6) {
2132  /*if ($status==0) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut0');
2133  elseif ($status==1) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut1');
2134  elseif ($status==2) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut3');
2135  elseif ($status==3) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut6');
2136  elseif ($status==4) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut6');
2137  elseif ($status==5) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut5');
2138  */
2139  //else return $this->progress.' %';
2140  return '&nbsp;';
2141  }
2142  }
2143 
2154  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2155  {
2156  global $conf;
2157 
2158  $outputlangs->load("projects");
2159 
2160  if (!dol_strlen($modele)) {
2161  $modele = 'nodefault';
2162 
2163  if (!empty($this->model_pdf)) {
2164  $modele = $this->model_pdf;
2165  } elseif (!empty($this->modelpdf)) { // deprecated
2166  $modele = $this->modelpdf;
2167  } elseif (!empty($conf->global->PROJECT_TASK_ADDON_PDF)) {
2168  $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
2169  }
2170  }
2171 
2172  $modelpath = "core/modules/project/task/doc/";
2173 
2174  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2175  }
2176 
2177 
2178  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2185  public function load_board($user)
2186  {
2187  // phpcs:enable
2188  global $conf, $langs;
2189 
2190  // For external user, no check is done on company because readability is managed by public status of project and assignement.
2191  //$socid = $user->socid;
2192  $socid = 0;
2193 
2194  $projectstatic = new Project($this->db);
2195  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
2196 
2197  // List of tasks (does not care about permissions. Filtering will be done later)
2198  $sql = "SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
2199  $sql .= " t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
2200  $sql .= " t.dateo as date_start, t.datee as datee";
2201  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
2202  //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
2203  //if (! $user->rights->societe->client->voir && ! $socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2204  $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
2205  $sql .= " WHERE p.entity IN (".getEntity('project', 0).')';
2206  $sql .= " AND p.fk_statut = 1";
2207  $sql .= " AND t.fk_projet = p.rowid";
2208  $sql .= " AND (t.progress IS NULL OR t.progress < 100)"; // tasks to do
2209  if (empty($user->rights->projet->all->lire)) {
2210  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
2211  }
2212  // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
2213  //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
2214  // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
2215  // if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))";
2216 
2217  //print $sql;
2218  $resql = $this->db->query($sql);
2219  if ($resql) {
2220  $task_static = new Task($this->db);
2221 
2222  $response = new WorkboardResponse();
2223  $response->warning_delay = $conf->project->task->warning_delay / 60 / 60 / 24;
2224  $response->label = $langs->trans("OpenedTasks");
2225  if ($user->rights->projet->all->lire) {
2226  $response->url = DOL_URL_ROOT.'/projet/tasks/list.php?mainmenu=project';
2227  } else {
2228  $response->url = DOL_URL_ROOT.'/projet/tasks/list.php?mode=mine&amp;mainmenu=project';
2229  }
2230  $response->img = img_object('', "task");
2231 
2232  // This assignment in condition is not a bug. It allows walking the results.
2233  while ($obj = $this->db->fetch_object($resql)) {
2234  $response->nbtodo++;
2235 
2236  $task_static->projectstatus = $obj->projectstatus;
2237  $task_static->progress = $obj->progress;
2238  $task_static->fk_statut = $obj->status;
2239  $task_static->date_end = $this->db->jdate($obj->datee);
2240 
2241  if ($task_static->hasDelay()) {
2242  $response->nbtodolate++;
2243  }
2244  }
2245 
2246  return $response;
2247  } else {
2248  $this->error = $this->db->error();
2249  return -1;
2250  }
2251  }
2252 
2253 
2254  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2260  public function load_state_board()
2261  {
2262  // phpcs:enable
2263  global $user;
2264 
2265  $mine = 0; $socid = $user->socid;
2266 
2267  $projectstatic = new Project($this->db);
2268  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2269 
2270  // List of tasks (does not care about permissions. Filtering will be done later)
2271  $sql = "SELECT count(p.rowid) as nb";
2272  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
2273  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
2274  if (empty($user->rights->societe->client->voir) && !$socid) {
2275  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2276  }
2277  $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
2278  $sql .= " WHERE p.entity IN (".getEntity('project', 0).')';
2279  $sql .= " AND t.fk_projet = p.rowid"; // tasks to do
2280  if ($mine || empty($user->rights->projet->all->lire)) {
2281  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
2282  }
2283  // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
2284  //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
2285  if ($socid) {
2286  $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
2287  }
2288  if (empty($user->rights->societe->client->voir) && !$socid) {
2289  $sql .= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))";
2290  }
2291 
2292  $resql = $this->db->query($sql);
2293  if ($resql) {
2294  // This assignment in condition is not a bug. It allows walking the results.
2295  while ($obj = $this->db->fetch_object($resql)) {
2296  $this->nb["tasks"] = $obj->nb;
2297  }
2298  $this->db->free($resql);
2299  return 1;
2300  } else {
2301  dol_print_error($this->db);
2302  $this->error = $this->db->error();
2303  return -1;
2304  }
2305  }
2306 
2312  public function hasDelay()
2313  {
2314  global $conf;
2315 
2316  if (!($this->progress >= 0 && $this->progress < 100)) {
2317  return false;
2318  }
2319 
2320  $now = dol_now();
2321 
2322  $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0);
2323 
2324  return ($datetouse > 0 && ($datetouse < ($now - $conf->project->task->warning_delay)));
2325  }
2326 }
dol_move_dir
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
Definition: files.lib.php:979
db
$conf db
API class for accounts.
Definition: inc.php:41
Task\update
update($user=null, $notrigger=0)
Update database.
Definition: task.class.php:372
Task\fetchAllTimeSpent
fetchAllTimeSpent(User $userobj, $morewherefilter='')
Load all records of time spent.
Definition: task.class.php:1574
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
Project
Class to manage projects.
Definition: project.class.php:35
dol_delete_dir_recursive
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1383
Task\createFromClone
createFromClone(User $user, $fromid, $project_id, $parent_task_id, $clone_change_dt=false, $clone_affectation=false, $clone_time=false, $clone_file=false, $clone_note=false, $clone_prog=false)
Load an object from its id and create a new one in database.
Definition: task.class.php:1853
Task\updateTimeSpent
updateTimeSpent($user, $notrigger=0)
Update time spent.
Definition: task.class.php:1664
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
Task\getListContactId
getListContactId($source='internal')
Return list of id of contacts of task.
Definition: task.class.php:1170
Task
Class to manage tasks.
Definition: task.class.php:37
ref
$object ref
Definition: info.php:77
Task\fetchTimeSpentOnTask
fetchTimeSpentOnTask($morewherefilter='')
Fetch records of time spent of this task.
Definition: task.class.php:1313
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
Task\addTimeSpent
addTimeSpent($user, $notrigger=0)
Add time spent.
Definition: task.class.php:1196
CommonObjectLine
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Definition: commonobjectline.class.php:32
Task\getNomUrl
getNomUrl($withpicto=0, $option='', $mode='task', $addlabel=0, $sep=' - ', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
Definition: task.class.php:712
CommonObject\isObjectUsed
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others.
Definition: commonobject.class.php:4556
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
WorkboardResponse
Definition: workboardresponse.class.php:25
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
Task\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: task.class.php:782
Task\create
create($user, $notrigger=0)
Create into database.
Definition: task.class.php:164
Task\hasDelay
hasDelay()
Is the task delayed?
Definition: task.class.php:2312
Task\load_board
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
Definition: task.class.php:2185
Task\__construct
__construct($db)
Constructor.
Definition: task.class.php:151
dol_copy
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:703
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6156
Task\getSumOfAmount
getSumOfAmount($fuser='', $dates='', $datee='')
Calculate quantity and value of time consumed using the thm (hourly amount value of work for user ent...
Definition: task.class.php:1473
CommonObject\delete_linked_contact
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
Definition: commonobject.class.php:1319
Task\getUserRolesForProjectsOrTasks
getUserRolesForProjectsOrTasks($userp, $usert, $projectid='', $taskid=0, $filteronprojstatus=-1)
Return list of roles for a user for each projects or each tasks (or a particular project or a particu...
Definition: task.class.php:1072
Task\getSummaryOfTimeSpent
getSummaryOfTimeSpent($userobj=null, $morewherefilter='')
Calculate total of time spent for task.
Definition: task.class.php:1405
Task\getTasksArray
getTasksArray($usert=null, $userp=null, $projectid=0, $socid=0, $mode=0, $filteronproj='', $filteronprojstatus='-1', $morewherefilter='', $filteronprojuser=0, $filterontaskuser=0, $extrafields=array(), $includebilltime=0, $search_array_options=array(), $loadextras=0, $loadRoleMode=1, $sortfield='', $sortorder='')
Return list of tasks for all projects or for one particular project Sort order is on project,...
Definition: task.class.php:820
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Task\$datee
$datee
Definition: task.class.php:91
Task\hasChildren
hasChildren()
Return nb of children.
Definition: task.class.php:638
CommonObject\fetch_optionals
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
Definition: commonobject.class.php:6007
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
Task\fetch
fetch($id, $ref='', $loadparentdata=0)
Load object in memory from database.
Definition: task.class.php:270
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Project\STATUS_VALIDATED
const STATUS_VALIDATED
Open/Validated status.
Definition: project.class.php:303
dol_html_entity_decode
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
Definition: functions.lib.php:7052
natural_search
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
Definition: functions.lib.php:9420
Task\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into PROJECT_TASK_ADDON_PDF.
Definition: task.class.php:2154
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
Task\LibStatut
LibStatut($status, $mode=0)
Return status label for an object.
Definition: task.class.php:2058
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
Task\hasTimeSpent
hasTimeSpent()
Return nb of time spent.
Definition: task.class.php:671
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
Task\getLibStatut
getLibStatut($mode=0)
Return status label of object.
Definition: task.class.php:2045
Task\load_state_board
load_state_board()
Charge indicateurs this->nb de tableau de bord.
Definition: task.class.php:2260
Task\delTimeSpent
delTimeSpent($user, $notrigger=0)
Delete time spent.
Definition: task.class.php:1772
Task\fetchTimeSpent
fetchTimeSpent($id)
Load properties of timespent of a task from the time spent ID.
Definition: task.class.php:1524