dolibarr  9.0.0
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28 
29 
33 class Task extends CommonObject
34 {
38  public $element='project_task';
39 
43  public $table_element='projet_task';
44 
48  public $fk_element='fk_task';
49 
50  public $picto = 'task';
51  protected $childtables=array('projet_task_time'); // To test if we can delete object
52 
56  public $fk_task_parent;
57 
61  public $label;
62 
66  public $description;
67 
68  public $duration_effective; // total of time spent on this task
69  public $planned_workload;
70  public $date_c;
71  public $date_start;
72  public $date_end;
73  public $progress;
74 
78  public $fk_statut;
79 
80  public $priority;
81 
85  public $fk_user_creat;
86 
90  public $fk_user_valid;
91 
92  public $rang;
93 
94  public $timespent_min_date;
95  public $timespent_max_date;
96  public $timespent_total_duration;
97  public $timespent_total_amount;
98  public $timespent_nblinesnull;
99  public $timespent_nblines;
100  // For detail of lines of timespent record, there is the property ->lines in common
101 
102  // Var used to call method addTimeSpent(). Bad practice.
103  public $timespent_id;
104  public $timespent_duration;
105  public $timespent_old_duration;
106  public $timespent_date;
107  public $timespent_datehour; // More accurate start date (same than timespent_date but includes hours, minutes and seconds)
108  public $timespent_withhour; // 1 = we entered also start hours for timesheet line
109  public $timespent_fk_user;
110  public $timespent_note;
111 
112  public $comments = array();
113 
114  public $oldcopy;
115 
116 
122  function __construct($db)
123  {
124  $this->db = $db;
125  }
126 
127 
135  function create($user, $notrigger=0)
136  {
137  global $conf, $langs;
138 
139  $error=0;
140 
141  // Clean parameters
142  $this->label = trim($this->label);
143  $this->description = trim($this->description);
144 
145  // Check parameters
146  // Put here code to add control on parameters values
147 
148  // Insert request
149  $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (";
150  $sql.= "fk_projet";
151  $sql.= ", ref";
152  $sql.= ", fk_task_parent";
153  $sql.= ", label";
154  $sql.= ", description";
155  $sql.= ", datec";
156  $sql.= ", fk_user_creat";
157  $sql.= ", dateo";
158  $sql.= ", datee";
159  $sql.= ", planned_workload";
160  $sql.= ", progress";
161  $sql.= ") VALUES (";
162  $sql.= $this->fk_project;
163  $sql.= ", ".(!empty($this->ref)?"'".$this->db->escape($this->ref)."'":'null');
164  $sql.= ", ".$this->fk_task_parent;
165  $sql.= ", '".$this->db->escape($this->label)."'";
166  $sql.= ", '".$this->db->escape($this->description)."'";
167  $sql.= ", '".$this->db->idate($this->date_c)."'";
168  $sql.= ", ".$user->id;
169  $sql.= ", ".($this->date_start!=''?"'".$this->db->idate($this->date_start)."'":'null');
170  $sql.= ", ".($this->date_end!=''?"'".$this->db->idate($this->date_end)."'":'null');
171  $sql.= ", ".(($this->planned_workload!='' && $this->planned_workload >= 0)?$this->planned_workload:'null');
172  $sql.= ", ".(($this->progress!='' && $this->progress >= 0)?$this->progress:'null');
173  $sql.= ")";
174 
175  $this->db->begin();
176 
177  dol_syslog(get_class($this)."::create", LOG_DEBUG);
178  $resql=$this->db->query($sql);
179  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
180 
181  if (! $error)
182  {
183  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
184 
185  if (! $notrigger)
186  {
187  // Call trigger
188  $result=$this->call_trigger('TASK_CREATE',$user);
189  if ($result < 0) { $error++; }
190  // End call triggers
191  }
192  }
193 
194  // Update extrafield
195  if (! $error)
196  {
197  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
198  {
199  $result=$this->insertExtraFields();
200  if ($result < 0)
201  {
202  $error++;
203  }
204  }
205  }
206 
207  // Commit or rollback
208  if ($error)
209  {
210  foreach($this->errors as $errmsg)
211  {
212  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
213  $this->error.=($this->error?', '.$errmsg:$errmsg);
214  }
215  $this->db->rollback();
216  return -1*$error;
217  }
218  else
219  {
220  $this->db->commit();
221  return $this->id;
222  }
223  }
224 
225 
234  function fetch($id, $ref='', $loadparentdata=0)
235  {
236  global $langs, $conf;
237 
238  $sql = "SELECT";
239  $sql.= " t.rowid,";
240  $sql.= " t.ref,";
241  $sql.= " t.fk_projet,";
242  $sql.= " t.fk_task_parent,";
243  $sql.= " t.label,";
244  $sql.= " t.description,";
245  $sql.= " t.duration_effective,";
246  $sql.= " t.planned_workload,";
247  $sql.= " t.datec,";
248  $sql.= " t.dateo,";
249  $sql.= " t.datee,";
250  $sql.= " t.fk_user_creat,";
251  $sql.= " t.fk_user_valid,";
252  $sql.= " t.fk_statut,";
253  $sql.= " t.progress,";
254  $sql.= " t.priority,";
255  $sql.= " t.note_private,";
256  $sql.= " t.note_public,";
257  $sql.= " t.rang";
258  if (! empty($loadparentdata))
259  {
260  $sql.=", t2.ref as task_parent_ref";
261  $sql.=", t2.rang as task_parent_position";
262  }
263  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as t";
264  if (! empty($loadparentdata)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t2 ON t.fk_task_parent = t2.rowid";
265  $sql.= " WHERE ";
266  if (!empty($ref)) {
267  $sql.="t.ref = '".$this->db->escape($ref)."'";
268  }else {
269  $sql.="t.rowid = ".$id;
270  }
271 
272  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
273  $resql=$this->db->query($sql);
274  if ($resql)
275  {
276  $num_rows = $this->db->num_rows($resql);
277 
278  if ($num_rows)
279  {
280  $obj = $this->db->fetch_object($resql);
281 
282  $this->id = $obj->rowid;
283  $this->ref = $obj->ref;
284  $this->fk_project = $obj->fk_projet;
285  $this->fk_task_parent = $obj->fk_task_parent;
286  $this->label = $obj->label;
287  $this->description = $obj->description;
288  $this->duration_effective = $obj->duration_effective;
289  $this->planned_workload = $obj->planned_workload;
290  $this->date_c = $this->db->jdate($obj->datec);
291  $this->date_start = $this->db->jdate($obj->dateo);
292  $this->date_end = $this->db->jdate($obj->datee);
293  $this->fk_user_creat = $obj->fk_user_creat;
294  $this->fk_user_valid = $obj->fk_user_valid;
295  $this->fk_statut = $obj->fk_statut;
296  $this->progress = $obj->progress;
297  $this->priority = $obj->priority;
298  $this->note_private = $obj->note_private;
299  $this->note_public = $obj->note_public;
300  $this->rang = $obj->rang;
301 
302  if (! empty($loadparentdata))
303  {
304  $this->task_parent_ref = $obj->task_parent_ref;
305  $this->task_parent_position = $obj->task_parent_position;
306  }
307 
308  // Retreive all extrafield
309  $this->fetch_optionals();
310  }
311 
312  $this->db->free($resql);
313 
314  if ($num_rows)
315  {
316  return 1;
317  }else {
318  return 0;
319  }
320  }
321  else
322  {
323  $this->error="Error ".$this->db->lasterror();
324  return -1;
325  }
326  }
327 
328 
336  function update($user=null, $notrigger=0)
337  {
338  global $conf, $langs;
339  $error=0;
340 
341  // Clean parameters
342  if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project);
343  if (isset($this->ref)) $this->ref=trim($this->ref);
344  if (isset($this->fk_task_parent)) $this->fk_task_parent = (int) $this->fk_task_parent;
345  if (isset($this->label)) $this->label=trim($this->label);
346  if (isset($this->description)) $this->description=trim($this->description);
347  if (isset($this->duration_effective)) $this->duration_effective=trim($this->duration_effective);
348  if (isset($this->planned_workload)) $this->planned_workload=trim($this->planned_workload);
349 
350  // Check parameters
351  // Put here code to add control on parameters values
352 
353  // Update request
354  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
355  $sql.= " fk_projet=".(isset($this->fk_project)?$this->fk_project:"null").",";
356  $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"'".$this->db->escape($this->id)."'").",";
357  $sql.= " fk_task_parent=".(isset($this->fk_task_parent)?$this->fk_task_parent:"null").",";
358  $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
359  $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
360  $sql.= " duration_effective=".(isset($this->duration_effective)?$this->duration_effective:"null").",";
361  $sql.= " planned_workload=".((isset($this->planned_workload) && $this->planned_workload != '')?$this->planned_workload:"null").",";
362  $sql.= " dateo=".($this->date_start!=''?"'".$this->db->idate($this->date_start)."'":'null').",";
363  $sql.= " datee=".($this->date_end!=''?"'".$this->db->idate($this->date_end)."'":'null').",";
364  $sql.= " progress=".(($this->progress!='' && $this->progress >= 0)?$this->progress:'null').",";
365  $sql.= " rang=".((!empty($this->rang))?$this->rang:"0");
366  $sql.= " WHERE rowid=".$this->id;
367 
368  $this->db->begin();
369 
370  dol_syslog(get_class($this)."::update", LOG_DEBUG);
371  $resql = $this->db->query($sql);
372  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
373 
374  // Update extrafield
375  if (! $error) {
376  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
377  {
378  $result=$this->insertExtraFields();
379  if ($result < 0)
380  {
381  $error++;
382  }
383  }
384  }
385 
386  if (! $error)
387  {
388  if (! $notrigger)
389  {
390  // Call trigger
391  $result=$this->call_trigger('TASK_MODIFY',$user);
392  if ($result < 0) { $error++; }
393  // End call triggers
394  }
395  }
396 
397  if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref))
398  {
399  // We remove directory
400  if ($conf->projet->dir_output)
401  {
402  $project = new Project($this->db);
403  $project->fetch($this->fk_project);
404 
405  $olddir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($this->oldcopy->ref);
406  $newdir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($this->ref);
407  if (file_exists($olddir))
408  {
409  include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
410  $res=dol_move($olddir, $newdir);
411  if (! $res)
412  {
413  $langs->load("errors");
414  $this->error=$langs->trans('ErrorFailToRenameDir',$olddir,$newdir);
415  $error++;
416  }
417  }
418  }
419  }
420 
421  // Commit or rollback
422  if ($error)
423  {
424  foreach($this->errors as $errmsg)
425  {
426  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
427  $this->error.=($this->error?', '.$errmsg:$errmsg);
428  }
429  $this->db->rollback();
430  return -1*$error;
431  }
432  else
433  {
434  $this->db->commit();
435  return 1;
436  }
437  }
438 
439 
447  function delete($user, $notrigger=0)
448  {
449 
450  global $conf, $langs;
451  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
452 
453  $error=0;
454 
455  $this->db->begin();
456 
457  if ($this->hasChildren() > 0)
458  {
459  dol_syslog(get_class($this)."::delete Can't delete record as it has some sub tasks", LOG_WARNING);
460  $this->error='ErrorRecordHasSubTasks';
461  $this->db->rollback();
462  return 0;
463  }
464 
465  $objectisused = $this->isObjectUsed($this->id);
466  if (! empty($objectisused))
467  {
468  dol_syslog(get_class($this)."::delete Can't delete record as it has some child", LOG_WARNING);
469  $this->error='ErrorRecordHasChildren';
470  $this->db->rollback();
471  return 0;
472  }
473 
474  if (! $error)
475  {
476  // Delete linked contacts
477  $res = $this->delete_linked_contact();
478  if ($res < 0)
479  {
480  $this->error='ErrorFailToDeleteLinkedContact';
481  //$error++;
482  $this->db->rollback();
483  return 0;
484  }
485  }
486 
487  if (! $error)
488  {
489  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time";
490  $sql.= " WHERE fk_task=".$this->id;
491 
492  $resql = $this->db->query($sql);
493  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
494  }
495 
496  if (! $error)
497  {
498  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_extrafields";
499  $sql.= " WHERE fk_object=".$this->id;
500 
501  $resql = $this->db->query($sql);
502  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
503  }
504 
505  if (! $error)
506  {
507  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task";
508  $sql.= " WHERE rowid=".$this->id;
509 
510  $resql = $this->db->query($sql);
511  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
512  }
513 
514  if (! $error)
515  {
516  if (! $notrigger)
517  {
518  // Call trigger
519  $result=$this->call_trigger('TASK_DELETE',$user);
520  if ($result < 0) { $error++; }
521  // End call triggers
522  }
523  }
524 
525  // Commit or rollback
526  if ($error)
527  {
528  foreach($this->errors as $errmsg)
529  {
530  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
531  $this->error.=($this->error?', '.$errmsg:$errmsg);
532  }
533  $this->db->rollback();
534  return -1*$error;
535  }
536  else
537  {
538  //Delete associated link file
539  if ($conf->projet->dir_output)
540  {
541  $projectstatic=new Project($this->db);
542  $projectstatic->fetch($this->fk_project);
543 
544  $dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($projectstatic->ref) . '/' . dol_sanitizeFileName($this->id);
545  dol_syslog(get_class($this)."::delete dir=".$dir, LOG_DEBUG);
546  if (file_exists($dir))
547  {
548  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
549  $res = @dol_delete_dir_recursive($dir);
550  if (!$res)
551  {
552  $this->error = 'ErrorFailToDeleteDir';
553  $this->db->rollback();
554  return 0;
555  }
556  }
557  }
558 
559  $this->db->commit();
560 
561  return 1;
562  }
563  }
564 
570  function hasChildren()
571  {
572  $error=0;
573  $ret=0;
574 
575  $sql = "SELECT COUNT(*) as nb";
576  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task";
577  $sql.= " WHERE fk_task_parent=".$this->id;
578 
579  dol_syslog(get_class($this)."::hasChildren", LOG_DEBUG);
580  $resql = $this->db->query($sql);
581  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
582  else
583  {
584  $obj=$this->db->fetch_object($resql);
585  if ($obj) $ret=$obj->nb;
586  $this->db->free($resql);
587  }
588 
589  if (! $error)
590  {
591  return $ret;
592  }
593  else
594  {
595  return -1;
596  }
597  }
598 
604  function hasTimeSpent()
605  {
606  $error=0;
607  $ret=0;
608 
609  $sql = "SELECT COUNT(*) as nb";
610  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time";
611  $sql.= " WHERE fk_task=".$this->id;
612 
613  dol_syslog(get_class($this)."::hasTimeSpent", LOG_DEBUG);
614  $resql = $this->db->query($sql);
615  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
616  else
617  {
618  $obj=$this->db->fetch_object($resql);
619  if ($obj) $ret=$obj->nb;
620  $this->db->free($resql);
621  }
622 
623  if (! $error)
624  {
625  return $ret;
626  }
627  else
628  {
629  return -1;
630  }
631  }
632 
633 
646  function getNomUrl($withpicto=0,$option='',$mode='task', $addlabel=0, $sep=' - ', $notooltip=0, $save_lastsearch_value=-1)
647  {
648  global $conf, $langs, $user;
649 
650  if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
651 
652  $result='';
653  $label = '<u>' . $langs->trans("ShowTask") . '</u>';
654  if (! empty($this->ref))
655  $label .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
656  if (! empty($this->label))
657  $label .= '<br><b>' . $langs->trans('LabelTask') . ':</b> ' . $this->label;
658  if ($this->date_start || $this->date_end)
659  {
660  $label .= "<br>".get_date_range($this->date_start,$this->date_end,'',$langs,0);
661  }
662 
663  $url = DOL_URL_ROOT.'/projet/tasks/'.$mode.'.php?id='.$this->id.($option=='withproject'?'&withproject=1':'');
664  // Add param to save lastsearch_values or not
665  $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
666  if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
667  if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
668 
669  $linkclose = '';
670  if (empty($notooltip))
671  {
672  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
673  {
674  $label=$langs->trans("ShowTask");
675  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
676  }
677  $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
678  $linkclose.=' class="classfortooltip"';
679  }
680 
681  $linkstart = '<a href="'.$url.'"';
682  $linkstart.=$linkclose.'>';
683  $linkend='</a>';
684 
685  $picto='projecttask';
686 
687  $result .= $linkstart;
688  if ($withpicto) $result.=img_object(($notooltip?'':$label), $picto, ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
689  if ($withpicto != 2) $result.= $this->ref;
690  $result .= $linkend;
691  if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
692 
693  return $result;
694  }
695 
703  function initAsSpecimen()
704  {
705  $this->id=0;
706 
707  $this->fk_projet='';
708  $this->ref='TK01';
709  $this->fk_task_parent=null;
710  $this->label='Specimen task TK01';
711  $this->duration_effective='';
712  $this->fk_user_creat=null;
713  $this->progress='25';
714  $this->fk_statut=null;
715  $this->note='This is a specimen task not';
716  }
717 
734  function getTasksArray($usert=null, $userp=null, $projectid=0, $socid=0, $mode=0, $filteronproj='', $filteronprojstatus='-1', $morewherefilter='',$filteronprojuser=0,$filterontaskuser=0)
735  {
736  global $conf;
737 
738  $tasks = array();
739 
740  //print $usert.'-'.$userp.'-'.$projectid.'-'.$socid.'-'.$mode.'<br>';
741 
742  // List of tasks (does not care about permissions. Filtering will be done later)
743  $sql = "SELECT ";
744  if ($filteronprojuser > 0 || $filterontaskuser > 0) $sql.= " DISTINCT"; // We may get several time the same record if user has several roles on same project/task
745  $sql.= " p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus,";
746  $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,";
747  $sql.= " t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang,";
748  $sql.= " s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email";
749  $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
750  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
751  if ($mode == 0)
752  {
753  if ($filteronprojuser > 0)
754  {
755  $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
756  $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
757  }
758  $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
759  if ($filterontaskuser > 0)
760  {
761  $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec2";
762  $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc2";
763  }
764  $sql.= " WHERE p.entity IN (".getEntity('project').")";
765  $sql.= " AND t.fk_projet = p.rowid";
766  }
767  elseif ($mode == 1)
768  {
769  if ($filteronprojuser > 0)
770  {
771  $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
772  $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
773  }
774  if ($filterontaskuser > 0)
775  {
776  $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
777  $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec2";
778  $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc2";
779  }
780  else
781  {
782  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t on t.fk_projet = p.rowid";
783  }
784  $sql.= " WHERE p.entity IN (".getEntity('project').")";
785  }
786  else return 'BadValueForParameterMode';
787 
788  if ($filteronprojuser > 0)
789  {
790  $sql.= " AND p.rowid = ec.element_id";
791  $sql.= " AND ctc.rowid = ec.fk_c_type_contact";
792  $sql.= " AND ctc.element = 'project'";
793  $sql.= " AND ec.fk_socpeople = ".$filteronprojuser;
794  $sql.= " AND ec.statut = 4";
795  $sql.= " AND ctc.source = 'internal'";
796  }
797  if ($filterontaskuser > 0)
798  {
799  $sql.= " AND t.fk_projet = p.rowid";
800  $sql.= " AND p.rowid = ec2.element_id";
801  $sql.= " AND ctc2.rowid = ec2.fk_c_type_contact";
802  $sql.= " AND ctc2.element = 'project_task'";
803  $sql.= " AND ec2.fk_socpeople = ".$filterontaskuser;
804  $sql.= " AND ec2.statut = 4";
805  $sql.= " AND ctc2.source = 'internal'";
806  }
807  if ($socid) $sql.= " AND p.fk_soc = ".$socid;
808  if ($projectid) $sql.= " AND p.rowid in (".$projectid.")";
809  if ($filteronproj) $sql.= natural_search(array("p.ref", "p.title"), $filteronproj);
810  if ($filteronprojstatus && $filteronprojstatus != '-1') $sql.= " AND p.fk_statut IN (".$filteronprojstatus.")";
811  if ($morewherefilter) $sql.=$morewherefilter;
812  $sql.= " ORDER BY p.ref, t.rang, t.dateo";
813 
814  //print $sql;exit;
815  dol_syslog(get_class($this)."::getTasksArray", LOG_DEBUG);
816  $resql = $this->db->query($sql);
817  if ($resql)
818  {
819  $num = $this->db->num_rows($resql);
820  $i = 0;
821  // Loop on each record found, so each couple (project id, task id)
822  while ($i < $num)
823  {
824  $error=0;
825 
826  $obj = $this->db->fetch_object($resql);
827 
828  if ((! $obj->public) && (is_object($userp))) // If not public project and we ask a filter on project owned by a user
829  {
830  if (! $this->getUserRolesForProjectsOrTasks($userp, 0, $obj->projectid, 0))
831  {
832  $error++;
833  }
834  }
835  if (is_object($usert)) // If we ask a filter on a user affected to a task
836  {
837  if (! $this->getUserRolesForProjectsOrTasks(0, $usert, $obj->projectid, $obj->taskid))
838  {
839  $error++;
840  }
841  }
842 
843  if (! $error)
844  {
845  $tasks[$i] = new Task($this->db);
846  $tasks[$i]->id = $obj->taskid;
847  $tasks[$i]->ref = $obj->taskref;
848  $tasks[$i]->fk_project = $obj->projectid;
849  $tasks[$i]->projectref = $obj->ref;
850  $tasks[$i]->projectlabel = $obj->plabel;
851  $tasks[$i]->projectstatus = $obj->projectstatus;
852  $tasks[$i]->label = $obj->label;
853  $tasks[$i]->description = $obj->description;
854  $tasks[$i]->fk_parent = $obj->fk_task_parent; // deprecated
855  $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
856  $tasks[$i]->duration = $obj->duration_effective;
857  $tasks[$i]->planned_workload= $obj->planned_workload;
858  $tasks[$i]->progress = $obj->progress;
859  $tasks[$i]->fk_statut = $obj->status;
860  $tasks[$i]->public = $obj->public;
861  $tasks[$i]->date_start = $this->db->jdate($obj->date_start);
862  $tasks[$i]->date_end = $this->db->jdate($obj->date_end);
863  $tasks[$i]->rang = $obj->rang;
864 
865  $tasks[$i]->socid = $obj->thirdparty_id; // For backward compatibility
866  $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
867  $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
868  $tasks[$i]->thirdparty_email= $obj->thirdparty_email;
869  }
870 
871  $i++;
872  }
873  $this->db->free($resql);
874  }
875  else
876  {
877  dol_print_error($this->db);
878  }
879 
880  return $tasks;
881  }
882 
893  function getUserRolesForProjectsOrTasks($userp, $usert, $projectid='', $taskid=0, $filteronprojstatus=-1)
894  {
895  $arrayroles = array();
896 
897  dol_syslog(get_class($this)."::getUserRolesForProjectsOrTasks userp=".is_object($userp)." usert=".is_object($usert)." projectid=".$projectid." taskid=".$taskid);
898 
899  // We want role of user for a projet or role of user for a task. Both are not possible.
900  if (empty($userp) && empty($usert))
901  {
902  $this->error="CallWithWrongParameters";
903  return -1;
904  }
905  if (! empty($userp) && ! empty($usert))
906  {
907  $this->error="CallWithWrongParameters";
908  return -1;
909  }
910 
911  /* Liste des taches et role sur les projets ou taches */
912  $sql = "SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
913  if ($userp) $sql.= " FROM ".MAIN_DB_PREFIX."projet as pt";
914  if ($usert && $filteronprojstatus > -1) $sql.= " FROM ".MAIN_DB_PREFIX."projet as p, ".MAIN_DB_PREFIX."projet_task as pt";
915  if ($usert && $filteronprojstatus <= -1) $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
916  $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
917  $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
918  $sql.= " WHERE pt.rowid = ec.element_id";
919  if ($userp && $filteronprojstatus > -1) $sql.= " AND pt.fk_statut = ".$filteronprojstatus;
920  if ($usert && $filteronprojstatus > -1) $sql.= " AND pt.fk_projet = p.rowid AND p.fk_statut = ".$filteronprojstatus;
921  if ($userp) $sql.= " AND ctc.element = 'project'";
922  if ($usert) $sql.= " AND ctc.element = 'project_task'";
923  $sql.= " AND ctc.rowid = ec.fk_c_type_contact";
924  if ($userp) $sql.= " AND ec.fk_socpeople = ".$userp->id;
925  if ($usert) $sql.= " AND ec.fk_socpeople = ".$usert->id;
926  $sql.= " AND ec.statut = 4";
927  $sql.= " AND ctc.source = 'internal'";
928  if ($projectid)
929  {
930  if ($userp) $sql.= " AND pt.rowid in (".$projectid.")";
931  if ($usert) $sql.= " AND pt.fk_projet in (".$projectid.")";
932  }
933  if ($taskid)
934  {
935  if ($userp) $sql.= " ERROR SHOULD NOT HAPPENS";
936  if ($usert) $sql.= " AND pt.rowid = ".$taskid;
937  }
938  //print $sql;
939 
940  dol_syslog(get_class($this)."::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
941  $resql = $this->db->query($sql);
942  if ($resql)
943  {
944  $num = $this->db->num_rows($resql);
945  $i = 0;
946  while ($i < $num)
947  {
948  $obj = $this->db->fetch_object($resql);
949  if (empty($arrayroles[$obj->pid])) $arrayroles[$obj->pid] = $obj->code;
950  else $arrayroles[$obj->pid].=','.$obj->code;
951  $i++;
952  }
953  $this->db->free($resql);
954  }
955  else
956  {
957  dol_print_error($this->db);
958  }
959 
960  return $arrayroles;
961  }
962 
963 
970  function getListContactId($source='internal')
971  {
972  $contactAlreadySelected = array();
973  $tab = $this->liste_contact(-1,$source);
974  //var_dump($tab);
975  $num=count($tab);
976  $i = 0;
977  while ($i < $num)
978  {
979  if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
980  else $contactAlreadySelected[$i] = $tab[$i]['id'];
981  $i++;
982  }
983  return $contactAlreadySelected;
984  }
985 
986 
994  function addTimeSpent($user, $notrigger=0)
995  {
996  global $conf,$langs;
997 
998  dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
999 
1000  $ret = 0;
1001 
1002  // Check parameters
1003  if (! is_object($user))
1004  {
1005  dol_print_error('',"Method addTimeSpent was called with wrong parameter user");
1006  return -1;
1007  }
1008 
1009  // Clean parameters
1010  if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
1011  if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date;
1012 
1013  $this->db->begin();
1014 
1015  $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (";
1016  $sql.= "fk_task";
1017  $sql.= ", task_date";
1018  $sql.= ", task_datehour";
1019  $sql.= ", task_date_withhour";
1020  $sql.= ", task_duration";
1021  $sql.= ", fk_user";
1022  $sql.= ", note";
1023  $sql.= ") VALUES (";
1024  $sql.= $this->id;
1025  $sql.= ", '".$this->db->idate($this->timespent_date)."'";
1026  $sql.= ", '".$this->db->idate($this->timespent_datehour)."'";
1027  $sql.= ", ".(empty($this->timespent_withhour)?0:1);
1028  $sql.= ", ".$this->timespent_duration;
1029  $sql.= ", ".$this->timespent_fk_user;
1030  $sql.= ", ".(isset($this->timespent_note)?"'".$this->db->escape($this->timespent_note)."'":"null");
1031  $sql.= ")";
1032 
1033  $resql=$this->db->query($sql);
1034  if ($resql)
1035  {
1036  $tasktime_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time");
1037  $ret = $tasktime_id;
1038  $this->timespent_id = $ret;
1039 
1040  if (! $notrigger)
1041  {
1042  // Call trigger
1043  $result=$this->call_trigger('TASK_TIMESPENT_CREATE',$user);
1044  if ($result < 0) { $ret=-1; }
1045  // End call triggers
1046  }
1047  }
1048  else
1049  {
1050  $this->error=$this->db->lasterror();
1051  $ret = -1;
1052  }
1053 
1054  if ($ret > 0)
1055  {
1056  // Recalculate amount of time spent for task and update denormalized field
1057  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
1058  $sql.= " SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX."projet_task_time as ptt where ptt.fk_task = ".$this->id.")";
1059  if (isset($this->progress)) $sql.= ", progress = " . $this->progress; // Do not overwrite value if not provided
1060  $sql.= " WHERE rowid = ".$this->id;
1061 
1062  dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
1063  if (! $this->db->query($sql) )
1064  {
1065  $this->error=$this->db->lasterror();
1066  $ret = -2;
1067  }
1068 
1069  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time";
1070  $sql.= " SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".$this->timespent_fk_user.")"; // set average hour rate of user
1071  $sql.= " WHERE rowid = ".$tasktime_id;
1072 
1073  dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
1074  if (! $this->db->query($sql) )
1075  {
1076  $this->error=$this->db->lasterror();
1077  $ret = -2;
1078  }
1079  }
1080 
1081  if ($ret >0)
1082  {
1083  $this->db->commit();
1084  }
1085  else
1086  {
1087  $this->db->rollback();
1088  }
1089  return $ret;
1090  }
1091 
1099  function getSummaryOfTimeSpent($userobj=null, $morewherefilter='')
1100  {
1101  global $langs;
1102 
1103  if (is_object($userobj)) $userid=$userobj->id;
1104  else $userid=$userobj; // old method
1105 
1106  $id=$this->id;
1107  if (empty($id) && empty($userid))
1108  {
1109  dol_syslog("getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1110  return -1;
1111  }
1112 
1113  $result=array();
1114 
1115  $sql = "SELECT";
1116  $sql.= " MIN(t.task_datehour) as min_date,";
1117  $sql.= " MAX(t.task_datehour) as max_date,";
1118  $sql.= " SUM(t.task_duration) as total_duration,";
1119  $sql.= " SUM(t.task_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as total_amount,";
1120  $sql.= " COUNT(t.rowid) as nblines,";
1121  $sql.= " SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull";
1122  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
1123  $sql.= " WHERE 1 = 1";
1124  if ($morewherefilter) $sql.=$morewherefilter;
1125  if ($id > 0) $sql.= " AND t.fk_task = ".$id;
1126  if ($userid > 0) $sql.=" AND t.fk_user = ".$userid;
1127 
1128  dol_syslog(get_class($this)."::getSummaryOfTimeSpent", LOG_DEBUG);
1129  $resql=$this->db->query($sql);
1130  if ($resql)
1131  {
1132  $obj = $this->db->fetch_object($resql);
1133 
1134  $result['min_date'] = $obj->min_date; // deprecated. use the ->timespent_xxx instead
1135  $result['max_date'] = $obj->max_date; // deprecated. use the ->timespent_xxx instead
1136  $result['total_duration'] = $obj->total_duration; // deprecated. use the ->timespent_xxx instead
1137 
1138  $this->timespent_min_date=$this->db->jdate($obj->min_date);
1139  $this->timespent_max_date=$this->db->jdate($obj->max_date);
1140  $this->timespent_total_duration=$obj->total_duration;
1141  $this->timespent_total_amount=$obj->total_amount;
1142  $this->timespent_nblinesnull=($obj->nblinesnull?$obj->nblinesnull:0);
1143  $this->timespent_nblines=($obj->nblines?$obj->nblines:0);
1144 
1145  $this->db->free($resql);
1146  }
1147  else
1148  {
1149  dol_print_error($this->db);
1150  }
1151  return $result;
1152  }
1153 
1162  function getSumOfAmount($fuser='', $dates='', $datee='')
1163  {
1164  global $langs;
1165 
1166  if (empty($id)) $id=$this->id;
1167 
1168  $result=array();
1169 
1170  $sql = "SELECT";
1171  $sql.= " SUM(t.task_duration) as nbseconds,";
1172  $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";
1173  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
1174  $sql.= " WHERE t.fk_task = ".$id;
1175  if (is_object($fuser) && $fuser->id > 0)
1176  {
1177  $sql.=" AND fk_user = ".$fuser->id;
1178  }
1179  if ($dates > 0)
1180  {
1181  $datefieldname="task_datehour";
1182  $sql.=" AND (".$datefieldname." >= '".$this->db->idate($dates)."' OR ".$datefieldname." IS NULL)";
1183  }
1184  if ($datee > 0)
1185  {
1186  $datefieldname="task_datehour";
1187  $sql.=" AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)";
1188  }
1189  //print $sql;
1190 
1191  dol_syslog(get_class($this)."::getSumOfAmount", LOG_DEBUG);
1192  $resql=$this->db->query($sql);
1193  if ($resql)
1194  {
1195  $obj = $this->db->fetch_object($resql);
1196 
1197  $result['amount'] = $obj->amount;
1198  $result['nbseconds'] = $obj->nbseconds;
1199  $result['nblinesnull'] = $obj->nblinesnull;
1200 
1201  $this->db->free($resql);
1202  return $result;
1203  }
1204  else
1205  {
1206  dol_print_error($this->db);
1207  return $result;
1208  }
1209  }
1210 
1217  function fetchTimeSpent($id)
1218  {
1219  global $langs;
1220 
1221  $sql = "SELECT";
1222  $sql.= " t.rowid,";
1223  $sql.= " t.fk_task,";
1224  $sql.= " t.task_date,";
1225  $sql.= " t.task_datehour,";
1226  $sql.= " t.task_date_withhour,";
1227  $sql.= " t.task_duration,";
1228  $sql.= " t.fk_user,";
1229  $sql.= " t.note";
1230  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
1231  $sql.= " WHERE t.rowid = ".$id;
1232 
1233  dol_syslog(get_class($this)."::fetchTimeSpent", LOG_DEBUG);
1234  $resql=$this->db->query($sql);
1235  if ($resql)
1236  {
1237  if ($this->db->num_rows($resql))
1238  {
1239  $obj = $this->db->fetch_object($resql);
1240 
1241  $this->timespent_id = $obj->rowid;
1242  $this->id = $obj->fk_task;
1243  $this->timespent_date = $this->db->jdate($obj->task_date);
1244  $this->timespent_datehour = $this->db->jdate($obj->task_datehour);
1245  $this->timespent_withhour = $obj->task_date_withhour;
1246  $this->timespent_duration = $obj->task_duration;
1247  $this->timespent_fk_user = $obj->fk_user;
1248  $this->timespent_note = $obj->note;
1249  }
1250 
1251  $this->db->free($resql);
1252 
1253  return 1;
1254  }
1255  else
1256  {
1257  $this->error="Error ".$this->db->lasterror();
1258  return -1;
1259  }
1260  }
1261 
1269  function fetchAllTimeSpent(User $userobj, $morewherefilter='')
1270  {
1271  global $langs;
1272 
1273  $arrayres=array();
1274 
1275  $sql = "SELECT";
1276  $sql.= " s.rowid as socid,";
1277  $sql.= " s.nom as thirdparty_name,";
1278  $sql.= " s.email as thirdparty_email,";
1279  $sql.= " ptt.rowid,";
1280  $sql.= " ptt.fk_task,";
1281  $sql.= " ptt.task_date,";
1282  $sql.= " ptt.task_datehour,";
1283  $sql.= " ptt.task_date_withhour,";
1284  $sql.= " ptt.task_duration,";
1285  $sql.= " ptt.fk_user,";
1286  $sql.= " ptt.note,";
1287  $sql.= " pt.rowid as task_id,";
1288  $sql.= " pt.ref as task_ref,";
1289  $sql.= " pt.label as task_label,";
1290  $sql.= " p.rowid as project_id,";
1291  $sql.= " p.ref as project_ref,";
1292  $sql.= " p.title as project_label,";
1293  $sql.= " p.public as public";
1294  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as ptt, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet as p";
1295  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
1296  $sql.= " WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1297  $sql.= " AND ptt.fk_user = ".$userobj->id;
1298  $sql.= " AND pt.entity IN (".getEntity('project').")";
1299  if ($morewherefilter) $sql.=$morewherefilter;
1300 
1301  dol_syslog(get_class($this)."::fetchAllTimeSpent", LOG_DEBUG);
1302  $resql=$this->db->query($sql);
1303  if ($resql)
1304  {
1305  $num = $this->db->num_rows($resql);
1306 
1307  $i=0;
1308  while ($i < $num)
1309  {
1310  $obj = $this->db->fetch_object($resql);
1311 
1312  $newobj = new stdClass();
1313 
1314  $newobj->socid = $obj->socid;
1315  $newobj->thirdparty_name = $obj->thirdparty_name;
1316  $newobj->thirdparty_email = $obj->thirdparty_email;
1317 
1318  $newobj->fk_project = $obj->project_id;
1319  $newobj->project_ref = $obj->project_ref;
1320  $newobj->project_label = $obj->project_label;
1321  $newobj->public = $obj->project_public;
1322 
1323  $newobj->fk_task = $obj->task_id;
1324  $newobj->task_ref = $obj->task_ref;
1325  $newobj->task_label = $obj->task_label;
1326 
1327  $newobj->timespent_id = $obj->rowid;
1328  $newobj->timespent_date = $this->db->jdate($obj->task_date);
1329  $newobj->timespent_datehour = $this->db->jdate($obj->task_datehour);
1330  $newobj->timespent_withhour = $obj->task_date_withhour;
1331  $newobj->timespent_duration = $obj->task_duration;
1332  $newobj->timespent_fk_user = $obj->fk_user;
1333  $newobj->timespent_note = $obj->note;
1334 
1335  $arrayres[] = $newobj;
1336 
1337  $i++;
1338  }
1339 
1340  $this->db->free($resql);
1341  }
1342  else
1343  {
1344  dol_print_error($this->db);
1345  $this->error="Error ".$this->db->lasterror();
1346  return -1;
1347  }
1348 
1349  return $arrayres;
1350  }
1351 
1359  function updateTimeSpent($user, $notrigger=0)
1360  {
1361  global $conf,$langs;
1362 
1363  $ret = 0;
1364 
1365  // Check parameters
1366  if ($this->timespent_date == '')
1367  {
1368  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Date"));
1369  return -1;
1370  }
1371  if (! ($this->timespent_fk_user > 0))
1372  {
1373  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("User"));
1374  return -1;
1375  }
1376 
1377  // Clean parameters
1378  if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date;
1379  if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
1380 
1381  $this->db->begin();
1382 
1383  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET";
1384  $sql.= " task_date = '".$this->db->idate($this->timespent_date)."',";
1385  $sql.= " task_datehour = '".$this->db->idate($this->timespent_datehour)."',";
1386  $sql.= " task_date_withhour = ".(empty($this->timespent_withhour)?0:1).",";
1387  $sql.= " task_duration = ".$this->timespent_duration.",";
1388  $sql.= " fk_user = ".$this->timespent_fk_user.",";
1389  $sql.= " note = ".(isset($this->timespent_note)?"'".$this->db->escape($this->timespent_note)."'":"null");
1390  $sql.= " WHERE rowid = ".$this->timespent_id;
1391 
1392  dol_syslog(get_class($this)."::updateTimeSpent", LOG_DEBUG);
1393  if ($this->db->query($sql) )
1394  {
1395  if (! $notrigger)
1396  {
1397  // Call trigger
1398  $result=$this->call_trigger('TASK_TIMESPENT_MODIFY',$user);
1399  if ($result < 0)
1400  {
1401  $this->db->rollback();
1402  $ret = -1;
1403  }
1404  else $ret = 1;
1405  // End call triggers
1406  }
1407  else $ret = 1;
1408  }
1409  else
1410  {
1411  $this->error=$this->db->lasterror();
1412  $this->db->rollback();
1413  $ret = -1;
1414  }
1415 
1416  if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration))
1417  {
1418  $newDuration = $this->timespent_duration - $this->timespent_old_duration;
1419 
1420  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
1421  $sql.= " SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX."projet_task_time as ptt where ptt.fk_task = ".$this->db->escape($this->id).")";
1422  $sql.= " WHERE rowid = ".$this->id;
1423 
1424  dol_syslog(get_class($this)."::updateTimeSpent", LOG_DEBUG);
1425  if (! $this->db->query($sql) )
1426  {
1427  $this->error=$this->db->lasterror();
1428  $this->db->rollback();
1429  $ret = -2;
1430  }
1431  }
1432 
1433  if ($ret >= 0) $this->db->commit();
1434  return $ret;
1435  }
1436 
1444  function delTimeSpent($user, $notrigger=0)
1445  {
1446  global $conf, $langs;
1447 
1448  $error=0;
1449 
1450  $this->db->begin();
1451 
1452  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time";
1453  $sql.= " WHERE rowid = ".$this->timespent_id;
1454 
1455  dol_syslog(get_class($this)."::delTimeSpent", LOG_DEBUG);
1456  $resql = $this->db->query($sql);
1457  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
1458 
1459  if (! $error)
1460  {
1461  if (! $notrigger)
1462  {
1463  // Call trigger
1464  $result=$this->call_trigger('TASK_TIMESPENT_DELETE',$user);
1465  if ($result < 0) { $error++; }
1466  // End call triggers
1467  }
1468  }
1469 
1470  if (! $error)
1471  {
1472  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
1473  $sql.= " SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration?$this->timespent_duration:0);
1474  $sql.= " WHERE rowid = ".$this->id;
1475 
1476  dol_syslog(get_class($this)."::delTimeSpent", LOG_DEBUG);
1477  if ($this->db->query($sql) )
1478  {
1479  $result = 0;
1480  }
1481  else
1482  {
1483  $this->error=$this->db->lasterror();
1484  $result = -2;
1485  }
1486  }
1487 
1488  // Commit or rollback
1489  if ($error)
1490  {
1491  foreach($this->errors as $errmsg)
1492  {
1493  dol_syslog(get_class($this)."::delTimeSpent ".$errmsg, LOG_ERR);
1494  $this->error.=($this->error?', '.$errmsg:$errmsg);
1495  }
1496  $this->db->rollback();
1497  return -1*$error;
1498  }
1499  else
1500  {
1501  $this->db->commit();
1502  return 1;
1503  }
1504  }
1505 
1519  function createFromClone($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)
1520  {
1521  global $user,$langs,$conf;
1522 
1523  $error=0;
1524 
1525  //Use 00:00 of today if time is use on task.
1526  $now=dol_mktime(0,0,0,dol_print_date(dol_now(),'%m'),dol_print_date(dol_now(),'%d'),dol_print_date(dol_now(),'%Y'));
1527 
1528  $datec = $now;
1529 
1530  $clone_task=new Task($this->db);
1531  $origin_task=new Task($this->db);
1532 
1533  $clone_task->context['createfromclone']='createfromclone';
1534 
1535  $this->db->begin();
1536 
1537  // Load source object
1538  $clone_task->fetch($fromid);
1539  $clone_task->fetch_optionals();
1540  //var_dump($clone_task->array_options);exit;
1541 
1542  $origin_task->fetch($fromid);
1543 
1544  $defaultref='';
1545  $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
1546  if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
1547  {
1548  require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
1549  $modTask = new $obj;
1550  $defaultref = $modTask->getNextValue(0,$clone_task);
1551  }
1552 
1553  $ori_project_id = $clone_task->fk_project;
1554 
1555  $clone_task->id = 0;
1556  $clone_task->ref = $defaultref;
1557  $clone_task->fk_project = $project_id;
1558  $clone_task->fk_task_parent = $parent_task_id;
1559  $clone_task->date_c = $datec;
1560  $clone_task->planned_workload = $origin_task->planned_workload;
1561  $clone_task->rang = $origin_task->rang;
1562 
1563  //Manage Task Date
1564  if ($clone_change_dt)
1565  {
1566  $projectstatic=new Project($this->db);
1567  $projectstatic->fetch($ori_project_id);
1568 
1569  //Origin project strat date
1570  $orign_project_dt_start = $projectstatic->date_start;
1571 
1572  //Calcultate new task start date with difference between origin proj start date and origin task start date
1573  if (!empty($clone_task->date_start))
1574  {
1575  $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
1576  }
1577 
1578  //Calcultate new task end date with difference between origin proj end date and origin task end date
1579  if (!empty($clone_task->date_end))
1580  {
1581  $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
1582  }
1583  }
1584 
1585  if (!$clone_prog)
1586  {
1587  $clone_task->progress=0;
1588  }
1589 
1590  // Create clone
1591  $result=$clone_task->create($user);
1592 
1593  // Other options
1594  if ($result < 0)
1595  {
1596  $this->error=$clone_task->error;
1597  $error++;
1598  }
1599 
1600  // End
1601  if (! $error)
1602  {
1603  $clone_task_id=$clone_task->id;
1604  $clone_task_ref = $clone_task->ref;
1605 
1606  //Note Update
1607  if (!$clone_note)
1608  {
1609  $clone_task->note_private='';
1610  $clone_task->note_public='';
1611  }
1612  else
1613  {
1614  $this->db->begin();
1615  $res=$clone_task->update_note(dol_html_entity_decode($clone_task->note_public, ENT_QUOTES),'_public');
1616  if ($res < 0)
1617  {
1618  $this->error.=$clone_task->error;
1619  $error++;
1620  $this->db->rollback();
1621  }
1622  else
1623  {
1624  $this->db->commit();
1625  }
1626 
1627  $this->db->begin();
1628  $res=$clone_task->update_note(dol_html_entity_decode($clone_task->note_private, ENT_QUOTES), '_private');
1629  if ($res < 0)
1630  {
1631  $this->error.=$clone_task->error;
1632  $error++;
1633  $this->db->rollback();
1634  }
1635  else
1636  {
1637  $this->db->commit();
1638  }
1639  }
1640 
1641  //Duplicate file
1642  if ($clone_file)
1643  {
1644  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1645 
1646  //retreive project origin ref to know folder to copy
1647  $projectstatic=new Project($this->db);
1648  $projectstatic->fetch($ori_project_id);
1649  $ori_project_ref=$projectstatic->ref;
1650 
1651  if ($ori_project_id!=$project_id)
1652  {
1653  $projectstatic->fetch($project_id);
1654  $clone_project_ref=$projectstatic->ref;
1655  }
1656  else
1657  {
1658  $clone_project_ref=$ori_project_ref;
1659  }
1660 
1661  $clone_task_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($clone_project_ref). "/" . dol_sanitizeFileName($clone_task_ref);
1662  $ori_task_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($ori_project_ref). "/" . dol_sanitizeFileName($fromid);
1663 
1664  $filearray=dol_dir_list($ori_task_dir,"files",0,'','(\.meta|_preview.*\.png)$','',SORT_ASC,1);
1665  foreach($filearray as $key => $file)
1666  {
1667  if (!file_exists($clone_task_dir))
1668  {
1669  if (dol_mkdir($clone_task_dir) < 0)
1670  {
1671  $this->error.=$langs->trans('ErrorInternalErrorDetected').':dol_mkdir';
1672  $error++;
1673  }
1674  }
1675 
1676  $rescopy = dol_copy($ori_task_dir . '/' . $file['name'], $clone_task_dir . '/' . $file['name'],0,1);
1677  if (is_numeric($rescopy) && $rescopy < 0)
1678  {
1679  $this->error.=$langs->trans("ErrorFailToCopyFile",$ori_task_dir . '/' . $file['name'],$clone_task_dir . '/' . $file['name']);
1680  $error++;
1681  }
1682  }
1683  }
1684 
1685  // clone affectation
1686  if ($clone_affectation)
1687  {
1688  $origin_task = new Task($this->db);
1689  $origin_task->fetch($fromid);
1690 
1691  foreach(array('internal','external') as $source)
1692  {
1693  $tab = $origin_task->liste_contact(-1,$source);
1694  $num=count($tab);
1695  $i = 0;
1696  while ($i < $num)
1697  {
1698  $clone_task->add_contact($tab[$i]['id'], $tab[$i]['code'], $tab[$i]['source']);
1699  if ($clone_task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1700  {
1701  $langs->load("errors");
1702  $this->error.=$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
1703  $error++;
1704  }
1705  else
1706  {
1707  if ($clone_task->error!='')
1708  {
1709  $this->error.=$clone_task->error;
1710  $error++;
1711  }
1712  }
1713  $i++;
1714  }
1715  }
1716  }
1717 
1718  if($clone_time)
1719  {
1720  //TODO clone time of affectation
1721  }
1722  }
1723 
1724  unset($clone_task->context['createfromclone']);
1725 
1726  if (! $error)
1727  {
1728  $this->db->commit();
1729  return $clone_task_id;
1730  }
1731  else
1732  {
1733  $this->db->rollback();
1734  dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
1735  return -1;
1736  }
1737  }
1738 
1739 
1746  function getLibStatut($mode=0)
1747  {
1748  return $this->LibStatut($this->fk_statut, $mode);
1749  }
1750 
1751  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1759  function LibStatut($statut, $mode=0)
1760  {
1761  // phpcs:enable
1762  // list of Statut of the task
1763  $this->statuts[0]='Draft';
1764  $this->statuts[1]='ToDo';
1765  $this->statuts[2]='Running';
1766  $this->statuts[3]='Finish';
1767  $this->statuts[4]='Transfered';
1768  $this->statuts_short[0]='Draft';
1769  $this->statuts_short[1]='ToDo';
1770  $this->statuts_short[2]='Running';
1771  $this->statuts_short[3]='Completed';
1772  $this->statuts_short[4]='Transfered';
1773 
1774  global $langs;
1775 
1776  if ($mode == 0)
1777  {
1778  return $langs->trans($this->statuts[$statut]);
1779  }
1780  elseif ($mode == 1)
1781  {
1782  return $langs->trans($this->statuts_short[$statut]);
1783  }
1784  elseif ($mode == 2)
1785  {
1786  if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]);
1787  elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut1').' '.$langs->trans($this->statuts_short[$statut]);
1788  elseif ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut3').' '.$langs->trans($this->statuts_short[$statut]);
1789  elseif ($statut==3) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]);
1790  elseif ($statut==4) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]);
1791  elseif ($statut==5) return img_picto($langs->trans($this->statuts_short[$statut]),'statut5').' '.$langs->trans($this->statuts_short[$statut]);
1792  }
1793  elseif ($mode == 3)
1794  {
1795  if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
1796  elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut1');
1797  elseif ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut3');
1798  elseif ($statut==3) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
1799  elseif ($statut==4) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
1800  elseif ($statut==5) return img_picto($langs->trans($this->statuts_short[$statut]),'statut5');
1801  }
1802  elseif ($mode == 4)
1803  {
1804  if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1805  elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
1806  elseif ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
1807  elseif ($statut==3) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
1808  elseif ($statut==4) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
1809  elseif ($statut==5) return img_picto($langs->trans($this->statuts_short[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]);
1810  }
1811  elseif ($mode == 5)
1812  {
1813  /*if ($statut==0) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
1814  elseif ($statut==1) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut1');
1815  elseif ($statut==2) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut3');
1816  elseif ($statut==3) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
1817  elseif ($statut==4) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
1818  elseif ($statut==5) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut5');
1819  */
1820  //else return $this->progress.' %';
1821  return '&nbsp;';
1822  }
1823  elseif ($mode == 6)
1824  {
1825  /*if ($statut==0) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
1826  elseif ($statut==1) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut1');
1827  elseif ($statut==2) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut3');
1828  elseif ($statut==3) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
1829  elseif ($statut==4) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
1830  elseif ($statut==5) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut5');
1831  */
1832  //else return $this->progress.' %';
1833  return '&nbsp;';
1834  }
1835  }
1836 
1847  public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
1848  {
1849  global $conf,$langs;
1850 
1851  $langs->load("projects");
1852 
1853  if (! dol_strlen($modele)) {
1854 
1855  $modele = 'nodefault';
1856 
1857  if ($this->modelpdf) {
1858  $modele = $this->modelpdf;
1859  } elseif (! empty($conf->global->PROJECT_TASK_ADDON_PDF)) {
1860  $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
1861  }
1862  }
1863 
1864  $modelpath = "core/modules/project/task/doc/";
1865 
1866  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1867  }
1868 
1869 
1870  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1877  function load_board($user)
1878  {
1879  // phpcs:enable
1880  global $conf, $langs;
1881 
1882  // For external user, no check is done on company because readability is managed by public status of project and assignement.
1883  //$socid=$user->societe_id;
1884 
1885  $projectstatic = new Project($this->db);
1886  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
1887 
1888  // List of tasks (does not care about permissions. Filtering will be done later)
1889  $sql = "SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
1890  $sql.= " t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
1891  $sql.= " t.dateo as date_start, t.datee as datee";
1892  $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
1893  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
1894  //if (! $user->rights->societe->client->voir && ! $socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
1895  $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
1896  $sql.= " WHERE p.entity IN (".getEntity('project', 0).')';
1897  $sql.= " AND p.fk_statut = 1";
1898  $sql.= " AND t.fk_projet = p.rowid";
1899  $sql.= " AND t.progress < 100"; // tasks to do
1900  if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";
1901  // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
1902  //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1903  if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1904  // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
1905  // if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
1906 
1907  //print $sql;
1908  $resql=$this->db->query($sql);
1909  if ($resql)
1910  {
1911  $task_static = new Task($this->db);
1912 
1913  $response = new WorkboardResponse();
1914  $response->warning_delay = $conf->projet->task->warning_delay/60/60/24;
1915  $response->label = $langs->trans("OpenedTasks");
1916  if ($user->rights->projet->all->lire) $response->url = DOL_URL_ROOT.'/projet/tasks/list.php?mainmenu=project';
1917  else $response->url = DOL_URL_ROOT.'/projet/tasks/list.php?mode=mine&amp;mainmenu=project';
1918  $response->img = img_object('',"task");
1919 
1920  // This assignment in condition is not a bug. It allows walking the results.
1921  while ($obj=$this->db->fetch_object($resql))
1922  {
1923  $response->nbtodo++;
1924 
1925  $task_static->projectstatus = $obj->projectstatus;
1926  $task_static->progress = $obj->progress;
1927  $task_static->fk_statut = $obj->status;
1928  $task_static->date_end = $this->db->jdate($obj->datee);
1929 
1930  if ($task_static->hasDelay()) {
1931  $response->nbtodolate++;
1932  }
1933  }
1934 
1935  return $response;
1936  }
1937  else
1938  {
1939  $this->error=$this->db->error();
1940  return -1;
1941  }
1942  }
1943 
1944 
1945  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1951  function load_state_board()
1952  {
1953  // phpcs:enable
1954  global $user;
1955 
1956  $mine=0; $socid=$user->societe_id;
1957 
1958  $projectstatic = new Project($this->db);
1959  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1,$socid);
1960 
1961  // List of tasks (does not care about permissions. Filtering will be done later)
1962  $sql = "SELECT count(p.rowid) as nb";
1963  $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
1964  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
1965  if (! $user->rights->societe->client->voir && ! $socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
1966  $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
1967  $sql.= " WHERE p.entity IN (".getEntity('project', 0).')';
1968  $sql.= " AND t.fk_projet = p.rowid"; // tasks to do
1969  if ($mine || ! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";
1970  // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
1971  //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1972  if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1973  if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
1974 
1975  $resql=$this->db->query($sql);
1976  if ($resql)
1977  {
1978 
1979  // This assignment in condition is not a bug. It allows walking the results.
1980  while ($obj=$this->db->fetch_object($resql))
1981  {
1982  $this->nb["tasks"]=$obj->nb;
1983  }
1984  $this->db->free($resql);
1985  return 1;
1986  }
1987  else
1988  {
1989  dol_print_error($this->db);
1990  $this->error=$this->db->error();
1991  return -1;
1992  }
1993  }
1994 
2000  public function hasDelay()
2001  {
2002  global $conf;
2003 
2004  if (! ($this->progress >= 0 && $this->progress < 100)) {
2005  return false;
2006  }
2007 
2008  $now = dol_now();
2009 
2010  $datetouse = ($this->date_end > 0) ? $this->date_end : ($this->datee > 0 ? $this->datee : 0);
2011 
2012  return ($datetouse > 0 && ($datetouse < ($now - $conf->projet->task->warning_delay)));
2013  }
2014 }
fetchAllTimeSpent(User $userobj, $morewherefilter='')
Load all records of time spent.
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
hasTimeSpent()
Return nb of time spent.
Definition: task.class.php:604
fetchTimeSpent($id)
Load one record of time spent.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:666
LibStatut($statut, $mode=0)
Return status label for an object.
getLibStatut($mode=0)
Return status label of object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
update($user=null, $notrigger=0)
Update database.
Definition: task.class.php:336
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
isObjectUsed($id=0)
Function to check if an object is used by others.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
updateTimeSpent($user, $notrigger=0)
Update time spent.
if(! empty($search_group)) natural_search(array("g.nom" g note
Definition: list.php:123
Class to manage Dolibarr users.
Definition: user.class.php:41
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getListContactId($source='internal')
Return list of id of contacts of task.
Definition: task.class.php:970
create($user, $notrigger=0)
Create into database.
Definition: task.class.php:135
addTimeSpent($user, $notrigger=0)
Add time spent.
Definition: task.class.php:994
createFromClone($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.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
Definition: files.lib.php:814
initAsSpecimen()
Initialise an instance with random values.
Definition: task.class.php:703
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:646
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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:893
Class to manage projects.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts.
hasDelay()
Is the task delayed?
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
hasChildren()
Return nb of children.
Definition: task.class.php:570
getSumOfAmount($fuser='', $dates='', $datee='')
Calculate quantity and value of time consumed using the thm (hourly amount value of work for user ent...
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
Definition: files.lib.php:1273
__construct($db)
Constructor.
Definition: task.class.php:122
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into PROJECT_TASK_ADDON_PDF.
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...
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:59
liste_contact($statut=-1, $source='external', $list=0, $code='')
Get array of all contacts for an object.
dol_now($mode='gmt')
Return date for now.
getTasksArray($usert=null, $userp=null, $projectid=0, $socid=0, $mode=0, $filteronproj='', $filteronprojstatus='-1', $morewherefilter='', $filteronprojuser=0, $filterontaskuser=0)
Return list of tasks for all projects or for one particular project Sort order is on project...
Definition: task.class.php:734
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...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getSummaryOfTimeSpent($userobj=null, $morewherefilter='')
Calculate total of time spent for task.
Class to manage tasks.
Definition: task.class.php:33
fetch($id, $ref='', $loadparentdata=0)
Load object in memory from database.
Definition: task.class.php:234
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
delTimeSpent($user, $notrigger=0)
Delete time spent.
dol_html_entity_decode($a, $b, $c='UTF-8')
Replace html_entity_decode functions to manage errors.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)