PageRenderTime 62ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/projet/tasks.php

https://github.com/atm-maxime/dolibarr
PHP | 853 lines | 628 code | 136 blank | 89 comment | 145 complexity | 852e019bb527006cad1e85d17b3041aa MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, CC-BY-SA-4.0, BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception, LGPL-3.0, LGPL-2.0, MIT
  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. /**
  20. * \file htdocs/projet/tasks.php
  21. * \ingroup project
  22. * \brief List all tasks of a project
  23. */
  24. require "../main.inc.php";
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  32. if ($conf->categorie->enabled) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; }
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('projects', 'users', 'companies'));
  35. $action = GETPOST('action', 'alpha');
  36. $massaction = GETPOST('massaction', 'alpha');
  37. $show_files = GETPOST('show_files', 'int');
  38. $confirm = GETPOST('confirm', 'alpha');
  39. $toselect = GETPOST('toselect', 'array');
  40. $id = GETPOST('id', 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. $taskref = GETPOST('taskref', 'alpha');
  43. $backtopage = GETPOST('backtopage', 'alpha');
  44. $cancel = GETPOST('cancel', 'alpha');
  45. $search_user_id = GETPOST('search_user_id', 'int');
  46. $search_taskref = GETPOST('search_taskref');
  47. $search_tasklabel = GETPOST('search_tasklabel');
  48. $search_taskdescription = GETPOST('search_taskdescription');
  49. $search_dtstartday = GETPOST('search_dtstartday');
  50. $search_dtstartmonth = GETPOST('search_dtstartmonth');
  51. $search_dtstartyear = GETPOST('search_dtstartyear');
  52. $search_dtendday = GETPOST('search_dtendday');
  53. $search_dtendmonth = GETPOST('search_dtendmonth');
  54. $search_dtendyear = GETPOST('search_dtendyear');
  55. $search_planedworkload = GETPOST('search_planedworkload');
  56. $search_timespend = GETPOST('search_timespend');
  57. $search_progresscalc = GETPOST('search_progresscalc');
  58. $search_progressdeclare = GETPOST('search_progressdeclare');
  59. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'projecttasklist';
  60. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  61. $object = new Project($db);
  62. $taskstatic = new Task($db);
  63. $extrafields = new ExtraFields($db);
  64. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  65. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
  66. if ($id > 0 || !empty($ref))
  67. {
  68. // fetch optionals attributes and labels
  69. $extrafields->fetch_name_optionals_label($object->table_element);
  70. }
  71. $extrafields->fetch_name_optionals_label($taskstatic->table_element);
  72. $search_array_options = $extrafields->getOptionalsFromPost($taskstatic->table_element, '', 'search_');
  73. // Security check
  74. $socid = 0;
  75. //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.
  76. $result = restrictedArea($user, 'projet', $id, 'projet&project');
  77. $diroutputmassaction = $conf->projet->dir_output.'/tasks/temp/massgeneration/'.$user->id;
  78. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  79. $hookmanager->initHooks(array('projecttaskscard', 'globalcard'));
  80. $progress = GETPOST('progress', 'int');
  81. $label = GETPOST('label', 'alpha');
  82. $description = GETPOST('description', 'none');
  83. $planned_workloadhour = (GETPOST('planned_workloadhour', 'int') ?GETPOST('planned_workloadhour', 'int') : 0);
  84. $planned_workloadmin = (GETPOST('planned_workloadmin', 'int') ?GETPOST('planned_workloadmin', 'int') : 0);
  85. $planned_workload = $planned_workloadhour * 3600 + $planned_workloadmin * 60;
  86. // Definition of fields for list
  87. $arrayfields = array(
  88. 't.ref'=>array('label'=>$langs->trans("RefTask"), 'checked'=>1, 'position'=>1),
  89. 't.label'=>array('label'=>$langs->trans("LabelTask"), 'checked'=>1, 'position'=>2),
  90. 't.description'=>array('label'=>$langs->trans("Description"), 'checked'=>0, 'position'=>3),
  91. 't.dateo'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>4),
  92. 't.datee'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1, 'position'=>5),
  93. 't.planned_workload'=>array('label'=>$langs->trans("PlannedWorkload"), 'checked'=>1, 'position'=>6),
  94. 't.duration_effective'=>array('label'=>$langs->trans("TimeSpent"), 'checked'=>1, 'position'=>7),
  95. 't.progress_calculated'=>array('label'=>$langs->trans("ProgressCalculated"), 'checked'=>1, 'position'=>8),
  96. 't.progress'=>array('label'=>$langs->trans("ProgressDeclared"), 'checked'=>1, 'position'=>9),
  97. 't.progress_summary'=>array('label'=>$langs->trans("TaskProgressSummary"), 'checked'=>1, 'position'=>10),
  98. );
  99. if ($object->usage_bill_time) {
  100. $arrayfields['t.tobill'] = array('label'=>$langs->trans("TimeToBill"), 'checked'=>0, 'position'=>11);
  101. $arrayfields['t.billed'] = array('label'=>$langs->trans("TimeBilled"), 'checked'=>0, 'position'=>12);
  102. }
  103. // Extra fields
  104. if (is_array($extrafields->attributes[$taskstatic->table_element]['label']) && count($extrafields->attributes[$taskstatic->table_element]['label']) > 0)
  105. {
  106. foreach ($extrafields->attributes[$taskstatic->table_element]['label'] as $key => $val)
  107. {
  108. if (!empty($extrafields->attributes[$taskstatic->table_element]['list'][$key]))
  109. $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$taskstatic->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$taskstatic->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$taskstatic->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$taskstatic->table_element]['list'][$key]) != 3 && $extrafields->attributes[$taskstatic->table_element]['perms'][$key]));
  110. }
  111. }
  112. $arrayfields = dol_sort_array($arrayfields, 'position');
  113. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  114. /*
  115. * Actions
  116. */
  117. $parameters = array('id'=>$id);
  118. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  119. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  120. if (empty($reshook))
  121. {
  122. // Selection of new fields
  123. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  124. // Purge search criteria
  125. 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
  126. {
  127. $search_user_id = "";
  128. $search_taskref = '';
  129. $search_tasklabel = '';
  130. $search_dtstartday = '';
  131. $search_dtstartmonth = '';
  132. $search_dtstartyear = '';
  133. $search_dtendday = '';
  134. $search_dtendmonth = '';
  135. $search_dtendyear = '';
  136. $search_planedworkload = '';
  137. $search_timespend = '';
  138. $search_progresscalc = '';
  139. $search_progressdeclare = '';
  140. $toselect = '';
  141. $search_array_options = array();
  142. }
  143. // Mass actions
  144. $objectclass = 'Task';
  145. $objectlabel = 'Tasks';
  146. $permissiontoread = $user->rights->projet->lire;
  147. $permissiontodelete = $user->rights->projet->supprimer;
  148. $uploaddir = $conf->projet->dir_output.'/tasks';
  149. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  150. }
  151. $morewherefilterarray = array();
  152. if (!empty($search_taskref)) {
  153. $morewherefilterarray[] = natural_search('t.ref', $search_taskref, 0, 1);
  154. }
  155. if (!empty($search_tasklabel)) {
  156. $morewherefilterarray[] = natural_search('t.label', $search_tasklabel, 0, 1);
  157. }
  158. $moresql = dolSqlDateFilter('t.dateo', $search_dtstartday, $search_dtstartmonth, $search_dtstartyear, 1);
  159. if ($moresql) $morewherefilterarray[] = $moresql;
  160. $moresql = dolSqlDateFilter('t.datee', $search_dtendday, $search_dtendmonth, $search_dtendyear, 1);
  161. if ($moresql) $morewherefilterarray[] = $moresql;
  162. if (!empty($search_planedworkload)) {
  163. $morewherefilterarray[] = natural_search('t.planned_workload', $search_planedworkload, 1, 1);
  164. }
  165. if (!empty($search_timespend)) {
  166. $morewherefilterarray[] = natural_search('t.duration_effective', $search_timespend, 1, 1);
  167. }
  168. if (!empty($search_progresscalc)) {
  169. $filterprogresscalc = 'if '.natural_search('round(100 * $line->duration / $line->planned_workload,2)', $search_progresscalc, 1, 1).'{return 1;} else {return 0;}';
  170. } else {
  171. $filterprogresscalc = '';
  172. }
  173. if (!empty($search_progressdeclare)) {
  174. $morewherefilterarray[] = natural_search('t.progress', $search_progressdeclare, 1, 1);
  175. }
  176. $morewherefilter = '';
  177. if (count($morewherefilterarray) > 0) {
  178. $morewherefilter = ' AND '.implode(' AND ', $morewherefilterarray);
  179. }
  180. if ($action == 'createtask' && $user->rights->projet->creer)
  181. {
  182. $error = 0;
  183. // If we use user timezone, we must change also view/list to use user timezone everywhere
  184. //$date_start = dol_mktime($_POST['dateohour'],$_POST['dateomin'],0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear'],'user');
  185. //$date_end = dol_mktime($_POST['dateehour'],$_POST['dateemin'],0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear'],'user');
  186. $date_start = dol_mktime($_POST['dateohour'], $_POST['dateomin'], 0, $_POST['dateomonth'], $_POST['dateoday'], $_POST['dateoyear']);
  187. $date_end = dol_mktime($_POST['dateehour'], $_POST['dateemin'], 0, $_POST['dateemonth'], $_POST['dateeday'], $_POST['dateeyear']);
  188. if (!$cancel)
  189. {
  190. if (empty($taskref))
  191. {
  192. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  193. $action = 'create';
  194. $error++;
  195. }
  196. if (empty($label))
  197. {
  198. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  199. $action = 'create';
  200. $error++;
  201. }
  202. elseif (empty($_POST['task_parent']))
  203. {
  204. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ChildOfProjectTask")), null, 'errors');
  205. $action = 'create';
  206. $error++;
  207. }
  208. if (!$error)
  209. {
  210. $tmparray = explode('_', $_POST['task_parent']);
  211. $projectid = $tmparray[0];
  212. if (empty($projectid)) $projectid = $id; // If projectid is ''
  213. $task_parent = $tmparray[1];
  214. if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
  215. $task = new Task($db);
  216. $task->fk_project = $projectid;
  217. $task->ref = $taskref;
  218. $task->label = $label;
  219. $task->description = $description;
  220. $task->planned_workload = $planned_workload;
  221. $task->fk_task_parent = $task_parent;
  222. $task->date_c = dol_now();
  223. $task->date_start = $date_start;
  224. $task->date_end = $date_end;
  225. $task->progress = $progress;
  226. // Fill array 'array_options' with data from add form
  227. $ret = $extrafields->setOptionalsFromPost(null, $task);
  228. $taskid = $task->create($user);
  229. if ($taskid > 0)
  230. {
  231. $result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
  232. }
  233. else
  234. {
  235. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  236. {
  237. $langs->load("projects");
  238. setEventMessages($langs->trans('NewTaskRefSuggested'), '', 'warnings');
  239. $duplicate_code_error = true;
  240. }
  241. else
  242. {
  243. setEventMessages($task->error, $task->errors, 'errors');
  244. }
  245. $action = 'create';
  246. $error++;
  247. }
  248. }
  249. if (!$error)
  250. {
  251. if (!empty($backtopage))
  252. {
  253. header("Location: ".$backtopage);
  254. exit;
  255. }
  256. elseif (empty($projectid))
  257. {
  258. header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode) ? '' : '?mode='.$mode));
  259. exit;
  260. }
  261. $id = $projectid;
  262. }
  263. }
  264. else
  265. {
  266. if (!empty($backtopage))
  267. {
  268. header("Location: ".$backtopage);
  269. exit;
  270. }
  271. elseif (empty($id))
  272. {
  273. // We go back on task list
  274. header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode) ? '' : '?mode='.$mode));
  275. exit;
  276. }
  277. }
  278. }
  279. /*
  280. * View
  281. */
  282. $now = dol_now();
  283. $form = new Form($db);
  284. $formother = new FormOther($db);
  285. $socstatic = new Societe($db);
  286. $projectstatic = new Project($db);
  287. $taskstatic = new Task($db);
  288. $userstatic = new User($db);
  289. $title = $langs->trans("Project").' - '.$langs->trans("Tasks").' - '.$object->ref.' '.$object->name;
  290. 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");
  291. $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  292. llxHeader("", $title, $help_url);
  293. if ($id > 0 || !empty($ref))
  294. {
  295. $object->fetch($id, $ref);
  296. $object->fetch_thirdparty();
  297. $res = $object->fetch_optionals();
  298. // To verify role of users
  299. //$userAccess = $object->restrictedProjectArea($user,'read');
  300. $userWrite = $object->restrictedProjectArea($user, 'write');
  301. //$userDelete = $object->restrictedProjectArea($user,'delete');
  302. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  303. $tab = GETPOST('tab') ?GETPOST('tab') : 'tasks';
  304. $head = project_prepare_head($object);
  305. dol_fiche_head($head, $tab, $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  306. $param = '&id='.$object->id;
  307. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  308. if ($search_user_id) $param .= '&search_user_id='.urlencode($search_user_id);
  309. if ($search_taskref) $param .= '&search_taskref='.urlencode($search_taskref);
  310. if ($search_tasklabel) $param .= '&search_tasklabel='.urlencode($search_tasklabel);
  311. if ($search_taskdescription) $param .= '&search_taskdescription='.urlencode($search_taskdescription);
  312. if ($search_dtstartday) $param .= '&search_dtstartday='.urlencode($search_dtstartday);
  313. if ($search_dtstartmonth) $param .= '&search_dtstartmonth='.urlencode($search_dtstartmonth);
  314. if ($search_dtstartyear) $param .= '&search_dtstartyear='.urlencode($search_dtstartyear);
  315. if ($search_dtendday) $param .= '&search_dtendday='.urlencode($search_dtendday);
  316. if ($search_dtendmonth) $param .= '&search_dtendmonth='.urlencode($search_dtendmonth);
  317. if ($search_dtendyear) $param .= '&search_dtendyear='.urlencode($search_dtendyear);
  318. if ($search_planedworkload) $param .= '&search_planedworkload='.urlencode($search_planedworkload);
  319. if ($search_timespend) $param .= '&search_timespend='.urlencode($search_timespend);
  320. if ($search_progresscalc) $param .= '&search_progresscalc='.urlencode($search_progresscalc);
  321. if ($search_progressdeclare) $param .= '&search_progressdeclare='.urlencode($search_progressdeclare);
  322. if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
  323. // Add $param from extra fields
  324. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  325. // Project card
  326. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  327. $morehtmlref = '<div class="refidno">';
  328. // Title
  329. $morehtmlref .= $object->title;
  330. // Thirdparty
  331. if ($object->thirdparty->id > 0)
  332. {
  333. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'project');
  334. }
  335. $morehtmlref .= '</div>';
  336. // Define a complementary filter for search of next/prev ref.
  337. if (!$user->rights->projet->all->lire)
  338. {
  339. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  340. $object->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  341. }
  342. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  343. print '<div class="fichecenter">';
  344. print '<div class="fichehalfleft">';
  345. print '<div class="underbanner clearboth"></div>';
  346. print '<table class="border tableforfield" width="100%">';
  347. // Usage
  348. print '<tr><td class="tdtop">';
  349. print $langs->trans("Usage");
  350. print '</td>';
  351. print '<td>';
  352. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
  353. {
  354. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  355. $htmltext = $langs->trans("ProjectFollowOpportunity");
  356. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  357. print '<br>';
  358. }
  359. if (empty($conf->global->PROJECT_HIDE_TASKS))
  360. {
  361. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
  362. $htmltext = $langs->trans("ProjectFollowTasks");
  363. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  364. print '<br>';
  365. }
  366. if (!empty($conf->global->PROJECT_BILL_TIME_SPENT))
  367. {
  368. 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"' : '')).'"> ';
  369. $htmltext = $langs->trans("ProjectBillTimeDescription");
  370. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  371. print '<br>';
  372. }
  373. print '</td></tr>';
  374. // Visibility
  375. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  376. if ($object->public) print $langs->trans('SharedProject');
  377. else print $langs->trans('PrivateProject');
  378. print '</td></tr>';
  379. // Date start - end
  380. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  381. $start = dol_print_date($object->date_start, 'day');
  382. print ($start ? $start : '?');
  383. $end = dol_print_date($object->date_end, 'day');
  384. print ' - ';
  385. print ($end ? $end : '?');
  386. if ($object->hasDelay()) print img_warning("Late");
  387. print '</td></tr>';
  388. // Budget
  389. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  390. if (strcmp($object->budget_amount, '')) print price($object->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
  391. print '</td></tr>';
  392. // Other attributes
  393. $cols = 2;
  394. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  395. print '</table>';
  396. print '</div>';
  397. print '<div class="fichehalfright">';
  398. print '<div class="ficheaddleft">';
  399. print '<div class="underbanner clearboth"></div>';
  400. print '<table class="border tableforfield" width="100%">';
  401. // Description
  402. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  403. print nl2br($object->description);
  404. print '</td></tr>';
  405. // Categories
  406. if ($conf->categorie->enabled) {
  407. print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td>';
  408. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  409. print "</td></tr>";
  410. }
  411. print '</table>';
  412. print '</div>';
  413. print '</div>';
  414. print '</div>';
  415. print '<div class="clearboth"></div>';
  416. dol_fiche_end();
  417. }
  418. if ($action == 'create' && $user->rights->projet->creer && (empty($object->thirdparty->id) || $userWrite > 0))
  419. {
  420. if ($id > 0 || !empty($ref)) print '<br>';
  421. print load_fiche_titre($langs->trans("NewTask"), '', 'projecttask');
  422. if ($object->statut == Project::STATUS_CLOSED)
  423. {
  424. print '<div class="warning">';
  425. $langs->load("errors");
  426. print $langs->trans("WarningProjectClosed");
  427. print '</div>';
  428. }
  429. else
  430. {
  431. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  432. print '<input type="hidden" name="token" value="'.newToken().'">';
  433. print '<input type="hidden" name="action" value="createtask">';
  434. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  435. if (!empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
  436. dol_fiche_head('');
  437. print '<table class="border centpercent">';
  438. $defaultref = '';
  439. $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
  440. if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
  441. {
  442. require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
  443. $modTask = new $obj;
  444. $defaultref = $modTask->getNextValue($object->thirdparty, null);
  445. }
  446. if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = '';
  447. // Ref
  448. print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>';
  449. if (empty($duplicate_code_error))
  450. {
  451. print (GETPOSTISSET("ref") ?GETPOST("ref", 'alpha') : $defaultref);
  452. }
  453. else
  454. {
  455. print $defaultref;
  456. }
  457. print '<input type="hidden" name="taskref" value="'.($_POST["ref"] ? $_POST["ref"] : $defaultref).'">';
  458. print '</td></tr>';
  459. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
  460. print '<input type="text" name="label" autofocus class="minwidth500" value="'.$label.'">';
  461. print '</td></tr>';
  462. // List of projects
  463. print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfProjectTask").'</td><td>';
  464. print $formother->selectProjectTasks(GETPOST('task_parent'), $projectid ? $projectid : $object->id, 'task_parent', 0, 0, 1, 1, 0, '0,1', 'maxwidth500');
  465. print '</td></tr>';
  466. print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
  467. $contactsofproject = (!empty($object->id) ? $object->getListContactId('internal') : '');
  468. if (is_array($contactsofproject) && count($contactsofproject))
  469. {
  470. print $form->select_dolusers($user->id, 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, '', 'maxwidth300');
  471. }
  472. else
  473. {
  474. print $langs->trans("NoUserAssignedToTheProject");
  475. }
  476. print '</td></tr>';
  477. // Date start
  478. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  479. print $form->selectDate(($date_start ? $date_start : ''), 'dateo', 1, 1, 0, '', 1, 1);
  480. print '</td></tr>';
  481. // Date end
  482. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  483. print $form->selectDate(($date_end ? $date_end : -1), 'datee', -1, 1, 0, '', 1, 1);
  484. print '</td></tr>';
  485. // Planned workload
  486. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  487. print $form->select_duration('planned_workload', $planned_workload ? $planned_workload : 0, 0, 'text');
  488. print '</td></tr>';
  489. // Progress
  490. print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
  491. print $formother->select_percent($progress, 'progress', 0, 5, 0, 100, 1);
  492. print '</td></tr>';
  493. // Description
  494. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  495. print '<td>';
  496. print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_4.'">'.$description.'</textarea>';
  497. print '</td></tr>';
  498. // Other options
  499. $parameters = array();
  500. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $taskstatic, $action); // Note that $action and $object may have been modified by hook
  501. print $hookmanager->resPrint;
  502. if (empty($reshook) && !empty($extrafields->attributes[$taskstatic->table_element]['label']))
  503. {
  504. print $taskstatic->showOptionals($extrafields, 'edit'); // Do not use $object here that is object of project but use $taskstatic
  505. }
  506. print '</table>';
  507. dol_fiche_end();
  508. print '<div class="center">';
  509. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  510. print ' &nbsp; &nbsp; ';
  511. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  512. print '</div>';
  513. print '</form>';
  514. }
  515. }
  516. elseif ($id > 0 || !empty($ref))
  517. {
  518. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  519. /*
  520. * Projet card in view mode
  521. */
  522. print '<br>';
  523. // Link to create task
  524. $linktocreatetaskParam = array();
  525. $linktocreatetaskUserRight = false;
  526. if ($user->rights->projet->all->creer || $user->rights->projet->creer) {
  527. if ($object->public || $userWrite > 0) {
  528. $linktocreatetaskUserRight = true;
  529. } else {
  530. $linktocreatetaskParam['attr']['title'] = $langs->trans("NotOwnerOfProject");
  531. }
  532. }
  533. $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);
  534. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  535. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  536. print '<input type="hidden" name="token" value="'.newToken().'">';
  537. print '<input type="hidden" name="action" value="list">';
  538. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  539. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  540. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  541. print '<input type="hidden" name="page" value="'.$page.'">';
  542. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  543. $title = $langs->trans("ListOfTasks");
  544. $linktotasks = dolGetButtonTitle($langs->trans('ViewGantt'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id.'&withproject=1', '', 1, array('morecss'=>'reposition'));
  545. //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'generic', 0, '', '', 0, 1);
  546. print load_fiche_titre($title, $linktotasks.' &nbsp; '.$linktocreatetask, 'generic');
  547. // Get list of tasks in tasksarray and taskarrayfiltered
  548. // 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).
  549. $filteronthirdpartyid = $socid;
  550. $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0, '', -1, $morewherefilter, 0, 0, $extrafields, 1, $search_array_options);
  551. // We load also tasks limited to a particular user
  552. $tmpuser = new User($db);
  553. if ($search_user_id > 0) $tmpuser->fetch($search_user_id);
  554. $tasksrole = ($tmpuser->id > 0 ? $taskstatic->getUserRolesForProjectsOrTasks(0, $tmpuser, $object->id, 0) : '');
  555. //var_dump($tasksarray);
  556. //var_dump($tasksrole);
  557. if (!empty($conf->use_javascript_ajax))
  558. {
  559. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  560. }
  561. // Filter on categories
  562. $moreforfilter = '';
  563. if (count($tasksarray) > 0)
  564. {
  565. $moreforfilter .= '<div class="divsearchfield">';
  566. $moreforfilter .= $langs->trans("TasksAssignedTo").': ';
  567. $moreforfilter .= $form->select_dolusers($tmpuser->id > 0 ? $tmpuser->id : '', 'search_user_id', 1);
  568. $moreforfilter .= '</div>';
  569. }
  570. if ($moreforfilter)
  571. {
  572. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  573. print $moreforfilter;
  574. print '</div>';
  575. }
  576. print '<div class="div-table-responsive">';
  577. print '<table id="tablelines" class="tagtable nobottom liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
  578. // Fields title search
  579. print '<tr class="liste_titre_filter">';
  580. if (!empty($arrayfields['t.ref']['checked'])) {
  581. print '<td class="liste_titre">';
  582. print '<input class="flat searchstring maxwidth50" type="text" name="search_taskref" value="'.dol_escape_htmltag($search_taskref).'">';
  583. print '</td>';
  584. }
  585. if (!empty($arrayfields['t.label']['checked'])) {
  586. print '<td class="liste_titre">';
  587. print '<input class="flat searchstring maxwidth100" type="text" name="search_tasklabel" value="'.dol_escape_htmltag($search_tasklabel).'">';
  588. print '</td>';
  589. }
  590. if (!empty($arrayfields['t.description']['checked'])) {
  591. print '<td class="liste_titre">';
  592. print '<input class="flat searchstring maxwidth100" type="text" name="search_taskdescription" value="'.dol_escape_htmltag($search_taskdescription).'">';
  593. print '</td>';
  594. }
  595. if (!empty($arrayfields['t.dateo']['checked'])) {
  596. print '<td class="liste_titre center">';
  597. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_dtstartday" value="'.$search_dtstartday.'">';
  598. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_dtstartmonth" value="'.$search_dtstartmonth.'">';
  599. $formother->select_year($search_dtstartyear ? $search_dtstartyear : -1, 'search_dtstartyear', 1, 20, 5);
  600. print '</td>';
  601. }
  602. if (!empty($arrayfields['t.datee']['checked'])) {
  603. print '<td class="liste_titre center">';
  604. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_dtendday" value="'.$search_dtendday.'">';
  605. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_dtendmonth" value="'.$search_dtendmonth.'">';
  606. $formother->select_year($search_dtendyear ? $search_dtendyear : -1, 'search_dtendyear', 1, 20, 5);
  607. print '</td>';
  608. }
  609. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  610. print '<td class="liste_titre right">';
  611. print '<input class="flat" type="text" size="4" name="search_planedworkload" value="'.$search_planedworkload.'">';
  612. print '</td>';
  613. }
  614. if (!empty($arrayfields['t.duration_effective']['checked'])) {
  615. print '<td class="liste_titre right">';
  616. print '<input class="flat" type="text" size="4" name="search_timespend" value="'.$search_timespend.'">';
  617. print '</td>';
  618. }
  619. if (!empty($arrayfields['t.progress_calculated']['checked'])) {
  620. print '<td class="liste_titre right">';
  621. print '<input class="flat" type="text" size="4" name="search_progresscalc" value="'.$search_progresscalc.'">';
  622. print '</td>';
  623. }
  624. if (!empty($arrayfields['t.progress']['checked'])) {
  625. print '<td class="liste_titre right">';
  626. print '<input class="flat" type="text" size="4" name="search_progressdeclare" value="'.$search_progressdeclare.'">';
  627. print '</td>';
  628. }
  629. // progress resume not searchable
  630. print '<td class="liste_titre right"></td>';
  631. if ($object->usage_bill_time)
  632. {
  633. if (!empty($arrayfields['t.tobill']['checked'])) {
  634. print '<td class="liste_titre right">';
  635. print '</td>';
  636. }
  637. if (!empty($arrayfields['t.billed']['checked'])) {
  638. print '<td class="liste_titre right">';
  639. print '</td>';
  640. }
  641. }
  642. if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) print '<td class="liste_titre"></td>';
  643. $extrafieldsobjectkey = $taskstatic->table_element;
  644. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  645. // Action column
  646. print '<td class="liste_titre maxwidthsearch">';
  647. $searchpicto = $form->showFilterButtons();
  648. print $searchpicto;
  649. print '</td>';
  650. print "</tr>\n";
  651. print '<tr class="liste_titre nodrag nodrop">';
  652. // print '<td>'.$langs->trans("Project").'</td>';
  653. if (!empty($arrayfields['t.ref']['checked'])) print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '');
  654. if (!empty($arrayfields['t.label']['checked'])) print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
  655. if (!empty($arrayfields['t.description']['checked'])) print_liste_field_titre($arrayfields['t.description']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
  656. if (!empty($arrayfields['t.dateo']['checked'])) print_liste_field_titre($arrayfields['t.dateo']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
  657. if (!empty($arrayfields['t.datee']['checked'])) print_liste_field_titre($arrayfields['t.datee']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
  658. if (!empty($arrayfields['t.planned_workload']['checked'])) print_liste_field_titre($arrayfields['t.planned_workload']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
  659. if (!empty($arrayfields['t.duration_effective']['checked'])) print_liste_field_titre($arrayfields['t.duration_effective']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
  660. if (!empty($arrayfields['t.progress_calculated']['checked'])) print_liste_field_titre($arrayfields['t.progress_calculated']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
  661. if (!empty($arrayfields['t.progress']['checked'])) print_liste_field_titre($arrayfields['t.progress']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
  662. if (!empty($arrayfields['t.progress_summary']['checked'])) print_liste_field_titre($arrayfields['t.progress_summary']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
  663. if ($object->usage_bill_time)
  664. {
  665. if (!empty($arrayfields['t.tobill']['checked'])) print_liste_field_titre($arrayfields['t.tobill']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
  666. if (!empty($arrayfields['t.billed']['checked'])) print_liste_field_titre($arrayfields['t.billed']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
  667. }
  668. if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) print_liste_field_titre("TaskRessourceLinks", $_SERVER["PHP_SELF"], '', '', $param, $sortfield, $sortorder);
  669. // Extra fields
  670. $disablesortlink = 1;
  671. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  672. // Hook fields
  673. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  674. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  675. print $hookmanager->resPrint;
  676. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  677. print "</tr>\n";
  678. if (count($tasksarray) > 0)
  679. {
  680. // Show all lines in taskarray (recursive function to go down on tree)
  681. $j = 0; $level = 0;
  682. $nboftaskshown = projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $object->id, 1, $object->id, $filterprogresscalc, ($object->usage_bill_time ? 1 : 0), $arrayfields);
  683. }
  684. else
  685. {
  686. $colspan = 10;
  687. if ($object->usage_bill_time) $colspan += 2;
  688. print '<tr class="oddeven nobottom"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoTasks").'</span></td></tr>';
  689. }
  690. print "</table>";
  691. print '</div>';
  692. print '</form>';
  693. // Test if database is clean. If not we clean it.
  694. //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
  695. 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)
  696. {
  697. if ($search_user_id == $user->id)
  698. {
  699. if ($nboftaskshown < count($tasksrole))
  700. {
  701. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  702. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  703. }
  704. }
  705. else
  706. {
  707. if ($nboftaskshown < count($tasksarray) && !GETPOST('search_user_id', 'int'))
  708. {
  709. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  710. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  711. }
  712. }
  713. }
  714. }
  715. // End of page
  716. llxFooter();
  717. $db->close();