PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/projet/tasks.php

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