tasks.php 48 KB

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