tasks.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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-2012 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. $action = GETPOST('action', 'alpha');
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $backtopage=GETPOST('backtopage','alpha');
  37. $cancel=GETPOST('cancel');
  38. $mode = GETPOST('mode', 'alpha');
  39. $mine = ($mode == 'mine' ? 1 : 0);
  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;
  55. $result = restrictedArea($user, 'projet', $id,'projet&project');
  56. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  57. $hookmanager->initHooks(array('projecttaskcard','globalcard'));
  58. $progress=GETPOST('progress', 'int');
  59. $label=GETPOST('label', 'alpha');
  60. $description=GETPOST('description');
  61. $planned_workload=GETPOST('planned_workloadhour')*3600+GETPOST('planned_workloadmin')*60;
  62. $userAccess=0;
  63. /*
  64. * Actions
  65. */
  66. if ($action == 'createtask' && $user->rights->projet->creer)
  67. {
  68. $error=0;
  69. $date_start = dol_mktime($_POST['dateohour'],$_POST['dateomin'],0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear'],'user');
  70. $date_end = dol_mktime($_POST['dateehour'],$_POST['dateemin'],0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear'],'user');
  71. if (! $cancel)
  72. {
  73. if (empty($label))
  74. {
  75. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  76. $action='create';
  77. $error++;
  78. }
  79. else if (empty($_POST['task_parent']))
  80. {
  81. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ChildOfTask")), null, 'errors');
  82. $action='create';
  83. $error++;
  84. }
  85. if (! $error)
  86. {
  87. $tmparray=explode('_',$_POST['task_parent']);
  88. $projectid=$tmparray[0];
  89. if (empty($projectid)) $projectid = $id; // If projectid is ''
  90. $task_parent=$tmparray[1];
  91. if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
  92. $task = new Task($db);
  93. $task->fk_project = $projectid;
  94. $task->ref = GETPOST('ref','alpha');
  95. $task->label = $label;
  96. $task->description = $description;
  97. $task->planned_workload = $planned_workload;
  98. $task->fk_task_parent = $task_parent;
  99. $task->date_c = dol_now();
  100. $task->date_start = $date_start;
  101. $task->date_end = $date_end;
  102. $task->progress = $progress;
  103. // Fill array 'array_options' with data from add form
  104. $ret = $extrafields_task->setOptionalsFromPost($extralabels_task,$task);
  105. $taskid = $task->create($user);
  106. if ($taskid > 0)
  107. {
  108. $result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
  109. }
  110. else
  111. {
  112. setEventMessages($task->error,$task->errors,'errors');
  113. }
  114. }
  115. if (! $error)
  116. {
  117. if (! empty($backtopage))
  118. {
  119. header("Location: ".$backtopage);
  120. exit;
  121. }
  122. else if (empty($projectid))
  123. {
  124. header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode)?'':'?mode='.$mode));
  125. exit;
  126. }
  127. $id = $projectid;
  128. }
  129. }
  130. else
  131. {
  132. if (! empty($backtopage))
  133. {
  134. header("Location: ".$backtopage);
  135. exit;
  136. }
  137. else if (empty($id))
  138. {
  139. // We go back on task list
  140. header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode)?'':'?mode='.$mode));
  141. exit;
  142. }
  143. }
  144. }
  145. /*
  146. * View
  147. */
  148. $form=new Form($db);
  149. $formother=new FormOther($db);
  150. $taskstatic = new Task($db);
  151. $userstatic=new User($db);
  152. $title=$langs->trans("Project").' - '.$langs->trans("Tasks").' - '.$object->ref.' '.$object->name;
  153. 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");
  154. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  155. llxHeader("",$title,$help_url);
  156. if ($id > 0 || ! empty($ref))
  157. {
  158. $object->fetch($id, $ref);
  159. $object->fetch_thirdparty();
  160. $res=$object->fetch_optionals($object->id,$extralabels_projet);
  161. // To verify role of users
  162. //$userAccess = $object->restrictedProjectArea($user,'read');
  163. $userWrite = $object->restrictedProjectArea($user,'write');
  164. //$userDelete = $object->restrictedProjectArea($user,'delete');
  165. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  166. $tab=GETPOST('tab')?GETPOST('tab'):'tasks';
  167. $head=project_prepare_head($object);
  168. dol_fiche_head($head, $tab, $langs->trans("Project"),0,($object->public?'projectpub':'project'));
  169. $param=($mode=='mine'?'&mode=mine':'');
  170. print '<table class="border" width="100%">';
  171. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
  172. // Ref
  173. print '<tr><td class="titlefield">';
  174. print $langs->trans("Ref");
  175. print '</td><td>';
  176. // Define a complementary filter for search of next/prev ref.
  177. if (! $user->rights->projet->all->lire)
  178. {
  179. $projectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
  180. $object->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
  181. }
  182. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '', $param);
  183. print '</td></tr>';
  184. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->title.'</td></tr>';
  185. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  186. if (! empty($object->thirdparty->id)) print $object->thirdparty->getNomUrl(1);
  187. else print '&nbsp;';
  188. print '</td>';
  189. print '</tr>';
  190. // Visibility
  191. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  192. if ($object->public) print $langs->trans('SharedProject');
  193. else print $langs->trans('PrivateProject');
  194. print '</td></tr>';
  195. // Statut
  196. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  197. // Date start
  198. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  199. print dol_print_date($object->date_start,'day');
  200. print '</td></tr>';
  201. // Date end
  202. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  203. print dol_print_date($object->date_end,'day');
  204. print '</td></tr>';
  205. // Budget
  206. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  207. if (strcmp($object->budget_amount, '')) print price($object->budget_amount,'',$langs,0,0,0,$conf->currency);
  208. print '</td></tr>';
  209. // Other options
  210. $parameters=array();
  211. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  212. if (empty($reshook) && ! empty($extrafields_project->attribute_label))
  213. {
  214. print $object->showOptionals($extrafields_project);
  215. }
  216. print '</table>';
  217. dol_fiche_end();
  218. }
  219. if ($action == 'create' && $user->rights->projet->creer && (empty($object->thirdparty->id) || $userWrite > 0))
  220. {
  221. if ($id > 0 || ! empty($ref)) print '<br>';
  222. print load_fiche_titre($langs->trans("NewTask"), '', 'title_project');
  223. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  224. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  225. print '<input type="hidden" name="action" value="createtask">';
  226. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  227. if (! empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
  228. if (! empty($mode)) print '<input type="hidden" name="mode" value="'.$mode.'">';
  229. print '<input type="hidden" name="ref" value="'.($_POST["ref"]?$_POST["ref"]:$defaultref).'">';
  230. dol_fiche_head('');
  231. print '<table class="border" width="100%">';
  232. $defaultref='';
  233. $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
  234. if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
  235. {
  236. require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
  237. $modTask = new $obj;
  238. $defaultref = $modTask->getNextValue($soc,$object);
  239. }
  240. if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
  241. // Ref
  242. print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>'.($_POST["ref"]?$_POST["ref"]:$defaultref).'</td></tr>';
  243. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
  244. print '<input type="text" size="25" name="label" class="flat" value="'.$label.'">';
  245. print '</td></tr>';
  246. // List of projects
  247. print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfTask").'</td><td>';
  248. print $formother->selectProjectTasks(GETPOST('task_parent'),$projectid?$projectid:$object->id, 'task_parent', 0, 0, 1, 1);
  249. print '</td></tr>';
  250. print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
  251. $contactsofproject=(! empty($object->id)?$object->getListContactId('internal'):'');
  252. if (count($contactsofproject))
  253. {
  254. print $form->select_dolusers($user->id, 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, '', 'maxwidth300');
  255. }
  256. else
  257. {
  258. print $langs->trans("NoUserAssignedToTheProject");
  259. }
  260. print '</td></tr>';
  261. // Date start
  262. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  263. print $form->select_date(($date_start?$date_start:''),'dateo',1,1,0,'',1,1,1);
  264. print '</td></tr>';
  265. // Date end
  266. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  267. print $form->select_date(($date_end?$date_end:-1),'datee',1,1,0,'',1,1,1);
  268. print '</td></tr>';
  269. // planned workload
  270. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  271. print $form->select_duration('planned_workload', $planned_workload?$planned_workload : $object->planned_workload,0,'text');
  272. print '</td></tr>';
  273. // Progress
  274. print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
  275. print $formother->select_percent($progress,'progress');
  276. print '</td></tr>';
  277. // Description
  278. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  279. print '<td>';
  280. print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$description.'</textarea>';
  281. print '</td></tr>';
  282. // Other options
  283. $parameters=array();
  284. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  285. if (empty($reshook) && ! empty($extrafields_task->attribute_label))
  286. {
  287. print $object->showOptionals($extrafields_task,'edit');
  288. }
  289. print '</table>';
  290. dol_fiche_end();
  291. print '<div align="center">';
  292. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  293. print ' &nbsp; &nbsp; ';
  294. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  295. print '</div>';
  296. print '</form>';
  297. }
  298. else if ($id > 0 || ! empty($ref))
  299. {
  300. /*
  301. * Fiche projet en mode visu
  302. */
  303. /*
  304. * Actions
  305. */
  306. print '<div class="tabsAction">';
  307. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  308. {
  309. if ($object->public || $userWrite > 0)
  310. {
  311. print '<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>';
  312. }
  313. else
  314. {
  315. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  316. }
  317. }
  318. else
  319. {
  320. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('AddTask').'</a>';
  321. }
  322. print '</div>';
  323. $title=$langs->trans("ListOfTasks");
  324. $linktotasks='<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$object->id.'&withproject=1">'.$langs->trans("GoToListOfTimeConsumed").'</a>';
  325. //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'title_generic.png', 0, '', '', 0, 1);
  326. print load_fiche_titre($title,$linktotasks,'title_generic.png');
  327. // Get list of tasks in tasksarray and taskarrayfiltered
  328. // 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).
  329. $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0);
  330. // We load also tasks limited to a particular user
  331. $tasksrole=($mode=='mine' ? $taskstatic->getUserRolesForProjectsOrTasks(0,$user,$object->id,0) : '');
  332. //var_dump($tasksarray);
  333. //var_dump($tasksrole);
  334. if (! empty($conf->use_javascript_ajax))
  335. {
  336. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  337. }
  338. print '<table id="tablelines" class="noborder" width="100%">';
  339. print '<tr class="liste_titre nodrag nodrop">';
  340. // print '<td>'.$langs->trans("Project").'</td>';
  341. print '<td width="100">'.$langs->trans("RefTask").'</td>';
  342. print '<td>'.$langs->trans("LabelTask").'</td>';
  343. print '<td align="center">'.$langs->trans("DateStart").'</td>';
  344. print '<td align="center">'.$langs->trans("DateEnd").'</td>';
  345. print '<td align="right">'.$langs->trans("PlannedWorkload").'</td>';
  346. print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
  347. print '<td align="right">'.$langs->trans("ProgressCalculated").'</td>';
  348. print '<td align="right">'.$langs->trans("ProgressDeclared").'</td>';
  349. print '<td>&nbsp;</td>';
  350. print "</tr>\n";
  351. if (count($tasksarray) > 0)
  352. {
  353. // Link to switch in "my task" / "all task"
  354. print '<tr class="liste_titre nodrag nodrop"><td colspan="9">';
  355. if ($mode == 'mine')
  356. {
  357. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">'.$langs->trans("DoNotShowMyTasksOnly").'</a>';
  358. }
  359. else
  360. {
  361. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mode=mine">'.$langs->trans("ShowMyTasksOnly").'</a>';
  362. }
  363. print '</td></tr>';
  364. // Show all lines in taskarray (recursive function to go down on tree)
  365. $j=0; $level=0;
  366. $nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $object->id, 1, $object->id);
  367. }
  368. else
  369. {
  370. print '<tr '.$bc[false].'><td colspan="9" class="opacitymedium">'.$langs->trans("NoTasks").'</td></tr>';
  371. }
  372. print "</table>";
  373. // Test if database is clean. If not we clean it.
  374. //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
  375. 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)
  376. {
  377. if ($mode=='mine')
  378. {
  379. if ($nboftaskshown < count($tasksrole))
  380. {
  381. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  382. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  383. }
  384. }
  385. else
  386. {
  387. if ($nboftaskshown < count($tasksarray))
  388. {
  389. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  390. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  391. }
  392. }
  393. }
  394. }
  395. llxFooter();
  396. $db->close();