tasks.php 29 KB

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