dolibarr  13.0.2
tasks.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require "../main.inc.php";
27 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
34 if ($conf->categorie->enabled) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; }
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('projects', 'users', 'companies'));
38 
39 $action = GETPOST('action', 'aZ09');
40 $massaction = GETPOST('massaction', 'alpha');
41 $show_files = GETPOST('show_files', 'int');
42 $confirm = GETPOST('confirm', 'alpha');
43 $toselect = GETPOST('toselect', 'array');
44 
45 $id = GETPOST('id', 'int');
46 $ref = GETPOST('ref', 'alpha');
47 $taskref = GETPOST('taskref', 'alpha');
48 
49 // Load variable for pagination
50 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
51 $sortfield = GETPOST('sortfield', 'aZ09comma');
52 $sortorder = GETPOST('sortorder', 'aZ09comma');
53 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
54 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 
59 $backtopage = GETPOST('backtopage', 'alpha');
60 $cancel = GETPOST('cancel', 'alpha');
61 
62 $search_user_id = GETPOST('search_user_id', 'int');
63 $search_taskref = GETPOST('search_taskref');
64 $search_tasklabel = GETPOST('search_tasklabel');
65 $search_taskdescription = GETPOST('search_taskdescription');
66 $search_dtstartday = GETPOST('search_dtstartday');
67 $search_dtstartmonth = GETPOST('search_dtstartmonth');
68 $search_dtstartyear = GETPOST('search_dtstartyear');
69 $search_dtendday = GETPOST('search_dtendday');
70 $search_dtendmonth = GETPOST('search_dtendmonth');
71 $search_dtendyear = GETPOST('search_dtendyear');
72 $search_planedworkload = GETPOST('search_planedworkload');
73 $search_timespend = GETPOST('search_timespend');
74 $search_progresscalc = GETPOST('search_progresscalc');
75 $search_progressdeclare = GETPOST('search_progressdeclare');
76 
77 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'projecttasklist';
78 
79 //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
80 
81 $object = new Project($db);
82 $taskstatic = new Task($db);
83 $extrafields = new ExtraFields($db);
84 
85 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
86 if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
87 
88 if ($id > 0 || !empty($ref))
89 {
90  // fetch optionals attributes and labels
91  $extrafields->fetch_name_optionals_label($object->table_element);
92 }
93 $extrafields->fetch_name_optionals_label($taskstatic->table_element);
94 $search_array_options = $extrafields->getOptionalsFromPost($taskstatic->table_element, '', 'search_');
95 
96 
97 // Default sort order (if not yet defined by previous GETPOST)
98 if (!$sortfield) { reset($object->fields); $sortfield="t.".key($object->fields); } // Set here default search field. By default 1st field in definition. Reset is required to avoid key() to return null.
99 if (!$sortorder) $sortorder = "ASC";
100 
101 
102 // Security check
103 $socid = 0;
104 //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
105 $result = restrictedArea($user, 'projet', $id, 'projet&project');
106 
107 $diroutputmassaction = $conf->projet->dir_output.'/tasks/temp/massgeneration/'.$user->id;
108 
109 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
110 $hookmanager->initHooks(array('projecttaskscard', 'globalcard'));
111 
112 $progress = GETPOST('progress', 'int');
113 $label = GETPOST('label', 'alpha');
114 $description = GETPOST('description', 'restricthtml');
115 $planned_workloadhour = (GETPOST('planned_workloadhour', 'int') ?GETPOST('planned_workloadhour', 'int') : 0);
116 $planned_workloadmin = (GETPOST('planned_workloadmin', 'int') ?GETPOST('planned_workloadmin', 'int') : 0);
117 $planned_workload = $planned_workloadhour * 3600 + $planned_workloadmin * 60;
118 
119 // Definition of fields for list
120 $arrayfields = array(
121  't.ref'=>array('label'=>$langs->trans("RefTask"), 'checked'=>1, 'position'=>1),
122  't.label'=>array('label'=>$langs->trans("LabelTask"), 'checked'=>1, 'position'=>2),
123  't.description'=>array('label'=>$langs->trans("Description"), 'checked'=>0, 'position'=>3),
124  't.dateo'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>4),
125  't.datee'=>array('label'=>$langs->trans("Deadline"), 'checked'=>1, 'position'=>5),
126  't.planned_workload'=>array('label'=>$langs->trans("PlannedWorkload"), 'checked'=>1, 'position'=>6),
127  't.duration_effective'=>array('label'=>$langs->trans("TimeSpent"), 'checked'=>1, 'position'=>7),
128  't.progress_calculated'=>array('label'=>$langs->trans("ProgressCalculated"), 'checked'=>1, 'position'=>8),
129  't.progress'=>array('label'=>$langs->trans("ProgressDeclared"), 'checked'=>1, 'position'=>9),
130  't.progress_summary'=>array('label'=>$langs->trans("TaskProgressSummary"), 'checked'=>1, 'position'=>10),
131 );
132 if ($object->usage_bill_time) {
133  $arrayfields['t.tobill'] = array('label'=>$langs->trans("TimeToBill"), 'checked'=>0, 'position'=>11);
134  $arrayfields['t.billed'] = array('label'=>$langs->trans("TimeBilled"), 'checked'=>0, 'position'=>12);
135 }
136 
137 // Extra fields
138 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
139 
140 $arrayfields = dol_sort_array($arrayfields, 'position');
141 
142 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
143 
144 
145 /*
146  * Actions
147  */
148 
149 $parameters = array('id'=>$id);
150 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
151 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
152 
153 if (empty($reshook))
154 {
155  // Selection of new fields
156  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
157 
158  // Purge search criteria
159  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
160  {
161  $search_user_id = "";
162  $search_taskref = '';
163  $search_tasklabel = '';
164  $search_dtstartday = '';
165  $search_dtstartmonth = '';
166  $search_dtstartyear = '';
167  $search_dtendday = '';
168  $search_dtendmonth = '';
169  $search_dtendyear = '';
170  $search_planedworkload = '';
171  $search_timespend = '';
172  $search_progresscalc = '';
173  $search_progressdeclare = '';
174  $toselect = '';
175  $search_array_options = array();
176  }
177 
178  // Mass actions
179  $objectclass = 'Task';
180  $objectlabel = 'Tasks';
181  $permissiontoread = $user->rights->projet->lire;
182  $permissiontodelete = $user->rights->projet->supprimer;
183  $uploaddir = $conf->projet->dir_output.'/tasks';
184  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
185 }
186 
187 $morewherefilterarray = array();
188 
189 if (!empty($search_taskref)) {
190  $morewherefilterarray[] = natural_search('t.ref', $search_taskref, 0, 1);
191 }
192 
193 if (!empty($search_tasklabel)) {
194  $morewherefilterarray[] = natural_search('t.label', $search_tasklabel, 0, 1);
195 }
196 
197 $moresql = dolSqlDateFilter('t.dateo', $search_dtstartday, $search_dtstartmonth, $search_dtstartyear, 1);
198 if ($moresql) $morewherefilterarray[] = $moresql;
199 
200 $moresql = dolSqlDateFilter('t.datee', $search_dtendday, $search_dtendmonth, $search_dtendyear, 1);
201 if ($moresql) $morewherefilterarray[] = $moresql;
202 
203 if (!empty($search_planedworkload)) {
204  $morewherefilterarray[] = natural_search('t.planned_workload', $search_planedworkload, 1, 1);
205 }
206 
207 if (!empty($search_timespend)) {
208  $morewherefilterarray[] = natural_search('t.duration_effective', $search_timespend, 1, 1);
209 }
210 
211 if (!empty($search_progresscalc)) {
212  $filterprogresscalc = 'if '.natural_search('round(100 * $line->duration / $line->planned_workload,2)', $search_progresscalc, 1, 1).'{return 1;} else {return 0;}';
213 } else {
214  $filterprogresscalc = '';
215 }
216 
217 if (!empty($search_progressdeclare)) {
218  $morewherefilterarray[] = natural_search('t.progress', $search_progressdeclare, 1, 1);
219 }
220 
221 $morewherefilter = '';
222 if (count($morewherefilterarray) > 0) {
223  $morewherefilter = ' AND '.implode(' AND ', $morewherefilterarray);
224 }
225 
226 if ($action == 'createtask' && $user->rights->projet->creer)
227 {
228  $error = 0;
229 
230  // If we use user timezone, we must change also view/list to use user timezone everywhere
231  //$date_start = dol_mktime($_POST['dateohour'],$_POST['dateomin'],0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear'],'user');
232  //$date_end = dol_mktime($_POST['dateehour'],$_POST['dateemin'],0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear'],'user');
233  $date_start = dol_mktime(GETPOST('dateohour', 'int'), GETPOST('dateomin', 'int'), 0, GETPOST('dateomonth', 'int'), GETPOST('dateoday', 'int'), GETPOST('dateoyear', 'int'));
234  $date_end = dol_mktime(GETPOST('dateehour', 'int'), GETPOST('dateemin', 'int'), 0, GETPOST('dateemonth', 'int'), GETPOST('dateeday', 'int'), GETPOST('dateeyear', 'int'));
235 
236  if (!$cancel)
237  {
238  if (empty($taskref))
239  {
240  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
241  $action = 'create';
242  $error++;
243  }
244  if (empty($label))
245  {
246  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
247  $action = 'create';
248  $error++;
249  } elseif (empty($_POST['task_parent']))
250  {
251  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ChildOfProjectTask")), null, 'errors');
252  $action = 'create';
253  $error++;
254  }
255 
256  if (!$error)
257  {
258  $tmparray = explode('_', GETPOST('task_parent'));
259  $projectid = $tmparray[0];
260  if (empty($projectid)) $projectid = $id; // If projectid is ''
261  $task_parent = $tmparray[1];
262  if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
263 
264  $task = new Task($db);
265 
266  $task->fk_project = $projectid;
267  $task->ref = $taskref;
268  $task->label = $label;
269  $task->description = $description;
270  $task->planned_workload = $planned_workload;
271  $task->fk_task_parent = $task_parent;
272  $task->date_c = dol_now();
273  $task->date_start = $date_start;
274  $task->date_end = $date_end;
275  $task->progress = $progress;
276 
277  // Fill array 'array_options' with data from add form
278  $ret = $extrafields->setOptionalsFromPost(null, $task);
279 
280  $taskid = $task->create($user);
281 
282  if ($taskid > 0)
283  {
284  $result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
285  } else {
286  if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
287  {
288  $langs->load("projects");
289  setEventMessages($langs->trans('NewTaskRefSuggested'), '', 'warnings');
290  $duplicate_code_error = true;
291  } else {
292  setEventMessages($task->error, $task->errors, 'errors');
293  }
294  $action = 'create';
295  $error++;
296  }
297  }
298 
299  if (!$error)
300  {
301  if (!empty($backtopage))
302  {
303  header("Location: ".$backtopage);
304  exit;
305  } elseif (empty($projectid))
306  {
307  header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode) ? '' : '?mode='.$mode));
308  exit;
309  }
310  $id = $projectid;
311  }
312  } else {
313  if (!empty($backtopage))
314  {
315  header("Location: ".$backtopage);
316  exit;
317  } elseif (empty($id))
318  {
319  // We go back on task list
320  header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode) ? '' : '?mode='.$mode));
321  exit;
322  }
323  }
324 }
325 
326 
327 /*
328  * View
329  */
330 
331 $now = dol_now();
332 $form = new Form($db);
333 $formother = new FormOther($db);
334 $socstatic = new Societe($db);
335 $projectstatic = new Project($db);
336 $taskstatic = new Task($db);
337 $userstatic = new User($db);
338 
339 $title = $langs->trans("Project").' - '.$langs->trans("Tasks").' - '.$object->ref.' '.$object->name;
340 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->ref.' '.$object->name.' - '.$langs->trans("Tasks");
341 $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
342 
343 llxHeader("", $title, $help_url);
344 
345 
346 if ($id > 0 || !empty($ref))
347 {
348  $object->fetch($id, $ref);
349  $object->fetch_thirdparty();
350  $res = $object->fetch_optionals();
351 
352  // To verify role of users
353  //$userAccess = $object->restrictedProjectArea($user,'read');
354  $userWrite = $object->restrictedProjectArea($user, 'write');
355  //$userDelete = $object->restrictedProjectArea($user,'delete');
356  //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
357 
358 
359  $tab = (GETPOSTISSET('tab') ? GETPOST('tab') : 'tasks');
360 
361  $head = project_prepare_head($object);
362  print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
363 
364  $param = '&id='.$object->id;
365  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
366  if ($search_user_id) $param .= '&search_user_id='.urlencode($search_user_id);
367  if ($search_taskref) $param .= '&search_taskref='.urlencode($search_taskref);
368  if ($search_tasklabel) $param .= '&search_tasklabel='.urlencode($search_tasklabel);
369  if ($search_taskdescription) $param .= '&search_taskdescription='.urlencode($search_taskdescription);
370  if ($search_dtstartday) $param .= '&search_dtstartday='.urlencode($search_dtstartday);
371  if ($search_dtstartmonth) $param .= '&search_dtstartmonth='.urlencode($search_dtstartmonth);
372  if ($search_dtstartyear) $param .= '&search_dtstartyear='.urlencode($search_dtstartyear);
373  if ($search_dtendday) $param .= '&search_dtendday='.urlencode($search_dtendday);
374  if ($search_dtendmonth) $param .= '&search_dtendmonth='.urlencode($search_dtendmonth);
375  if ($search_dtendyear) $param .= '&search_dtendyear='.urlencode($search_dtendyear);
376  if ($search_planedworkload) $param .= '&search_planedworkload='.urlencode($search_planedworkload);
377  if ($search_timespend) $param .= '&search_timespend='.urlencode($search_timespend);
378  if ($search_progresscalc) $param .= '&search_progresscalc='.urlencode($search_progresscalc);
379  if ($search_progressdeclare) $param .= '&search_progressdeclare='.urlencode($search_progressdeclare);
380  if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
381  // Add $param from extra fields
382  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
383 
384  // Project card
385 
386  $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
387 
388  $morehtmlref = '<div class="refidno">';
389  // Title
390  $morehtmlref .= $object->title;
391  // Thirdparty
392  if ($object->thirdparty->id > 0)
393  {
394  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'project');
395  }
396  $morehtmlref .= '</div>';
397 
398  // Define a complementary filter for search of next/prev ref.
399  if (!$user->rights->projet->all->lire)
400  {
401  $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
402  $object->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
403  }
404 
405  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
406 
407  print '<div class="fichecenter">';
408  print '<div class="fichehalfleft">';
409  print '<div class="underbanner clearboth"></div>';
410 
411  print '<table class="border tableforfield" width="100%">';
412 
413  // Usage
414  print '<tr><td class="tdtop">';
415  print $langs->trans("Usage");
416  print '</td>';
417  print '<td>';
418  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
419  {
420  print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
421  $htmltext = $langs->trans("ProjectFollowOpportunity");
422  print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
423  print '<br>';
424  }
425  if (empty($conf->global->PROJECT_HIDE_TASKS))
426  {
427  print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
428  $htmltext = $langs->trans("ProjectFollowTasks");
429  print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
430  print '<br>';
431  }
432  if (!empty($conf->global->PROJECT_BILL_TIME_SPENT))
433  {
434  print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_bill_time ? ' checked="checked"' : '')).'"> ';
435  $htmltext = $langs->trans("ProjectBillTimeDescription");
436  print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
437  print '<br>';
438  }
439  print '</td></tr>';
440 
441  // Visibility
442  print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
443  if ($object->public) print $langs->trans('SharedProject');
444  else print $langs->trans('PrivateProject');
445  print '</td></tr>';
446 
447  // Date start - end
448  print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
449  $start = dol_print_date($object->date_start, 'day');
450  print ($start ? $start : '?');
451  $end = dol_print_date($object->date_end, 'day');
452  print ' - ';
453  print ($end ? $end : '?');
454  if ($object->hasDelay()) print img_warning("Late");
455  print '</td></tr>';
456 
457  // Budget
458  print '<tr><td>'.$langs->trans("Budget").'</td><td>';
459  if (strcmp($object->budget_amount, '')) print price($object->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
460  print '</td></tr>';
461 
462  // Other attributes
463  $cols = 2;
464  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
465 
466  print '</table>';
467 
468  print '</div>';
469  print '<div class="fichehalfright">';
470  print '<div class="ficheaddleft">';
471  print '<div class="underbanner clearboth"></div>';
472 
473  print '<table class="border tableforfield" width="100%">';
474 
475  // Description
476  print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
477  print nl2br($object->description);
478  print '</td></tr>';
479 
480  // Categories
481  if ($conf->categorie->enabled) {
482  print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td>';
483  print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
484  print "</td></tr>";
485  }
486 
487  print '</table>';
488 
489  print '</div>';
490  print '</div>';
491  print '</div>';
492 
493  print '<div class="clearboth"></div>';
494 
495 
497 }
498 
499 
500 if ($action == 'create' && $user->rights->projet->creer && (empty($object->thirdparty->id) || $userWrite > 0))
501 {
502  if ($id > 0 || !empty($ref)) print '<br>';
503 
504  print load_fiche_titre($langs->trans("NewTask"), '', 'projecttask');
505 
506  if ($object->id > 0 && $object->statut == Project::STATUS_CLOSED) {
507  print '<div class="warning">';
508  $langs->load("errors");
509  print $langs->trans("WarningProjectClosed");
510  print '</div>';
511  }
512 
513  if ($object->id > 0 && $object->statut == Project::STATUS_DRAFT) {
514  print '<div class="warning">';
515  $langs->load("errors");
516  print $langs->trans("WarningProjectDraft");
517  print '</div>';
518  }
519 
520  print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
521  print '<input type="hidden" name="token" value="'.newToken().'">';
522  print '<input type="hidden" name="action" value="createtask">';
523  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
524  if (!empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
525 
527 
528  print '<table class="border centpercent">';
529 
530  $defaultref = '';
531  $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
532  if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
533  {
534  require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
535  $modTask = new $obj;
536  $defaultref = $modTask->getNextValue($object->thirdparty, null);
537  }
538 
539  if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = '';
540 
541  // Ref
542  print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>';
543  if (empty($duplicate_code_error))
544  {
545  print (GETPOSTISSET("ref") ? GETPOST("ref", 'alpha') : $defaultref);
546  } else {
547  print $defaultref;
548  }
549  print '<input type="hidden" name="taskref" value="'.(GETPOSTISSET("ref") ? GETPOST("ref", 'alpha') : $defaultref).'">';
550  print '</td></tr>';
551 
552  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
553  print '<input type="text" name="label" autofocus class="minwidth500 maxwidthonsmartphone" value="'.$label.'">';
554  print '</td></tr>';
555 
556  // List of projects
557  print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfProjectTask").'</td><td>';
558  print img_picto('', 'project');
559  $formother->selectProjectTasks(GETPOST('task_parent'), $projectid ? $projectid : $object->id, 'task_parent', 0, 0, 1, 1, 0, '0,1', 'maxwidth500');
560  print '</td></tr>';
561 
562  print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
563  $contactsofproject = (!empty($object->id) ? $object->getListContactId('internal') : '');
564  if (is_array($contactsofproject) && count($contactsofproject))
565  {
566  print $form->select_dolusers($user->id, 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, '', 'maxwidth300');
567  } else {
568  print $langs->trans("NoUserAssignedToTheProject");
569  }
570  print '</td></tr>';
571 
572  // Date start
573  print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
574  print $form->selectDate(($date_start ? $date_start : ''), 'dateo', 1, 1, 0, '', 1, 1);
575  print '</td></tr>';
576 
577  // Date end
578  print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
579  print $form->selectDate(($date_end ? $date_end : -1), 'datee', -1, 1, 0, '', 1, 1);
580  print '</td></tr>';
581 
582  // Planned workload
583  print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
584  print $form->select_duration('planned_workload', $planned_workload ? $planned_workload : 0, 0, 'text');
585  print '</td></tr>';
586 
587  // Progress
588  print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
589  print $formother->select_percent($progress, 'progress', 0, 5, 0, 100, 1);
590  print '</td></tr>';
591 
592  // Description
593  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
594  print '<td>';
595  print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_4.'">'.$description.'</textarea>';
596  print '</td></tr>';
597 
598  // Other options
599  $parameters = array();
600  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $taskstatic, $action); // Note that $action and $object may have been modified by hook
601  print $hookmanager->resPrint;
602 
603  if (empty($reshook) && !empty($extrafields->attributes[$taskstatic->table_element]['label']))
604  {
605  print $taskstatic->showOptionals($extrafields, 'edit'); // Do not use $object here that is object of project but use $taskstatic
606  }
607 
608  print '</table>';
609 
611 
612  print '<div class="center">';
613  print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
614  print ' &nbsp; &nbsp; ';
615  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
616  print '</div>';
617 
618  print '</form>';
619 } elseif ($id > 0 || !empty($ref)) {
620  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
621 
622  /*
623  * Projet card in view mode
624  */
625 
626  print '<br>';
627 
628  // Link to create task
629  $linktocreatetaskParam = array();
630  $linktocreatetaskUserRight = false;
631  if ($user->rights->projet->all->creer || $user->rights->projet->creer) {
632  if ($object->public || $userWrite > 0) {
633  $linktocreatetaskUserRight = true;
634  } else {
635  $linktocreatetaskParam['attr']['title'] = $langs->trans("NotOwnerOfProject");
636  }
637  }
638 
639  $linktocreatetask = dolGetButtonTitle($langs->trans('AddTask'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/tasks.php?action=create'.$param.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id), '', $linktocreatetaskUserRight, $linktocreatetaskParam);
640 
641  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
642  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
643  print '<input type="hidden" name="token" value="'.newToken().'">';
644  print '<input type="hidden" name="action" value="list">';
645  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
646  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
647  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
648  print '<input type="hidden" name="page" value="'.$page.'">';
649  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
650 
651  $title = $langs->trans("ListOfTasks");
652  $linktotasks = dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-list-alt imgforviewmode', DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id, '', 1, array('morecss'=>'reposition btnTitleSelected'));
653  $linktotasks .= dolGetButtonTitle($langs->trans('ViewGantt'), '', 'fa fa-stream imgforviewmode', DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id.'&withproject=1', '', 1, array('morecss'=>'reposition marginleftonly'));
654 
655  //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'generic', 0, '', '', 0, 1);
656  print load_fiche_titre($title, $linktotasks.' &nbsp; '.$linktocreatetask, 'projecttask');
657 
658  // Get list of tasks in tasksarray and taskarrayfiltered
659  // We need all tasks (even not limited to a user because a task to user can have a parent that is not affected to him).
660  $filteronthirdpartyid = $socid;
661  $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0, '', -1, $morewherefilter, 0, 0, $extrafields, 1, $search_array_options);
662 
663  // We load also tasks limited to a particular user
664  $tmpuser = new User($db);
665  if ($search_user_id > 0) $tmpuser->fetch($search_user_id);
666 
667  $tasksrole = ($tmpuser->id > 0 ? $taskstatic->getUserRolesForProjectsOrTasks(0, $tmpuser, $object->id, 0) : '');
668  //var_dump($tasksarray);
669  //var_dump($tasksrole);
670 
671  if (!empty($conf->use_javascript_ajax))
672  {
673  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
674  }
675 
676  // Filter on categories
677  $moreforfilter = '';
678  if (count($tasksarray) > 0)
679  {
680  $moreforfilter .= '<div class="divsearchfield">';
681  $moreforfilter .= $langs->trans("TasksAssignedTo").': ';
682  $moreforfilter .= $form->select_dolusers($tmpuser->id > 0 ? $tmpuser->id : '', 'search_user_id', 1);
683  $moreforfilter .= '</div>';
684  }
685  if ($moreforfilter)
686  {
687  print '<div class="liste_titre liste_titre_bydiv centpercent">';
688  print $moreforfilter;
689  print '</div>';
690  }
691 
692  print '<div class="div-table-responsive">';
693  print '<table id="tablelines" class="tagtable nobottom liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
694 
695  // Fields title search
696  print '<tr class="liste_titre_filter">';
697 
698  if (!empty($arrayfields['t.ref']['checked'])) {
699  print '<td class="liste_titre">';
700  print '<input class="flat searchstring maxwidth50" type="text" name="search_taskref" value="'.dol_escape_htmltag($search_taskref).'">';
701  print '</td>';
702  }
703 
704  if (!empty($arrayfields['t.label']['checked'])) {
705  print '<td class="liste_titre">';
706  print '<input class="flat searchstring maxwidth100" type="text" name="search_tasklabel" value="'.dol_escape_htmltag($search_tasklabel).'">';
707  print '</td>';
708  }
709 
710  if (!empty($arrayfields['t.description']['checked'])) {
711  print '<td class="liste_titre">';
712  print '<input class="flat searchstring maxwidth100" type="text" name="search_taskdescription" value="'.dol_escape_htmltag($search_taskdescription).'">';
713  print '</td>';
714  }
715 
716  if (!empty($arrayfields['t.dateo']['checked'])) {
717  print '<td class="liste_titre center">';
718  print '<span class="nowraponall"><input class="flat valignmiddle width20" type="text" maxlength="2" name="search_dtstartday" value="'.$search_dtstartday.'">';
719  print '<input class="flat valignmiddle width20" type="text" maxlength="2" name="search_dtstartmonth" value="'.$search_dtstartmonth.'"></span>';
720  $formother->select_year($search_dtstartyear ? $search_dtstartyear : -1, 'search_dtstartyear', 1, 20, 5);
721  print '</td>';
722  }
723 
724  if (!empty($arrayfields['t.datee']['checked'])) {
725  print '<td class="liste_titre center">';
726  print '<span class="nowraponall"><input class="flat valignmiddle width20" type="text" maxlength="2" name="search_dtendday" value="'.$search_dtendday.'">';
727  print '<input class="flat valignmiddle width20" type="text" maxlength="2" name="search_dtendmonth" value="'.$search_dtendmonth.'"></span>';
728  $formother->select_year($search_dtendyear ? $search_dtendyear : -1, 'search_dtendyear', 1, 20, 5);
729  print '</td>';
730  }
731 
732  if (!empty($arrayfields['t.planned_workload']['checked'])) {
733  print '<td class="liste_titre right">';
734  print '<input class="flat" type="text" size="4" name="search_planedworkload" value="'.$search_planedworkload.'">';
735  print '</td>';
736  }
737 
738  if (!empty($arrayfields['t.duration_effective']['checked'])) {
739  print '<td class="liste_titre right">';
740  print '<input class="flat" type="text" size="4" name="search_timespend" value="'.$search_timespend.'">';
741  print '</td>';
742  }
743 
744  if (!empty($arrayfields['t.progress_calculated']['checked'])) {
745  print '<td class="liste_titre right">';
746  print '<input class="flat" type="text" size="4" name="search_progresscalc" value="'.$search_progresscalc.'">';
747  print '</td>';
748  }
749 
750  if (!empty($arrayfields['t.progress']['checked'])) {
751  print '<td class="liste_titre right">';
752  print '<input class="flat" type="text" size="4" name="search_progressdeclare" value="'.$search_progressdeclare.'">';
753  print '</td>';
754  }
755 
756  // progress resume not searchable
757  print '<td class="liste_titre right"></td>';
758 
759  if ($object->usage_bill_time)
760  {
761  if (!empty($arrayfields['t.tobill']['checked'])) {
762  print '<td class="liste_titre right">';
763  print '</td>';
764  }
765 
766  if (!empty($arrayfields['t.billed']['checked'])) {
767  print '<td class="liste_titre right">';
768  print '</td>';
769  }
770  }
771 
772  if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) print '<td class="liste_titre"></td>';
773 
774  $extrafieldsobjectkey = $taskstatic->table_element;
775  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
776 
777  // Action column
778  print '<td class="liste_titre maxwidthsearch">';
779  $searchpicto = $form->showFilterButtons();
780  print $searchpicto;
781  print '</td>';
782  print "</tr>\n";
783 
784  print '<tr class="liste_titre nodrag nodrop">';
785  // print '<td>'.$langs->trans("Project").'</td>';
786  if (!empty($arrayfields['t.ref']['checked'])) print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '');
787  if (!empty($arrayfields['t.label']['checked'])) print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
788  if (!empty($arrayfields['t.description']['checked'])) print_liste_field_titre($arrayfields['t.description']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
789  if (!empty($arrayfields['t.dateo']['checked'])) print_liste_field_titre($arrayfields['t.dateo']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
790  if (!empty($arrayfields['t.datee']['checked'])) print_liste_field_titre($arrayfields['t.datee']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
791  if (!empty($arrayfields['t.planned_workload']['checked'])) print_liste_field_titre($arrayfields['t.planned_workload']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
792  if (!empty($arrayfields['t.duration_effective']['checked'])) print_liste_field_titre($arrayfields['t.duration_effective']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
793  if (!empty($arrayfields['t.progress_calculated']['checked'])) print_liste_field_titre($arrayfields['t.progress_calculated']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
794  if (!empty($arrayfields['t.progress']['checked'])) print_liste_field_titre($arrayfields['t.progress']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
795  if (!empty($arrayfields['t.progress_summary']['checked'])) print_liste_field_titre($arrayfields['t.progress_summary']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ', '', 1);
796  if ($object->usage_bill_time)
797  {
798  if (!empty($arrayfields['t.tobill']['checked'])) print_liste_field_titre($arrayfields['t.tobill']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
799  if (!empty($arrayfields['t.billed']['checked'])) print_liste_field_titre($arrayfields['t.billed']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
800  }
801  if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) print_liste_field_titre("TaskRessourceLinks", $_SERVER["PHP_SELF"], '', '', $param, $sortfield, $sortorder);
802  // Extra fields
803  $disablesortlink = 1;
804  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
805  // Hook fields
806  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
807  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
808  print $hookmanager->resPrint;
809  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
810  print "</tr>\n";
811 
812  if (count($tasksarray) > 0)
813  {
814  // Show all lines in taskarray (recursive function to go down on tree)
815  $j = 0; $level = 0;
816  $nboftaskshown = projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $object->id, 1, $object->id, $filterprogresscalc, ($object->usage_bill_time ? 1 : 0), $arrayfields);
817  } else {
818  $colspan = 10;
819  if ($object->usage_bill_time) $colspan += 2;
820  print '<tr class="oddeven nobottom"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoTasks").'</span></td></tr>';
821  }
822 
823  print "</table>";
824  print '</div>';
825 
826  print '</form>';
827 
828 
829  // Test if database is clean. If not we clean it.
830  //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
831  if (!empty($user->rights->projet->all->lire)) // We make test to clean only if user has permission to see all (test may report false positive otherwise)
832  {
833  if ($search_user_id == $user->id)
834  {
835  if ($nboftaskshown < count($tasksrole))
836  {
837  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
838  cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
839  }
840  } else {
841  if ($nboftaskshown < count($tasksarray) && !GETPOST('search_user_id', 'int'))
842  {
843  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
844  cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
845  }
846  }
847  }
848 }
849 
850 // End of page
851 llxFooter();
852 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent)
Clean corrupted tree (orphelins linked to a not existing parent), record linked to themself and child...
const STATUS_CLOSED
Closed status.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
llxHeader()
Empty header.
Definition: wrapper.php:45
projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId= '', $addordertick=0, $projectidfortotallink=0, $filterprogresscalc= '', $showbilltime=0, $arrayfields=array())
Show task lines with a particular parent.
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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...
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
Definition: date.lib.php:281
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
project_prepare_head(Project $project)
Prepare array with list of tabs.
Definition: project.lib.php:36
print
Draft customers invoices.
Definition: index.php:89
Class to manage tasks.
Definition: task.class.php:35
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
const STATUS_DRAFT
Draft status.
llxFooter()
Empty footer.
Definition: wrapper.php:59