PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/tasks.php

https://github.com/atm-maximep/dolibarr
PHP | 470 lines | 313 code | 84 blank | 73 comment | 64 complexity | 64f80d29b20629fb63d1848925e4703d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, LGPL-3.0, GPL-2.0, GPL-3.0, CC-BY-SA-4.0, LGPL-2.1
  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. $extralabels_task=$extrafields_task->fetch_name_optionals_label($taskstatic->table_element);
  51. }
  52. // Security check
  53. $socid=0;
  54. if ($user->societe_id > 0) $socid = $user->societe_id;
  55. $result = restrictedArea($user, 'projet', $id);
  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. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")), 'errors');
  76. $action='create';
  77. $error++;
  78. }
  79. else if (empty($_POST['task_parent']))
  80. {
  81. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("ChildOfTask")), '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/index.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/index.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 width="30%">';
  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,$mine,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. // Other options
  206. $parameters=array();
  207. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  208. if (empty($reshook) && ! empty($extrafields_project->attribute_label))
  209. {
  210. print $object->showOptionals($extrafields_project);
  211. }
  212. print '</table>';
  213. dol_fiche_end();
  214. }
  215. if ($action == 'create' && $user->rights->projet->creer && (empty($object->thirdparty->id) || $userWrite > 0))
  216. {
  217. if ($id > 0 || ! empty($ref)) print '<br>';
  218. print_fiche_titre($langs->trans("NewTask"), '', 'title_project');
  219. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  220. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  221. print '<input type="hidden" name="action" value="createtask">';
  222. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  223. if (! empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
  224. if (! empty($mode)) print '<input type="hidden" name="mode" value="'.$mode.'">';
  225. dol_fiche_head('');
  226. print '<table class="border" width="100%">';
  227. $defaultref='';
  228. $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
  229. if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
  230. {
  231. require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
  232. $modTask = new $obj;
  233. $defaultref = $modTask->getNextValue($soc,$object);
  234. }
  235. if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
  236. // Ref
  237. print '<input type="hidden" name="ref" value="'.($_POST["ref"]?$_POST["ref"]:$defaultref).'">';
  238. print '<tr><td><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>'.($_POST["ref"]?$_POST["ref"]:$defaultref).'</td></tr>';
  239. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
  240. print '<input type="text" size="25" name="label" class="flat" value="'.$label.'">';
  241. print '</td></tr>';
  242. // List of projects
  243. print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfTask").'</td><td>';
  244. print $formother->selectProjectTasks(GETPOST('task_parent'),$projectid?$projectid:$object->id, 'task_parent', 0, 0, 1, 1);
  245. print '</td></tr>';
  246. print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
  247. $contactsofproject=(! empty($object->id)?$object->getListContactId('internal'):'');
  248. $form->select_users($user->id,'userid',0,'',0,'',$contactsofproject);
  249. print '</td></tr>';
  250. // Date start
  251. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  252. print $form->select_date(($date_start?$date_start:''),'dateo',1,1,0,'',1,1);
  253. print '</td></tr>';
  254. // Date end
  255. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  256. print $form->select_date(($date_end?$date_end:-1),'datee',1,1,0,'',1,1);
  257. print '</td></tr>';
  258. // planned workload
  259. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  260. print $form->select_duration('planned_workload', $planned_workload?$planned_workload : $object->planned_workload,0,'text');
  261. print '</td></tr>';
  262. // Progress
  263. print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
  264. print $formother->select_percent($progress,'progress');
  265. print '</td></tr>';
  266. // Description
  267. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  268. print '<td>';
  269. print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$description.'</textarea>';
  270. print '</td></tr>';
  271. // Other options
  272. $parameters=array();
  273. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  274. if (empty($reshook) && ! empty($extrafields_task->attribute_label))
  275. {
  276. print $object->showOptionals($extrafields_task,'edit');
  277. }
  278. print '</table>';
  279. dol_fiche_end();
  280. print '<div align="center">';
  281. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  282. print ' &nbsp; &nbsp; ';
  283. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  284. print '</div>';
  285. print '</form>';
  286. }
  287. else if ($id > 0 || ! empty($ref))
  288. {
  289. /*
  290. * Fiche projet en mode visu
  291. */
  292. /*
  293. * Actions
  294. */
  295. print '<div class="tabsAction">';
  296. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  297. {
  298. if ($object->public || $userWrite > 0)
  299. {
  300. 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>';
  301. }
  302. else
  303. {
  304. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  305. }
  306. }
  307. else
  308. {
  309. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('AddTask').'</a>';
  310. }
  311. print '</div>';
  312. print '<br>';
  313. // Link to switch in "my task" / "all task"
  314. print '<table width="100%"><tr><td align="right">';
  315. if ($mode == 'mine')
  316. {
  317. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">'.$langs->trans("DoNotShowMyTasksOnly").'</a>';
  318. //print ' - ';
  319. //print $langs->trans("ShowMyTaskOnly");
  320. }
  321. else
  322. {
  323. //print $langs->trans("DoNotShowMyTaskOnly");
  324. //print ' - ';
  325. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mode=mine">'.$langs->trans("ShowMyTasksOnly").'</a>';
  326. }
  327. print '</td></tr></table>';
  328. // Get list of tasks in tasksarray and taskarrayfiltered
  329. // 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).
  330. $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0);
  331. // We load also tasks limited to a particular user
  332. $tasksrole=($mode=='mine' ? $taskstatic->getUserRolesForProjectsOrTasks(0,$user,$object->id,0) : '');
  333. //var_dump($tasksarray);
  334. //var_dump($tasksrole);
  335. if (! empty($conf->use_javascript_ajax))
  336. {
  337. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  338. }
  339. print '<table id="tablelines" class="noborder" width="100%">';
  340. print '<tr class="liste_titre nodrag nodrop">';
  341. // print '<td>'.$langs->trans("Project").'</td>';
  342. print '<td width="100">'.$langs->trans("RefTask").'</td>';
  343. print '<td>'.$langs->trans("LabelTask").'</td>';
  344. print '<td align="center">'.$langs->trans("DateStart").'</td>';
  345. print '<td align="center">'.$langs->trans("DateEnd").'</td>';
  346. print '<td align="right">'.$langs->trans("PlannedWorkload").'</td>';
  347. print '<td align="right">'.$langs->trans("ProgressDeclared").'</td>';
  348. print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
  349. print '<td align="right">'.$langs->trans("ProgressCalculated").'</td>';
  350. print '<td>&nbsp;</td>';
  351. print "</tr>\n";
  352. if (count($tasksarray) > 0)
  353. {
  354. // Show all lines in taskarray (recursive function to go down on tree)
  355. $j=0; $level=0;
  356. $nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $id, 1);
  357. }
  358. else
  359. {
  360. print '<tr><td colspan="9">'.$langs->trans("NoTasks").'</td></tr>';
  361. }
  362. print "</table>";
  363. // Test if database is clean. If not we clean it.
  364. //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
  365. 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)
  366. {
  367. if ($mode=='mine')
  368. {
  369. if ($nboftaskshown < count($tasksrole))
  370. {
  371. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  372. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  373. }
  374. }
  375. else
  376. {
  377. if ($nboftaskshown < count($tasksarray))
  378. {
  379. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  380. cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
  381. }
  382. }
  383. }
  384. }
  385. llxFooter();
  386. $db->close();