tasks.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  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 (isModEnabled('categorie')) {
  33. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  34. }
  35. // Load translation files required by the page
  36. $langsLoad=array('projects', 'users', 'companies');
  37. if (isModEnabled('eventorganization')) {
  38. $langsLoad[]='eventorganization';
  39. }
  40. $langs->loadLangs($langsLoad);
  41. $action = GETPOST('action', 'aZ09');
  42. $massaction = GETPOST('massaction', 'alpha');
  43. $show_files = GETPOST('show_files', 'int');
  44. $confirm = GETPOST('confirm', 'alpha');
  45. $toselect = GETPOST('toselect', 'array');
  46. $id = GETPOST('id', 'int');
  47. $ref = GETPOST('ref', 'alpha');
  48. $taskref = GETPOST('taskref', 'alpha');
  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')) {
  55. $page = 0;
  56. } // If $page is not defined, or '' or -1 or if we click on clear filters
  57. $offset = $limit * $page;
  58. $pageprev = $page - 1;
  59. $pagenext = $page + 1;
  60. $backtopage = GETPOST('backtopage', 'alpha');
  61. $cancel = GETPOST('cancel', 'alpha');
  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. $search_task_budget_amount = GETPOST('search_task_budget_amount');
  77. $search_date_start_startmonth = GETPOST('search_date_start_startmonth', 'int');
  78. $search_date_start_startyear = GETPOST('search_date_start_startyear', 'int');
  79. $search_date_start_startday = GETPOST('search_date_start_startday', 'int');
  80. $search_date_start_start = dol_mktime(0, 0, 0, $search_date_start_startmonth, $search_date_start_startday, $search_date_start_startyear); // Use tzserver
  81. $search_date_start_endmonth = GETPOST('search_date_start_endmonth', 'int');
  82. $search_date_start_endyear = GETPOST('search_date_start_endyear', 'int');
  83. $search_date_start_endday = GETPOST('search_date_start_endday', 'int');
  84. $search_date_start_end = dol_mktime(23, 59, 59, $search_date_start_endmonth, $search_date_start_endday, $search_date_start_endyear); // Use tzserver
  85. $search_date_end_startmonth = GETPOST('search_date_end_startmonth', 'int');
  86. $search_date_end_startyear = GETPOST('search_date_end_startyear', 'int');
  87. $search_date_end_startday = GETPOST('search_date_end_startday', 'int');
  88. $search_date_end_start = dol_mktime(0, 0, 0, $search_date_end_startmonth, $search_date_end_startday, $search_date_end_startyear); // Use tzserver
  89. $search_date_end_endmonth = GETPOST('search_date_end_endmonth', 'int');
  90. $search_date_end_endyear = GETPOST('search_date_end_endyear', 'int');
  91. $search_date_end_endday = GETPOST('search_date_end_endday', 'int');
  92. $search_date_end_end = dol_mktime(23, 59, 59, $search_date_end_endmonth, $search_date_end_endday, $search_date_end_endyear); // Use tzserver
  93. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'projecttasklist';
  94. $optioncss = GETPOST('optioncss', 'aZ');
  95. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  96. $object = new Project($db);
  97. $taskstatic = new Task($db);
  98. $extrafields = new ExtraFields($db);
  99. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  100. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  101. $object->fetchComments();
  102. }
  103. if ($id > 0 || !empty($ref)) {
  104. // fetch optionals attributes and labels
  105. $extrafields->fetch_name_optionals_label($object->table_element);
  106. }
  107. $extrafields->fetch_name_optionals_label($taskstatic->table_element);
  108. $search_array_options = $extrafields->getOptionalsFromPost($taskstatic->table_element, '', 'search_');
  109. // Default sort order (if not yet defined by previous GETPOST)
  110. /* if (!$sortfield) {
  111. reset($object->fields); $sortfield="t.".key($object->fields);
  112. } // Set here default search field. By default 1st field in definition. Reset is required to avoid key() to return null.
  113. if (!$sortorder) {
  114. $sortorder = "ASC";
  115. } */
  116. // Security check
  117. $socid = 0;
  118. //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.
  119. $result = restrictedArea($user, 'projet', $id, 'projet&project');
  120. $diroutputmassaction = $conf->project->dir_output.'/tasks/temp/massgeneration/'.$user->id;
  121. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  122. $hookmanager->initHooks(array('projecttaskscard', 'globalcard'));
  123. $progress = GETPOST('progress', 'int');
  124. $budget_amount = GETPOST('budget_amount', 'int');
  125. $label = GETPOST('label', 'alpha');
  126. $description = GETPOST('description', 'restricthtml');
  127. $planned_workloadhour = (GETPOST('planned_workloadhour', 'int') ?GETPOST('planned_workloadhour', 'int') : 0);
  128. $planned_workloadmin = (GETPOST('planned_workloadmin', 'int') ?GETPOST('planned_workloadmin', 'int') : 0);
  129. $planned_workload = $planned_workloadhour * 3600 + $planned_workloadmin * 60;
  130. // Definition of fields for list
  131. $arrayfields = array(
  132. 't.ref'=>array('label'=>"RefTask", 'checked'=>1, 'position'=>1),
  133. 't.label'=>array('label'=>"LabelTask", 'checked'=>1, 'position'=>2),
  134. 't.description'=>array('label'=>"Description", 'checked'=>0, 'position'=>3),
  135. 't.dateo'=>array('label'=>"DateStart", 'checked'=>1, 'position'=>4),
  136. 't.datee'=>array('label'=>"Deadline", 'checked'=>1, 'position'=>5),
  137. 't.planned_workload'=>array('label'=>"PlannedWorkload", 'checked'=>1, 'position'=>6),
  138. 't.duration_effective'=>array('label'=>"TimeSpent", 'checked'=>1, 'position'=>7),
  139. 't.progress_calculated'=>array('label'=>"ProgressCalculated", 'checked'=>1, 'position'=>8),
  140. 't.progress'=>array('label'=>"ProgressDeclared", 'checked'=>1, 'position'=>9),
  141. 't.progress_summary'=>array('label'=>"TaskProgressSummary", 'checked'=>1, 'position'=>10),
  142. 't.budget_amount'=>array('label'=>"Budget", 'checked'=>0, 'position'=>11),
  143. 'c.assigned'=>array('label'=>"TaskRessourceLinks", 'checked'=>1, 'position'=>12),
  144. );
  145. if ($object->usage_bill_time) {
  146. $arrayfields['t.tobill'] = array('label'=>$langs->trans("TimeToBill"), 'checked'=>0, 'position'=>11);
  147. $arrayfields['t.billed'] = array('label'=>$langs->trans("TimeBilled"), 'checked'=>0, 'position'=>12);
  148. }
  149. // Extra fields
  150. $extrafieldsobjectkey = $taskstatic->table_element;
  151. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  152. $arrayfields = dol_sort_array($arrayfields, 'position');
  153. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  154. /*
  155. * Actions
  156. */
  157. if (GETPOST('cancel', 'alpha')) {
  158. $action = 'list';
  159. $massaction = '';
  160. }
  161. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  162. $massaction = '';
  163. }
  164. $parameters = array('id'=>$id);
  165. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  166. if ($reshook < 0) {
  167. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  168. }
  169. if (empty($reshook)) {
  170. // Selection of new fields
  171. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  172. // Purge search criteria
  173. 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
  174. $search_user_id = "";
  175. $search_taskref = '';
  176. $search_tasklabel = '';
  177. $search_dtstartday = '';
  178. $search_dtstartmonth = '';
  179. $search_dtstartyear = '';
  180. $search_dtendday = '';
  181. $search_dtendmonth = '';
  182. $search_dtendyear = '';
  183. $search_planedworkload = '';
  184. $search_timespend = '';
  185. $search_progresscalc = '';
  186. $search_progressdeclare = '';
  187. $search_task_budget_amount = '';
  188. $toselect = array();
  189. $search_array_options = array();
  190. $search_date_start_startmonth = "";
  191. $search_date_start_startyear = "";
  192. $search_date_start_startday = "";
  193. $search_date_start_start = "";
  194. $search_date_start_endmonth = "";
  195. $search_date_start_endyear = "";
  196. $search_date_start_endday = "";
  197. $search_date_start_end = "";
  198. $search_date_end_startmonth = "";
  199. $search_date_end_startyear = "";
  200. $search_date_end_startday = "";
  201. $search_date_end_start = "";
  202. $search_date_end_endmonth = "";
  203. $search_date_end_endyear = "";
  204. $search_date_end_endday = "";
  205. $search_date_end_end = "";
  206. }
  207. // Mass actions
  208. $objectclass = 'Task';
  209. $objectlabel = 'Tasks';
  210. $permissiontoread = $user->hasRight('projet', 'lire');
  211. $permissiontodelete = $user->hasRight('projet', 'supprimer');
  212. $uploaddir = $conf->project->dir_output.'/tasks';
  213. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  214. }
  215. $morewherefilterarray = array();
  216. if (!empty($search_taskref)) {
  217. $morewherefilterarray[] = natural_search('t.ref', $search_taskref, 0, 1);
  218. }
  219. if (!empty($search_tasklabel)) {
  220. $morewherefilterarray[] = natural_search('t.label', $search_tasklabel, 0, 1);
  221. }
  222. $moresql = dolSqlDateFilter('t.dateo', $search_dtstartday, $search_dtstartmonth, $search_dtstartyear, 1);
  223. if ($moresql) {
  224. $morewherefilterarray[] = $moresql;
  225. }
  226. $moresql = dolSqlDateFilter('t.datee', $search_dtendday, $search_dtendmonth, $search_dtendyear, 1);
  227. if ($moresql) {
  228. $morewherefilterarray[] = $moresql;
  229. }
  230. if ($search_date_start_start) {
  231. $morewherefilterarray[] = " t.dateo >= '".$db->idate($search_date_start_start)."'";
  232. }
  233. if ($search_date_start_end) {
  234. $morewherefilterarray[] = " t.dateo <= '".$db->idate($search_date_start_end)."'";
  235. }
  236. if ($search_date_end_start) {
  237. $morewherefilterarray[] = " t.datee >= '".$db->idate($search_date_end_start)."'";
  238. }
  239. if ($search_date_end_end) {
  240. $morewherefilterarray[] = " t.datee <= '".$db->idate($search_date_end_end)."'";
  241. }
  242. if (!empty($search_planedworkload)) {
  243. $morewherefilterarray[] = natural_search('t.planned_workload', $search_planedworkload, 1, 1);
  244. }
  245. if (!empty($search_timespend)) {
  246. $morewherefilterarray[] = natural_search('t.duration_effective', $search_timespend, 1, 1);
  247. }
  248. if (!empty($search_progressdeclare)) {
  249. $morewherefilterarray[] = natural_search('t.progress', $search_progressdeclare, 1, 1);
  250. }
  251. if (!empty($search_progresscalc)) {
  252. $morewherefilterarray[] = '(planned_workload IS NULL OR planned_workload = 0 OR '.natural_search('ROUND(100 * duration_effective / planned_workload, 2)', $search_progresscalc, 1, 1).')';
  253. //natural_search('round(100 * $line->duration_effective / $line->planned_workload,2)', $filterprogresscalc, 1, 1).' {return 1;} else {return 0;}';
  254. }
  255. if ($search_task_budget_amount) {
  256. $morewherefilterarray[]= natural_search('t.budget_amount', $search_task_budget_amount, 1, 1);
  257. }
  258. //var_dump($morewherefilterarray);
  259. $morewherefilter = '';
  260. if (count($morewherefilterarray) > 0) {
  261. $morewherefilter = ' AND '.implode(' AND ', $morewherefilterarray);
  262. }
  263. if ($action == 'createtask' && $user->hasRight('projet', 'creer')) {
  264. $error = 0;
  265. // If we use user timezone, we must change also view/list to use user timezone everywhere
  266. $date_start = dol_mktime(GETPOST('dateohour', 'int'), GETPOST('dateomin', 'int'), 0, GETPOST('dateomonth', 'int'), GETPOST('dateoday', 'int'), GETPOST('dateoyear', 'int'));
  267. $date_end = dol_mktime(GETPOST('dateehour', 'int'), GETPOST('dateemin', 'int'), 0, GETPOST('dateemonth', 'int'), GETPOST('dateeday', 'int'), GETPOST('dateeyear', 'int'));
  268. if (!$cancel) {
  269. if (empty($taskref)) {
  270. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  271. $action = 'create';
  272. $error++;
  273. }
  274. if (empty($label)) {
  275. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  276. $action = 'create';
  277. $error++;
  278. } elseif (!GETPOST('task_parent')) {
  279. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ChildOfProjectTask")), null, 'errors');
  280. $action = 'create';
  281. $error++;
  282. }
  283. if (!$error) {
  284. $tmparray = explode('_', GETPOST('task_parent'));
  285. $projectid = $tmparray[0];
  286. if (empty($projectid)) {
  287. $projectid = $id; // If projectid is ''
  288. }
  289. $task_parent = $tmparray[1];
  290. if (empty($task_parent)) {
  291. $task_parent = 0; // If task_parent is ''
  292. }
  293. $task = new Task($db);
  294. $task->fk_project = $projectid;
  295. $task->entity = $object->entity; // Task have the same entity of project
  296. $task->ref = $taskref;
  297. $task->label = $label;
  298. $task->description = $description;
  299. $task->planned_workload = $planned_workload;
  300. $task->fk_task_parent = $task_parent;
  301. $task->date_c = dol_now();
  302. $task->date_start = $date_start;
  303. $task->date_end = $date_end;
  304. $task->progress = $progress;
  305. $task->budget_amount = $budget_amount;
  306. // Fill array 'array_options' with data from add form
  307. $ret = $extrafields->setOptionalsFromPost(null, $task);
  308. $taskid = $task->create($user);
  309. if ($taskid > 0) {
  310. $result = $task->add_contact(GETPOST("userid", 'int'), 'TASKEXECUTIVE', 'internal');
  311. } else {
  312. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  313. $langs->load("projects");
  314. setEventMessages($langs->trans('NewTaskRefSuggested'), null, 'warnings');
  315. $duplicate_code_error = true;
  316. } else {
  317. setEventMessages($task->error, $task->errors, 'errors');
  318. }
  319. $action = 'create';
  320. $error++;
  321. }
  322. }
  323. if (!$error) {
  324. if (!empty($backtopage)) {
  325. header("Location: ".$backtopage);
  326. exit;
  327. } elseif (empty($projectid)) {
  328. header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode) ? '' : '?mode='.$mode));
  329. exit;
  330. }
  331. $id = $projectid;
  332. }
  333. } else {
  334. if (!empty($backtopage)) {
  335. header("Location: ".$backtopage);
  336. exit;
  337. } elseif (empty($id)) {
  338. // We go back on task list
  339. header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode) ? '' : '?mode='.$mode));
  340. exit;
  341. }
  342. }
  343. }
  344. /*
  345. * View
  346. */
  347. $now = dol_now();
  348. $form = new Form($db);
  349. $formother = new FormOther($db);
  350. $socstatic = new Societe($db);
  351. $projectstatic = new Project($db);
  352. $taskstatic = new Task($db);
  353. $userstatic = new User($db);
  354. $title = $langs->trans("Tasks").' - '.$object->ref.' '.$object->name;
  355. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  356. $title = $object->ref.' '.$object->name.' - '.$langs->trans("Tasks");
  357. }
  358. if ($action == 'create') {
  359. $title = $langs->trans("NewTask");
  360. }
  361. $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  362. llxHeader("", $title, $help_url);
  363. $arrayofselected = is_array($toselect) ? $toselect : array();
  364. if ($id > 0 || !empty($ref)) {
  365. $result = $object->fetch($id, $ref);
  366. if ($result < 0) {
  367. setEventMessages(null, $object->errors, 'errors');
  368. }
  369. $result = $object->fetch_thirdparty();
  370. if ($result < 0) {
  371. setEventMessages(null, $object->errors, 'errors');
  372. }
  373. $result = $object->fetch_optionals();
  374. if ($result < 0) {
  375. setEventMessages(null, $object->errors, 'errors');
  376. }
  377. // To verify role of users
  378. //$userAccess = $object->restrictedProjectArea($user,'read');
  379. $userWrite = $object->restrictedProjectArea($user, 'write');
  380. //$userDelete = $object->restrictedProjectArea($user,'delete');
  381. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  382. $tab = (GETPOSTISSET('tab') ? GETPOST('tab') : 'tasks');
  383. $head = project_prepare_head($object);
  384. print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  385. $param = '&id='.$object->id;
  386. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  387. $param .= '&contextpage='.urlencode($contextpage);
  388. }
  389. if ($search_user_id) {
  390. $param .= '&search_user_id='.urlencode($search_user_id);
  391. }
  392. if ($search_taskref) {
  393. $param .= '&search_taskref='.urlencode($search_taskref);
  394. }
  395. if ($search_tasklabel) {
  396. $param .= '&search_tasklabel='.urlencode($search_tasklabel);
  397. }
  398. if ($search_taskdescription) {
  399. $param .= '&search_taskdescription='.urlencode($search_taskdescription);
  400. }
  401. if ($search_dtstartday) {
  402. $param .= '&search_dtstartday='.urlencode($search_dtstartday);
  403. }
  404. if ($search_dtstartmonth) {
  405. $param .= '&search_dtstartmonth='.urlencode($search_dtstartmonth);
  406. }
  407. if ($search_dtstartyear) {
  408. $param .= '&search_dtstartyear='.urlencode($search_dtstartyear);
  409. }
  410. if ($search_dtendday) {
  411. $param .= '&search_dtendday='.urlencode($search_dtendday);
  412. }
  413. if ($search_dtendmonth) {
  414. $param .= '&search_dtendmonth='.urlencode($search_dtendmonth);
  415. }
  416. if ($search_dtendyear) {
  417. $param .= '&search_dtendyear='.urlencode($search_dtendyear);
  418. }
  419. if ($search_date_start_startmonth) {
  420. $param .= '&search_date_start_startmonth='.urlencode($search_date_start_startmonth);
  421. }
  422. if ($search_date_start_startyear) {
  423. $param .= '&search_date_start_startyear='.urlencode($search_date_start_startyear);
  424. }
  425. if ($search_date_start_startday) {
  426. $param .= '&search_date_start_startday='.urlencode($search_date_start_startday);
  427. }
  428. if ($search_date_start_start) {
  429. $param .= '&search_date_start_start='.urlencode($search_date_start_start);
  430. }
  431. if ($search_date_start_endmonth) {
  432. $param .= '&search_date_start_endmonth='.urlencode($search_date_start_endmonth);
  433. }
  434. if ($search_date_start_endyear) {
  435. $param .= '&search_date_start_endyear='.urlencode($search_date_start_endyear);
  436. }
  437. if ($search_date_start_endday) {
  438. $param .= '&search_date_start_endday='.urlencode($search_date_start_endday);
  439. }
  440. if ($search_date_start_end) {
  441. $param .= '&search_date_start_end='.urlencode($search_date_start_end);
  442. }
  443. if ($search_date_end_startmonth) {
  444. $param .= '&search_date_end_startmonth='.urlencode($search_date_end_startmonth);
  445. }
  446. if ($search_date_end_startyear) {
  447. $param .= '&search_date_end_startyear='.urlencode($search_date_end_startyear);
  448. }
  449. if ($search_date_end_startday) {
  450. $param .= '&search_date_end_startday='.urlencode($search_date_end_startday);
  451. }
  452. if ($search_date_end_start) {
  453. $param .= '&search_date_end_start='.urlencode($search_date_end_start);
  454. }
  455. if ($search_date_end_endmonth) {
  456. $param .= '&search_date_end_endmonth='.urlencode($search_date_end_endmonth);
  457. }
  458. if ($search_date_end_endyear) {
  459. $param .= '&search_date_end_endyear='.urlencode($search_date_end_endyear);
  460. }
  461. if ($search_date_end_endday) {
  462. $param .= '&search_date_end_endday='.urlencode($search_date_end_endday);
  463. }
  464. if ($search_date_end_end) {
  465. $param .= '&search_date_end_end=' . urlencode($search_date_end_end);
  466. }
  467. if ($search_planedworkload) {
  468. $param .= '&search_planedworkload='.urlencode($search_planedworkload);
  469. }
  470. if ($search_timespend) {
  471. $param .= '&search_timespend='.urlencode($search_timespend);
  472. }
  473. if ($search_progresscalc) {
  474. $param .= '&search_progresscalc='.urlencode($search_progresscalc);
  475. }
  476. if ($search_progressdeclare) {
  477. $param .= '&search_progressdeclare='.urlencode($search_progressdeclare);
  478. }
  479. if ($search_task_budget_amount) {
  480. $param .= '&search_task_budget_amount='.urlencode($search_task_budget_amount);
  481. }
  482. if ($optioncss != '') {
  483. $param .= '&optioncss='.urlencode($optioncss);
  484. }
  485. // Add $param from extra fields
  486. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  487. $arrayofmassactions = array();
  488. if ($user->hasRight('projet', 'creer')) {
  489. $arrayofmassactions['preclonetasks'] = img_picto('', 'clone', 'class="pictofixedwidth"').$langs->trans("Clone");
  490. }
  491. if ($permissiontodelete) {
  492. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  493. }
  494. if (in_array($massaction, array('presend', 'predelete'))) {
  495. $arrayofmassactions = array();
  496. }
  497. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  498. // Project card
  499. if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
  500. $tmpurl = $_SESSION['pageforbacktolist']['project'];
  501. $tmpurl = preg_replace('/__SOCID__/', $object->socid, $tmpurl);
  502. $linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  503. } else {
  504. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  505. }
  506. $morehtmlref = '<div class="refidno">';
  507. // Title
  508. $morehtmlref .= $object->title;
  509. // Thirdparty
  510. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  511. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
  512. }
  513. $morehtmlref .= '</div>';
  514. // Define a complementary filter for search of next/prev ref.
  515. if (!$user->hasRight('projet', 'all', 'lire')) {
  516. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  517. $object->next_prev_filter = "rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  518. }
  519. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  520. print '<div class="fichecenter">';
  521. print '<div class="fichehalfleft">';
  522. print '<div class="underbanner clearboth"></div>';
  523. print '<table class="border tableforfield centpercent">';
  524. // Usage
  525. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || isModEnabled('eventorganization')) {
  526. print '<tr><td class="tdtop">';
  527. print $langs->trans("Usage");
  528. print '</td>';
  529. print '<td>';
  530. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  531. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  532. $htmltext = $langs->trans("ProjectFollowOpportunity");
  533. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  534. print '<br>';
  535. }
  536. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  537. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
  538. $htmltext = $langs->trans("ProjectFollowTasks");
  539. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  540. print '<br>';
  541. }
  542. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  543. 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"' : '')).'"> ';
  544. $htmltext = $langs->trans("ProjectBillTimeDescription");
  545. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  546. print '<br>';
  547. }
  548. if (isModEnabled('eventorganization')) {
  549. print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_organize_event ? ' checked="checked"' : '')).'"> ';
  550. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  551. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  552. }
  553. print '</td></tr>';
  554. }
  555. // Visibility
  556. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  557. if ($object->public) {
  558. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  559. print $langs->trans('SharedProject');
  560. } else {
  561. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  562. print $langs->trans('PrivateProject');
  563. }
  564. print '</td></tr>';
  565. // Budget
  566. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  567. if (!is_null($object->budget_amount) && strcmp($object->budget_amount, '')) {
  568. print '<span class="amount">'.price($object->budget_amount, '', $langs, 1, 0, 0, $conf->currency).'</span>';
  569. }
  570. print '</td></tr>';
  571. // Date start - end project
  572. print '<tr><td>'.$langs->trans("Dates").'</td><td>';
  573. $start = dol_print_date($object->date_start, 'day');
  574. print ($start ? $start : '?');
  575. $end = dol_print_date($object->date_end, 'day');
  576. print ' - ';
  577. print ($end ? $end : '?');
  578. if ($object->hasDelay()) {
  579. print img_warning("Late");
  580. }
  581. print '</td></tr>';
  582. // Other attributes
  583. $cols = 2;
  584. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  585. print '</table>';
  586. print '</div>';
  587. print '<div class="fichehalfright">';
  588. print '<div class="underbanner clearboth"></div>';
  589. print '<table class="border tableforfield centpercent">';
  590. // Description
  591. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  592. print dol_htmlentitiesbr($object->description);
  593. print '</td></tr>';
  594. // Categories
  595. if (isModEnabled('categorie')) {
  596. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  597. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  598. print "</td></tr>";
  599. }
  600. print '</table>';
  601. print '</div>';
  602. print '</div>';
  603. print '<div class="clearboth"></div>';
  604. print dol_get_fiche_end();
  605. }
  606. if ($action == 'create' && $user->hasRight('projet', 'creer') && (empty($object->thirdparty->id) || $userWrite > 0)) {
  607. if ($id > 0 || !empty($ref)) {
  608. print '<br>';
  609. }
  610. print load_fiche_titre($langs->trans("NewTask"), '', 'projecttask');
  611. $projectoktoentertime = 1;
  612. if ($object->id > 0 && $object->statut == Project::STATUS_CLOSED) {
  613. $projectoktoentertime = 0;
  614. print '<div class="warning">';
  615. $langs->load("errors");
  616. print $langs->trans("WarningProjectClosed");
  617. print '</div>';
  618. }
  619. if ($object->id > 0 && $object->statut == Project::STATUS_DRAFT) {
  620. $projectoktoentertime = 0;
  621. print '<div class="warning">';
  622. $langs->load("errors");
  623. print $langs->trans("WarningProjectDraft");
  624. print '</div>';
  625. }
  626. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  627. print '<input type="hidden" name="token" value="'.newToken().'">';
  628. print '<input type="hidden" name="action" value="createtask">';
  629. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  630. if (!empty($object->id)) {
  631. print '<input type="hidden" name="id" value="'.$object->id.'">';
  632. }
  633. print dol_get_fiche_head('');
  634. print '<div class="div-table-responsive-no-min">';
  635. print '<table class="border centpercent">';
  636. $defaultref = '';
  637. $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
  638. if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON').".php")) {
  639. require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON').'.php';
  640. $modTask = new $obj;
  641. $defaultref = $modTask->getNextValue($object->thirdparty, null);
  642. }
  643. if (is_numeric($defaultref) && $defaultref <= 0) {
  644. $defaultref = '';
  645. }
  646. // Ref
  647. print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>';
  648. if (empty($duplicate_code_error)) {
  649. print (GETPOSTISSET("ref") ? GETPOST("ref", 'alpha') : $defaultref);
  650. } else {
  651. print $defaultref;
  652. }
  653. print '<input type="hidden" name="taskref" value="'.(GETPOSTISSET("ref") ? GETPOST("ref", 'alpha') : $defaultref).'">';
  654. print '</td></tr>';
  655. // Label
  656. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
  657. print '<input type="text" name="label" autofocus class="minwidth500" value="'.$label.'">';
  658. print '</td></tr>';
  659. // Project
  660. print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfProjectTask").'</td><td>';
  661. print img_picto('', 'project', 'class="pictofixedwidth"');
  662. if ($projectoktoentertime) {
  663. $formother->selectProjectTasks(GETPOST('task_parent'), empty($projectid) ? $object->id : $projectid, 'task_parent', 0, 0, 1, 1, 0, '0,1', 'maxwidth500 widthcentpercentminusxx');
  664. } else {
  665. $formother->selectProjectTasks(GETPOST('task_parent'), empty($projectid) ? $object->id : $projectid, 'task_parent', 0, 0, 1, 1, 0, '', 'maxwidth500 widthcentpercentminusxx');
  666. }
  667. print '</td></tr>';
  668. $contactsofproject = (empty($object->id) ? '' : $object->getListContactId('internal'));
  669. // Assigned to
  670. print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
  671. print img_picto('', 'user', 'class="pictofixedwidth"');
  672. if (is_array($contactsofproject) && count($contactsofproject)) {
  673. print $form->select_dolusers($user->id, 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, '', 'maxwidth500 widthcentpercentminusx');
  674. } else {
  675. if ((isset($projectid) && $projectid > 0) || $object->id > 0) {
  676. print '<span class="opacitymedium">'.$langs->trans("NoUserAssignedToTheProject").'</span>';
  677. } else {
  678. print $form->select_dolusers($user->id, 'userid', 0, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth500 widthcentpercentminusx');
  679. }
  680. }
  681. print '</td></tr>';
  682. // Date start task
  683. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  684. print img_picto('', 'action', 'class="pictofixedwidth"');
  685. print $form->selectDate((!empty($date_start) ? $date_start : ''), 'dateo', 1, 1, 0, '', 1, 1);
  686. print '</td></tr>';
  687. // Date end task
  688. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  689. print img_picto('', 'action', 'class="pictofixedwidth"');
  690. print $form->selectDate((!empty($date_end) ? $date_end : -1), 'datee', -1, 1, 0, '', 1, 1);
  691. print '</td></tr>';
  692. // Planned workload
  693. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  694. print img_picto('', 'clock', 'class="pictofixedwidth"');
  695. print $form->select_duration('planned_workload', !empty($planned_workload) ? $planned_workload : 0, 0, 'text');
  696. print '</td></tr>';
  697. // Progress
  698. print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
  699. print img_picto('', 'fa-percent', 'class="pictofixedwidth"');
  700. print $formother->select_percent($progress, 'progress', 0, 5, 0, 100, 1);
  701. print '</td></tr>';
  702. // Description
  703. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  704. print '<td>';
  705. // WYSIWYG editor
  706. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  707. $cked_enabled = (!empty($conf->global->FCKEDITOR_ENABLE_SOCIETE) ? $conf->global->FCKEDITOR_ENABLE_SOCIETE : 0);
  708. $nbrows = 0;
  709. if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
  710. $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
  711. }
  712. $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_details', '', false, true, $cked_enabled, $nbrows, '90%');
  713. print $doleditor->Create();
  714. print '</td></tr>';
  715. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  716. print img_picto('', 'currency', 'class="pictofixedwidth"');
  717. print '<input size="8" type="text" name="budget_amount" value="'.dol_escape_htmltag(GETPOSTISSET('budget_amount') ? GETPOST('budget_amount') : '').'"></td>';
  718. print '</tr>';
  719. // Other options
  720. $parameters = array('arrayfields' => &$arrayfields);
  721. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $taskstatic, $action); // Note that $action and $object may have been modified by hook
  722. print $hookmanager->resPrint;
  723. if (empty($reshook) && !empty($extrafields->attributes[$taskstatic->table_element]['label'])) {
  724. print $taskstatic->showOptionals($extrafields, 'edit'); // Do not use $object here that is object of project but use $taskstatic
  725. }
  726. print '</table>';
  727. print '</div>';
  728. print dol_get_fiche_end();
  729. print $form->buttonsSaveCancel("Add");
  730. print '</form>';
  731. } elseif ($id > 0 || !empty($ref)) {
  732. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  733. /*
  734. * Projet card in view mode
  735. */
  736. print '<br>';
  737. // Link to create task
  738. $linktocreatetaskParam = array();
  739. $linktocreatetaskUserRight = false;
  740. if ($user->hasRight('projet', 'all', 'creer') || $user->hasRight('projet', 'creer')) {
  741. if ($object->public || $userWrite > 0) {
  742. $linktocreatetaskUserRight = true;
  743. } else {
  744. $linktocreatetaskParam['attr']['title'] = $langs->trans("NotOwnerOfProject");
  745. }
  746. }
  747. $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);
  748. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  749. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  750. print '<input type="hidden" name="token" value="'.newToken().'">';
  751. print '<input type="hidden" name="action" value="list">';
  752. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  753. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  754. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  755. print '<input type="hidden" name="page" value="'.$page.'">';
  756. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  757. $title = $langs->trans("ListOfTasks");
  758. $linktotasks = dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id, '', 1, array('morecss'=>'reposition btnTitleSelected'));
  759. $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'));
  760. //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'generic', 0, '', '', 0, 1);
  761. print load_fiche_titre($title, $linktotasks.' &nbsp; '.$linktocreatetask, 'projecttask', '', '', '', $massactionbutton);
  762. $objecttmp = new Task($db);
  763. $trackid = 'task'.$taskstatic->id;
  764. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  765. // Get list of tasks in tasksarray and taskarrayfiltered
  766. // 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).
  767. $filteronthirdpartyid = $socid;
  768. $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0, '', -1, $morewherefilter, 0, 0, $extrafields, 1, $search_array_options, 0, 1, $sortfield, $sortorder);
  769. // We load also tasks limited to a particular user
  770. $tmpuser = new User($db);
  771. if ($search_user_id > 0) {
  772. $tmpuser->fetch($search_user_id);
  773. }
  774. $tasksrole = ($tmpuser->id > 0 ? $taskstatic->getUserRolesForProjectsOrTasks(null, $tmpuser, $object->id, 0) : '');
  775. //var_dump($tasksarray);
  776. //var_dump($tasksrole);
  777. if (!empty($conf->use_javascript_ajax)) {
  778. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  779. }
  780. // Filter on assigned users
  781. $moreforfilter = '';
  782. $moreforfilter .= '<div class="divsearchfield">';
  783. $moreforfilter .= img_picto('', 'user', 'class="pictofixedwidth"');
  784. $moreforfilter .= $form->select_dolusers($tmpuser->id > 0 ? $tmpuser->id : '', 'search_user_id', $langs->trans("TasksAssignedTo"), null, 0, '', '');
  785. $moreforfilter .= '</div>';
  786. if ($moreforfilter) {
  787. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  788. print $moreforfilter;
  789. print '</div>';
  790. }
  791. // Show the massaction checkboxes only when this page is not opend from the Extended POS
  792. if ($massactionbutton && $contextpage != 'poslist') {
  793. $selectedfields = $form->showCheckAddButtons('checkforselect', 1);
  794. }
  795. print '<div class="div-table-responsive">';
  796. print '<table id="tablelines" class="tagtable nobottom liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
  797. // Fields title search
  798. print '<tr class="liste_titre_filter">';
  799. // Action column
  800. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  801. print '<td class="liste_titre maxwidthsearch">';
  802. $searchpicto = $form->showFilterButtons();
  803. print $searchpicto;
  804. print '</td>';
  805. }
  806. if (!empty($arrayfields['t.ref']['checked'])) {
  807. print '<td class="liste_titre">';
  808. print '<input class="flat searchstring maxwidth50" type="text" name="search_taskref" value="'.dol_escape_htmltag($search_taskref).'">';
  809. print '</td>';
  810. }
  811. if (!empty($arrayfields['t.label']['checked'])) {
  812. print '<td class="liste_titre">';
  813. print '<input class="flat searchstring maxwidth100" type="text" name="search_tasklabel" value="'.dol_escape_htmltag($search_tasklabel).'">';
  814. print '</td>';
  815. }
  816. if (!empty($arrayfields['t.description']['checked'])) {
  817. print '<td class="liste_titre">';
  818. print '<input class="flat searchstring maxwidth100" type="text" name="search_taskdescription" value="'.dol_escape_htmltag($search_taskdescription).'">';
  819. print '</td>';
  820. }
  821. if (!empty($arrayfields['t.dateo']['checked'])) {
  822. print '<td class="liste_titre center">';
  823. /*print '<span class="nowraponall"><input class="flat valignmiddle width20" type="text" maxlength="2" name="search_dtstartday" value="'.$search_dtstartday.'">';
  824. print '<input class="flat valignmiddle width20" type="text" maxlength="2" name="search_dtstartmonth" value="'.$search_dtstartmonth.'"></span>';
  825. print $formother->selectyear($search_dtstartyear ? $search_dtstartyear : -1, 'search_dtstartyear', 1, 20, 5);*/
  826. print '<div class="nowrap">';
  827. print $form->selectDate($search_date_start_start ? $search_date_start_start : -1, 'search_date_start_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  828. print '</div>';
  829. print '<div class="nowrap">';
  830. print $form->selectDate($search_date_start_end ? $search_date_start_end : -1, 'search_date_start_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  831. print '</div>';
  832. print '</td>';
  833. }
  834. if (!empty($arrayfields['t.datee']['checked'])) {
  835. print '<td class="liste_titre center">';
  836. /*print '<span class="nowraponall"><input class="flat valignmiddle width20" type="text" maxlength="2" name="search_dtendday" value="'.$search_dtendday.'">';
  837. print '<input class="flat valignmiddle width20" type="text" maxlength="2" name="search_dtendmonth" value="'.$search_dtendmonth.'"></span>';
  838. print $formother->selectyear($search_dtendyear ? $search_dtendyear : -1, 'search_dtendyear', 1, 20, 5);*/
  839. print '<div class="nowrap">';
  840. print $form->selectDate($search_date_end_start ? $search_date_end_start : -1, 'search_date_end_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  841. print '</div>';
  842. print '<div class="nowrap">';
  843. print $form->selectDate($search_date_end_end ? $search_date_end_end : -1, 'search_date_end_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  844. print '</div>';
  845. print '</td>';
  846. }
  847. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  848. print '<td class="liste_titre right">';
  849. print '<input class="flat" type="text" size="4" name="search_planedworkload" value="'.$search_planedworkload.'">';
  850. print '</td>';
  851. }
  852. if (!empty($arrayfields['t.duration_effective']['checked'])) {
  853. print '<td class="liste_titre right">';
  854. print '<input class="flat" type="text" size="4" name="search_timespend" value="'.$search_timespend.'">';
  855. print '</td>';
  856. }
  857. if (!empty($arrayfields['t.progress_calculated']['checked'])) {
  858. print '<td class="liste_titre right">';
  859. print '<input class="flat" type="text" size="4" name="search_progresscalc" value="'.$search_progresscalc.'">';
  860. print '</td>';
  861. }
  862. if (!empty($arrayfields['t.progress']['checked'])) {
  863. print '<td class="liste_titre right">';
  864. print '<input class="flat" type="text" size="4" name="search_progressdeclare" value="'.$search_progressdeclare.'">';
  865. print '</td>';
  866. }
  867. // progress resume not searchable
  868. if (!empty($arrayfields['t.progress_summary']['checked'])) {
  869. print '<td class="liste_titre right"></td>';
  870. }
  871. if ($object->usage_bill_time) {
  872. if (!empty($arrayfields['t.tobill']['checked'])) {
  873. print '<td class="liste_titre right">';
  874. print '</td>';
  875. }
  876. if (!empty($arrayfields['t.billed']['checked'])) {
  877. print '<td class="liste_titre right">';
  878. print '</td>';
  879. }
  880. }
  881. // Contacts of task, disabled because available by default jsut after
  882. /*
  883. if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) {
  884. print '<td class="liste_titre"></td>';
  885. }
  886. */
  887. if (!empty($arrayfields['t.budget_amount']['checked'])) {
  888. print '<td class="liste_titre center">';
  889. print '<input type="text" class="flat" name="search_task_budget_amount" value="'.$search_task_budget_amount.'" size="4">';
  890. print '</td>';
  891. }
  892. if (!empty($arrayfields['c.assigned']['checked'])) {
  893. print '<td class="liste_titre right">';
  894. print '</td>';
  895. }
  896. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  897. print '<td class="liste_titre maxwidthsearch">&nbsp;</td>';
  898. // Action column
  899. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  900. print '<td class="liste_titre maxwidthsearch">';
  901. $searchpicto = $form->showFilterButtons();
  902. print $searchpicto;
  903. print '</td>';
  904. }
  905. print "</tr>\n";
  906. print '<tr class="liste_titre nodrag nodrop">';
  907. // Action column
  908. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  909. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  910. }
  911. // print '<td>'.$langs->trans("Project").'</td>';
  912. if (!empty($arrayfields['t.ref']['checked'])) {
  913. print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], 't.ref', '', $param, '', $sortfield, $sortorder, '');
  914. }
  915. if (!empty($arrayfields['t.label']['checked'])) {
  916. print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER["PHP_SELF"], "t.label", '', $param, '', $sortfield, $sortorder, '');
  917. }
  918. if (!empty($arrayfields['t.description']['checked'])) {
  919. print_liste_field_titre($arrayfields['t.description']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
  920. }
  921. if (!empty($arrayfields['t.dateo']['checked'])) {
  922. print_liste_field_titre($arrayfields['t.dateo']['label'], $_SERVER["PHP_SELF"], "t.dateo", '', $param, '', $sortfield, $sortorder, 'center ');
  923. }
  924. if (!empty($arrayfields['t.datee']['checked'])) {
  925. print_liste_field_titre($arrayfields['t.datee']['label'], $_SERVER["PHP_SELF"], "t.datee", '', $param, '', $sortfield, $sortorder, 'center ');
  926. }
  927. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  928. print_liste_field_titre($arrayfields['t.planned_workload']['label'], $_SERVER["PHP_SELF"], "t.planned_workload", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
  929. }
  930. if (!empty($arrayfields['t.duration_effective']['checked'])) {
  931. print_liste_field_titre($arrayfields['t.duration_effective']['label'], $_SERVER["PHP_SELF"], "t.duration_effective", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
  932. }
  933. if (!empty($arrayfields['t.progress_calculated']['checked'])) {
  934. print_liste_field_titre($arrayfields['t.progress_calculated']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
  935. }
  936. if (!empty($arrayfields['t.progress']['checked'])) {
  937. print_liste_field_titre($arrayfields['t.progress']['label'], $_SERVER["PHP_SELF"], "t.progress", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
  938. }
  939. if (!empty($arrayfields['t.progress_summary']['checked'])) {
  940. print_liste_field_titre($arrayfields['t.progress_summary']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ', '', 1);
  941. }
  942. if ($object->usage_bill_time) {
  943. if (!empty($arrayfields['t.tobill']['checked'])) {
  944. print_liste_field_titre($arrayfields['t.tobill']['label'], $_SERVER["PHP_SELF"], "t.tobill", '', $param, '', $sortfield, $sortorder, 'right ');
  945. }
  946. if (!empty($arrayfields['t.billed']['checked'])) {
  947. print_liste_field_titre($arrayfields['t.billed']['label'], $_SERVER["PHP_SELF"], "t.billed", '', $param, '', $sortfield, $sortorder, 'right ');
  948. }
  949. }
  950. // Contacts of task, disabled because available by default jsut after
  951. /*
  952. if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) {
  953. print_liste_field_titre("TaskRessourceLinks", $_SERVER["PHP_SELF"], '', '', $param, $sortfield, $sortorder);
  954. }
  955. */
  956. if (!empty($arrayfields['t.budget_amount']['checked'])) {
  957. print_liste_field_titre($arrayfields['t.budget_amount']['label'], $_SERVER["PHP_SELF"], "t.budget_amount", "", $param, '', $sortfield, $sortorder, 'center ');
  958. }
  959. if (!empty($arrayfields['c.assigned']['checked'])) {
  960. print_liste_field_titre($arrayfields['c.assigned']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ', '');
  961. }
  962. // Extra fields
  963. $disablesortlink = 1;
  964. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  965. // Hook fields
  966. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  967. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  968. print $hookmanager->resPrint;
  969. print '<td></td>';
  970. // Action column
  971. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  972. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  973. }
  974. print "</tr>\n";
  975. $nboftaskshown = 0;
  976. if (count($tasksarray) > 0) {
  977. // Show all lines in taskarray (recursive function to go down on tree)
  978. $j = 0; $level = 0;
  979. $nboftaskshown = projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $object->id, 1, $object->id, '', ($object->usage_bill_time ? 1 : 0), $arrayfields, $arrayofselected);
  980. } else {
  981. $colspan = count($arrayfields);
  982. if ($object->usage_bill_time) {
  983. $colspan += 2;
  984. }
  985. print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoTasks").'</span></td></tr>';
  986. }
  987. print "</table>";
  988. print '</div>';
  989. print '</form>';
  990. // Test if database is clean. If not we clean it.
  991. //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
  992. if ($user->hasRight('projet', 'all', 'lire')) { // We make test to clean only if user has permission to see all (test may report false positive otherwise)
  993. if ($search_user_id == $user->id) {
  994. if ($nboftaskshown < count($tasksrole)) {
  995. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  996. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  997. }
  998. } else {
  999. if ($nboftaskshown < count($tasksarray) && !GETPOST('search_user_id', 'int')) {
  1000. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1001. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  1002. }
  1003. }
  1004. }
  1005. }
  1006. // End of page
  1007. llxFooter();
  1008. $db->close();