tasks.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.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 <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/projet/tasks.php
  21. * \ingroup projet
  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. $langs->load("users");
  32. $langs->load("projects");
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $taskref = GETPOST('taskref', 'alpha');
  36. $action = GETPOST('action', 'alpha');
  37. $backtopage=GETPOST('backtopage','alpha');
  38. $cancel=GETPOST('cancel','alpha');
  39. $search_user_id = GETPOST('search_user_id', 'int');
  40. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  41. $object = new Project($db);
  42. $taskstatic = new Task($db);
  43. $extrafields_project = new ExtraFields($db);
  44. $extrafields_task = new ExtraFields($db);
  45. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  46. if ($id > 0 || ! empty($ref))
  47. {
  48. // fetch optionals attributes and labels
  49. $extralabels_projet=$extrafields_project->fetch_name_optionals_label($object->table_element);
  50. }
  51. $extralabels_task=$extrafields_task->fetch_name_optionals_label($taskstatic->table_element);
  52. // Security check
  53. $socid=0;
  54. //if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  55. $result = restrictedArea($user, 'projet', $id, 'projet&project');
  56. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  57. $hookmanager->initHooks(array('projecttaskcard','globalcard'));
  58. $progress=GETPOST('progress', 'int');
  59. $label=GETPOST('label', 'alpha');
  60. $description=GETPOST('description');
  61. $planned_workloadhour=(GETPOST('planned_workloadhour','int')?GETPOST('planned_workloadhour','int'):0);
  62. $planned_workloadmin=(GETPOST('planned_workloadmin','int')?GETPOST('planned_workloadmin','int'):0);
  63. $planned_workload=$planned_workloadhour*3600+$planned_workloadmin*60;
  64. $userAccess=0;
  65. $parameters=array('id'=>$id);
  66. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  67. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  68. /*
  69. * Actions
  70. */
  71. // Purge search criteria
  72. 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
  73. {
  74. $search_user_id="";
  75. $toselect='';
  76. $search_array_options=array();
  77. }
  78. if ($action == 'createtask' && $user->rights->projet->creer)
  79. {
  80. $error=0;
  81. // If we use user timezone, we must change also view/list to use user timezone everywhere
  82. //$date_start = dol_mktime($_POST['dateohour'],$_POST['dateomin'],0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear'],'user');
  83. //$date_end = dol_mktime($_POST['dateehour'],$_POST['dateemin'],0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear'],'user');
  84. $date_start = dol_mktime($_POST['dateohour'],$_POST['dateomin'],0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']);
  85. $date_end = dol_mktime($_POST['dateehour'],$_POST['dateemin'],0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']);
  86. if (! $cancel)
  87. {
  88. if (empty($taskref))
  89. {
  90. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  91. $action='create';
  92. $error++;
  93. }
  94. if (empty($label))
  95. {
  96. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  97. $action='create';
  98. $error++;
  99. }
  100. else if (empty($_POST['task_parent']))
  101. {
  102. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ChildOfProjectTask")), null, 'errors');
  103. $action='create';
  104. $error++;
  105. }
  106. if (! $error)
  107. {
  108. $tmparray=explode('_',$_POST['task_parent']);
  109. $projectid=$tmparray[0];
  110. if (empty($projectid)) $projectid = $id; // If projectid is ''
  111. $task_parent=$tmparray[1];
  112. if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
  113. $task = new Task($db);
  114. $task->fk_project = $projectid;
  115. $task->ref = $taskref;
  116. $task->label = $label;
  117. $task->description = $description;
  118. $task->planned_workload = $planned_workload;
  119. $task->fk_task_parent = $task_parent;
  120. $task->date_c = dol_now();
  121. $task->date_start = $date_start;
  122. $task->date_end = $date_end;
  123. $task->progress = $progress;
  124. // Fill array 'array_options' with data from add form
  125. $ret = $extrafields_task->setOptionalsFromPost($extralabels_task,$task);
  126. $taskid = $task->create($user);
  127. if ($taskid > 0)
  128. {
  129. $result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
  130. }
  131. else
  132. {
  133. setEventMessages($task->error,$task->errors,'errors');
  134. }
  135. }
  136. if (! $error)
  137. {
  138. if (! empty($backtopage))
  139. {
  140. header("Location: ".$backtopage);
  141. exit;
  142. }
  143. else if (empty($projectid))
  144. {
  145. header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode)?'':'?mode='.$mode));
  146. exit;
  147. }
  148. $id = $projectid;
  149. }
  150. }
  151. else
  152. {
  153. if (! empty($backtopage))
  154. {
  155. header("Location: ".$backtopage);
  156. exit;
  157. }
  158. else if (empty($id))
  159. {
  160. // We go back on task list
  161. header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode)?'':'?mode='.$mode));
  162. exit;
  163. }
  164. }
  165. }
  166. /*
  167. * View
  168. */
  169. $form=new Form($db);
  170. $formother=new FormOther($db);
  171. $taskstatic = new Task($db);
  172. $userstatic=new User($db);
  173. $title=$langs->trans("Project").' - '.$langs->trans("Tasks").' - '.$object->ref.' '.$object->name;
  174. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->ref.' '.$object->name.' - '.$langs->trans("Tasks");
  175. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  176. llxHeader("",$title,$help_url);
  177. if ($id > 0 || ! empty($ref))
  178. {
  179. $object->fetch($id, $ref);
  180. $object->fetch_thirdparty();
  181. $res=$object->fetch_optionals();
  182. // To verify role of users
  183. //$userAccess = $object->restrictedProjectArea($user,'read');
  184. $userWrite = $object->restrictedProjectArea($user,'write');
  185. //$userDelete = $object->restrictedProjectArea($user,'delete');
  186. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  187. $tab=GETPOST('tab')?GETPOST('tab'):'tasks';
  188. $head=project_prepare_head($object);
  189. dol_fiche_head($head, $tab, $langs->trans("Project"), -1, ($object->public?'projectpub':'project'));
  190. $param='';
  191. if ($search_user_id > 0) $param.='&search_user_id='.dol_escape_htmltag($search_user_id);
  192. // Project card
  193. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  194. $morehtmlref='<div class="refidno">';
  195. // Title
  196. $morehtmlref.=$object->title;
  197. // Thirdparty
  198. if ($object->thirdparty->id > 0)
  199. {
  200. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'project');
  201. }
  202. $morehtmlref.='</div>';
  203. // Define a complementary filter for search of next/prev ref.
  204. if (! $user->rights->projet->all->lire)
  205. {
  206. $objectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
  207. $object->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")";
  208. }
  209. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  210. print '<div class="fichecenter">';
  211. print '<div class="fichehalfleft">';
  212. print '<div class="underbanner clearboth"></div>';
  213. print '<table class="border" width="100%">';
  214. // Visibility
  215. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  216. if ($object->public) print $langs->trans('SharedProject');
  217. else print $langs->trans('PrivateProject');
  218. print '</td></tr>';
  219. /*if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
  220. {
  221. // Opportunity status
  222. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  223. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  224. if ($code) print $langs->trans("OppStatus".$code);
  225. print '</td></tr>';
  226. // Opportunity percent
  227. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  228. if (strcmp($object->opp_percent,'')) print price($object->opp_percent,'',$langs,1,0).' %';
  229. print '</td></tr>';
  230. // Opportunity Amount
  231. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  232. if (strcmp($object->opp_amount,'')) print price($object->opp_amount,'',$langs,1,0,0,$conf->currency);
  233. print '</td></tr>';
  234. }*/
  235. // Date start - end
  236. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  237. $start = dol_print_date($object->date_start,'day');
  238. print ($start?$start:'?');
  239. $end = dol_print_date($object->date_end,'day');
  240. print ' - ';
  241. print ($end?$end:'?');
  242. if ($object->hasDelay()) print img_warning("Late");
  243. print '</td></tr>';
  244. // Budget
  245. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  246. if (strcmp($object->budget_amount, '')) print price($object->budget_amount,'',$langs,1,0,0,$conf->currency);
  247. print '</td></tr>';
  248. // Other attributes
  249. $cols = 2;
  250. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  251. print '</table>';
  252. print '</div>';
  253. print '<div class="fichehalfright">';
  254. print '<div class="ficheaddleft">';
  255. print '<div class="underbanner clearboth"></div>';
  256. print '<table class="border" width="100%">';
  257. // Description
  258. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  259. print nl2br($object->description);
  260. print '</td></tr>';
  261. // Categories
  262. if($conf->categorie->enabled) {
  263. print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td>';
  264. print $form->showCategories($object->id,'project',1);
  265. print "</td></tr>";
  266. }
  267. print '</table>';
  268. print '</div>';
  269. print '</div>';
  270. print '</div>';
  271. print '<div class="clearboth"></div>';
  272. dol_fiche_end();
  273. }
  274. if ($action == 'create' && $user->rights->projet->creer && (empty($object->thirdparty->id) || $userWrite > 0))
  275. {
  276. if ($id > 0 || ! empty($ref)) print '<br>';
  277. print load_fiche_titre($langs->trans("NewTask"), '', 'title_project');
  278. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  279. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  280. print '<input type="hidden" name="action" value="createtask">';
  281. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  282. if (! empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
  283. dol_fiche_head('');
  284. print '<table class="border" width="100%">';
  285. $defaultref='';
  286. $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
  287. if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
  288. {
  289. require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
  290. $modTask = new $obj;
  291. $defaultref = $modTask->getNextValue($object->thirdparty,null);
  292. }
  293. if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
  294. // Ref
  295. print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>';
  296. print ($_POST["ref"]?$_POST["ref"]:$defaultref);
  297. print '<input type="hidden" name="taskref" value="'.($_POST["ref"]?$_POST["ref"]:$defaultref).'">';
  298. print '</td></tr>';
  299. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
  300. print '<input type="text" name="label" autofocus class="minwidth500" value="'.$label.'">';
  301. print '</td></tr>';
  302. // List of projects
  303. print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfProjectTask").'</td><td>';
  304. print $formother->selectProjectTasks(GETPOST('task_parent'),$projectid?$projectid:$object->id, 'task_parent', 0, 0, 1, 1);
  305. print '</td></tr>';
  306. print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
  307. $contactsofproject=(! empty($object->id)?$object->getListContactId('internal'):'');
  308. if (count($contactsofproject))
  309. {
  310. print $form->select_dolusers($user->id, 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, '', 'maxwidth300');
  311. }
  312. else
  313. {
  314. print $langs->trans("NoUserAssignedToTheProject");
  315. }
  316. print '</td></tr>';
  317. // Date start
  318. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  319. print $form->select_date(($date_start?$date_start:''),'dateo',1,1,0,'',1,1,1);
  320. print '</td></tr>';
  321. // Date end
  322. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  323. print $form->select_date(($date_end?$date_end:-1),'datee',-1,1,0,'',1,1,1);
  324. print '</td></tr>';
  325. // Planned workload
  326. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  327. print $form->select_duration('planned_workload', $planned_workload?$planned_workload : $object->planned_workload,0,'text');
  328. print '</td></tr>';
  329. // Progress
  330. print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
  331. print $formother->select_percent($progress,'progress',0,5,0,100,1);
  332. print '</td></tr>';
  333. // Description
  334. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  335. print '<td>';
  336. print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_4.'">'.$description.'</textarea>';
  337. print '</td></tr>';
  338. // Other options
  339. $parameters=array();
  340. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  341. print $hookmanager->resPrint;
  342. if (empty($reshook))
  343. {
  344. print $object->showOptionals($extrafields_task,'edit');
  345. }
  346. print '</table>';
  347. dol_fiche_end();
  348. print '<div align="center">';
  349. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  350. print ' &nbsp; &nbsp; ';
  351. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  352. print '</div>';
  353. print '</form>';
  354. }
  355. else if ($id > 0 || ! empty($ref))
  356. {
  357. /*
  358. * Projet card in view mode
  359. */
  360. // Definition of fields for list
  361. $arrayfields=array();
  362. $arrayfields['t.task_ref']=array('label'=>$langs->trans("RefTask"), 'checked'=>1);
  363. $arrayfields['t.task_label']=array('label'=>$langs->trans("LabelTask"), 'checked'=>1);
  364. $arrayfields['t.task_date_start']=array('label'=>$langs->trans("DateStart"), 'checked'=>1);
  365. $arrayfields['t.task_date_end']=array('label'=>$langs->trans("DateEnd"), 'checked'=>1);
  366. // Extra fields
  367. if (is_array($extrafields_task->attribute_label) && count($extrafields_task->attribute_label))
  368. {
  369. foreach($extrafields_task->attribute_label as $key => $val)
  370. {
  371. if (! empty($extrafields_task->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields_task->attribute_label[$key], 'checked'=>(($extrafields_task->attribute_list[$key]<0)?0:1), 'position'=>$extrafields_task->attribute_pos[$key], 'enabled'=>(abs($extrafields_task->attribute_list[$key])!=3 && $extrafields_task->attribute_perms[$key]));
  372. }
  373. }
  374. print '<br>';
  375. // Link to create task
  376. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  377. {
  378. if ($object->public || $userWrite > 0)
  379. {
  380. $linktocreatetask = '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create'.$param.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id).'">'.$langs->trans('AddTask').'</a>';
  381. }
  382. else
  383. {
  384. $linktocreatetask = '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  385. }
  386. }
  387. else
  388. {
  389. $linktocreatetask = '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('AddTask').'</a>';
  390. }
  391. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  392. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  393. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  394. print '<input type="hidden" name="action" value="list">';
  395. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  396. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  397. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  398. print '<input type="hidden" name="page" value="'.$page.'">';
  399. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  400. $title=$langs->trans("ListOfTasks");
  401. $linktotasks='<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$object->id.'&withproject=1">'.$langs->trans("GoToListOfTimeConsumed").'</a>';
  402. //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'title_generic.png', 0, '', '', 0, 1);
  403. print load_fiche_titre($title, $linktotasks.' &nbsp; '.$linktocreatetask, 'title_generic.png');
  404. // Get list of tasks in tasksarray and taskarrayfiltered
  405. // 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).
  406. $filteronthirdpartyid = $socid;
  407. $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0);
  408. // We load also tasks limited to a particular user
  409. $tmpuser=new User($db);
  410. if ($search_user_id > 0) $tmpuser->fetch($search_user_id);
  411. $tasksrole=($tmpuser->id > 0 ? $taskstatic->getUserRolesForProjectsOrTasks(0, $tmpuser, $object->id, 0) : '');
  412. //var_dump($tasksarray);
  413. //var_dump($tasksrole);
  414. if (! empty($conf->use_javascript_ajax))
  415. {
  416. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  417. }
  418. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  419. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  420. print '<div class="div-table-responsive">';
  421. print '<table id="tablelines" class="noborder" width="100%">';
  422. if (count($tasksarray) > 0)
  423. {
  424. // Link to switch in "my task" / "all task"
  425. print '<tr class="liste_titre_filter nodrag nodrop"><td colspan="8">';
  426. print $langs->trans("TasksAssignedTo");
  427. print $form->select_dolusers($tmpuser->id > 0 ? $tmpuser->id : '', 'search_user_id', 1);
  428. print '</td>';
  429. // Action column
  430. print '<td class="liste_titre" align="right">';
  431. $searchpicto=$form->showFilterButtons();
  432. print $searchpicto;
  433. print '</td>';
  434. }
  435. print '<tr class="liste_titre nodrag nodrop">';
  436. // print '<td>'.$langs->trans("Project").'</td>';
  437. print_liste_field_titre("RefTask", $_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'');
  438. print_liste_field_titre("LabelTask", $_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'');
  439. print_liste_field_titre("DateStart", $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'');
  440. print_liste_field_titre("DateEnd", $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'');
  441. print_liste_field_titre("PlannedWorkload", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'');
  442. print_liste_field_titre("TimeSpent", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'');
  443. print_liste_field_titre("ProgressCalculated", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'');
  444. print_liste_field_titre("ProgressDeclared", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'');
  445. //print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center" width="80"',$sortfield,$sortorder,'maxwidthsearch ');
  446. print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="center" width="80"',$sortfield,$sortorder,'maxwidthsearch ');
  447. print "</tr>\n";
  448. if (count($tasksarray) > 0)
  449. {
  450. // Show all lines in taskarray (recursive function to go down on tree)
  451. $j=0; $level=0;
  452. $nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $object->id, 1, $object->id);
  453. }
  454. else
  455. {
  456. print '<tr class="oddeven"><td colspan="9" class="opacitymedium">'.$langs->trans("NoTasks").'</td></tr>';
  457. }
  458. print "</table>";
  459. print '</div>';
  460. print '</form>';
  461. // Test if database is clean. If not we clean it.
  462. //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
  463. if (! empty($user->rights->projet->all->lire)) // We make test to clean only if user has permission to see all (test may report false positive otherwise)
  464. {
  465. if ($search_user_id == $user->id)
  466. {
  467. if ($nboftaskshown < count($tasksrole))
  468. {
  469. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  470. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  471. }
  472. }
  473. else
  474. {
  475. if ($nboftaskshown < count($tasksarray) && ! GETPOST('search_user_id','int'))
  476. {
  477. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  478. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  479. }
  480. }
  481. }
  482. }
  483. llxFooter();
  484. $db->close();