PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/tasks/task.php

https://bitbucket.org/speedealing/speedealing
PHP | 413 lines | 251 code | 73 blank | 89 comment | 52 complexity | 1b96d34dff653666f42f809e60f41b2b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010-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/task.php
  21. * \ingroup project
  22. * \brief Page of a project task
  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/class/html.formother.class.php';
  29. $id=GETPOST('id','int');
  30. $ref=GETPOST('ref','alpha');
  31. $action=GETPOST('action','alpha');
  32. $confirm=GETPOST('confirm','alpha');
  33. $withproject=GETPOST('withproject','int');
  34. $project_ref=GETPOST('project_ref','alpha');
  35. // Security check
  36. $socid=0;
  37. if ($user->societe_id > 0) $socid = $user->societe_id;
  38. if (! $user->rights->projet->lire) accessforbidden();
  39. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  40. $hookmanager->initHooks(array('projecttaskcard'));
  41. $object = new Task($db);
  42. $projectstatic = new Project($db);
  43. /*
  44. * Actions
  45. */
  46. if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
  47. {
  48. $error=0;
  49. if (empty($_POST["label"]))
  50. {
  51. $error++;
  52. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
  53. }
  54. if (! $error)
  55. {
  56. $object->fetch($id);
  57. $tmparray=explode('_',$_POST['task_parent']);
  58. $task_parent=$tmparray[1];
  59. if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
  60. $object->label = $_POST["label"];
  61. $object->description = $_POST['description'];
  62. $object->fk_task_parent = $task_parent;
  63. $object->date_start = dol_mktime(0,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']);
  64. $object->date_end = dol_mktime(0,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']);
  65. $object->progress = $_POST['progress'];
  66. $result=$object->update($user);
  67. }
  68. else
  69. {
  70. $action='edit';
  71. }
  72. }
  73. if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->projet->supprimer)
  74. {
  75. if ($object->fetch($id) >= 0 )
  76. {
  77. $result=$projectstatic->fetch($object->fk_projet);
  78. if (! empty($projectstatic->socid))
  79. {
  80. $projectstatic->societe->fetch($projectstatic->socid);
  81. }
  82. if ($object->delete($user) > 0)
  83. {
  84. header("Location: index.php");
  85. exit;
  86. }
  87. else
  88. {
  89. $langs->load("errors");
  90. $mesg='<div class="error">'.$langs->trans($object->error).'</div>';
  91. $action='';
  92. }
  93. }
  94. }
  95. // Retreive First Task ID of Project if withprojet is on to allow project prev next to work
  96. if (! empty($project_ref) && ! empty($withproject))
  97. {
  98. if ($projectstatic->fetch('',$project_ref) > 0)
  99. {
  100. $tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
  101. if (count($tasksarray) > 0)
  102. {
  103. $id=$tasksarray[0]->id;
  104. }
  105. else
  106. {
  107. header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode)?'':'&mode='.$mode));
  108. }
  109. }
  110. }
  111. /*
  112. * View
  113. */
  114. $langs->load('projects');
  115. llxHeader('', $langs->trans("Task"));
  116. $form = new Form($db);
  117. $formother = new FormOther($db);
  118. if ($id > 0 || ! empty($ref))
  119. {
  120. if ($object->fetch($id) > 0)
  121. {
  122. $result=$projectstatic->fetch($object->fk_project);
  123. if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
  124. $userWrite = $projectstatic->restrictedProjectArea($user,'write');
  125. if (! empty($withproject))
  126. {
  127. // Tabs for project
  128. $tab='tasks';
  129. $head=project_prepare_head($projectstatic);
  130. dol_fiche_head($head, $tab, $langs->trans("Project"),0,($projectstatic->public?'projectpub':'project'));
  131. $param=($mode=='mine'?'&mode=mine':'');
  132. print '<table class="border" width="100%">';
  133. // Ref
  134. print '<tr><td width="30%">';
  135. print $langs->trans("Ref");
  136. print '</td><td>';
  137. // Define a complementary filter for search of next/prev ref.
  138. if (! $user->rights->projet->all->lire)
  139. {
  140. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0);
  141. $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
  142. }
  143. print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1');
  144. print '</td></tr>';
  145. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projectstatic->title.'</td></tr>';
  146. print '<tr><td>'.$langs->trans("Company").'</td><td>';
  147. if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1);
  148. else print '&nbsp;';
  149. print '</td>';
  150. print '</tr>';
  151. // Visibility
  152. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  153. if ($projectstatic->public) print $langs->trans('SharedProject');
  154. else print $langs->trans('PrivateProject');
  155. print '</td></tr>';
  156. // Statut
  157. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projectstatic->getLibStatut(4).'</td></tr>';
  158. print '</table>';
  159. dol_fiche_end();
  160. print '<br>';
  161. }
  162. /*
  163. * Actions
  164. */
  165. /*print '<div class="tabsAction">';
  166. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  167. {
  168. if ($projectstatic->public || $userWrite > 0)
  169. {
  170. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create'.$param.'">'.$langs->trans('AddTask').'</a>';
  171. }
  172. else
  173. {
  174. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  175. }
  176. }
  177. else
  178. {
  179. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NoPermission").'">'.$langs->trans('AddTask').'</a>';
  180. }
  181. print '</div>';
  182. */
  183. // To verify role of users
  184. //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
  185. //$arrayofuseridoftask=$object->getListContactId('internal');
  186. dol_htmloutput_mesg($mesg);
  187. $head=task_prepare_head($object);
  188. dol_fiche_head($head, 'task_task', $langs->trans("Task"),0,'projecttask');
  189. if ($action == 'edit' && $user->rights->projet->creer)
  190. {
  191. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  192. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  193. print '<input type="hidden" name="action" value="update">';
  194. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  195. print '<input type="hidden" name="id" value="'.$object->id.'">';
  196. print '<table class="border" width="100%">';
  197. // Ref
  198. print '<tr><td width="30%">'.$langs->trans("Ref").'</td>';
  199. print '<td>'.$object->ref.'</td></tr>';
  200. // Label
  201. print '<tr><td>'.$langs->trans("Label").'</td>';
  202. print '<td><input size="30" name="label" value="'.$object->label.'"></td></tr>';
  203. // Project
  204. if (empty($withproject))
  205. {
  206. print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
  207. print $projectstatic->getNomUrl(1);
  208. print '</td></tr>';
  209. // Third party
  210. print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
  211. if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
  212. else print '&nbsp;';
  213. print '</td></tr>';
  214. }
  215. // Task parent
  216. print '<tr><td>'.$langs->trans("ChildOfTask").'</td><td>';
  217. print $formother->selectProjectTasks($object->fk_task_parent,$projectstatic->id, 'task_parent', $user->admin?0:1, 0);
  218. print '</td></tr>';
  219. // Date start
  220. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  221. print $form->select_date($object->date_start,'dateo');
  222. print '</td></tr>';
  223. // Date end
  224. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  225. print $form->select_date($object->date_end?$object->date_end:-1,'datee');
  226. print '</td></tr>';
  227. // Progress
  228. print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
  229. print $formother->select_percent($object->progress,'progress');
  230. print '</td></tr>';
  231. // Description
  232. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  233. print '<td>';
  234. print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$object->description.'</textarea>';
  235. print '</td></tr>';
  236. // Other options
  237. $parameters=array();
  238. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  239. print '</table>';
  240. print '<center><br>';
  241. print '<input type="submit" class="button" name="update" value="'.$langs->trans("Modify").'"> &nbsp; ';
  242. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  243. print '<center>';
  244. print '</form>';
  245. }
  246. else
  247. {
  248. /*
  249. * Fiche tache en mode visu
  250. */
  251. $param=($withproject?'&withproject=1':'');
  252. $linkback=$withproject?'<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>':'';
  253. if ($action == 'delete')
  254. {
  255. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"].'&withproject='.$withproject,$langs->trans("DeleteATask"),$langs->trans("ConfirmDeleteATask"),"confirm_delete");
  256. if ($ret == 'html') print '<br>';
  257. }
  258. print '<table class="border" width="100%">';
  259. // Ref
  260. print '<tr><td width="30%">';
  261. print $langs->trans("Ref");
  262. print '</td><td colspan="3">';
  263. if (! GETPOST('withproject') || empty($projectstatic->id))
  264. {
  265. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1);
  266. $object->next_prev_filter=" fk_projet in (".$projectsListId.")";
  267. }
  268. else $object->next_prev_filter=" fk_projet = ".$projectstatic->id;
  269. print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param);
  270. print '</td>';
  271. print '</tr>';
  272. // Label
  273. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$object->label.'</td></tr>';
  274. // Project
  275. if (empty($withproject))
  276. {
  277. print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
  278. print $projectstatic->getNomUrl(1);
  279. print '</td></tr>';
  280. // Third party
  281. print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
  282. if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
  283. else print '&nbsp;';
  284. print '</td></tr>';
  285. }
  286. // Date start
  287. print '<tr><td>'.$langs->trans("DateStart").'</td><td colspan="3">';
  288. print dol_print_date($object->date_start,'day');
  289. print '</td></tr>';
  290. // Date end
  291. print '<tr><td>'.$langs->trans("DateEnd").'</td><td colspan="3">';
  292. print dol_print_date($object->date_end,'day');
  293. print '</td></tr>';
  294. // Progress
  295. print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
  296. print $object->progress.' %';
  297. print '</td></tr>';
  298. // Description
  299. print '<td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
  300. print nl2br($object->description);
  301. print '</td></tr>';
  302. // Other options
  303. $parameters=array();
  304. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  305. print '</table>';
  306. }
  307. dol_fiche_end();
  308. if ($_GET["action"] != 'edit')
  309. {
  310. /*
  311. * Actions
  312. */
  313. print '<div class="tabsAction">';
  314. // Modify
  315. if ($user->rights->projet->creer)
  316. {
  317. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit&amp;withproject='.$withproject.'">'.$langs->trans('Modify').'</a>';
  318. }
  319. else
  320. {
  321. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Modify').'</a>';
  322. }
  323. // Delete
  324. if ($user->rights->projet->supprimer && ! $object->hasChildren())
  325. {
  326. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete&amp;withproject='.$withproject.'">'.$langs->trans('Delete').'</a>';
  327. }
  328. else
  329. {
  330. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
  331. }
  332. print '</div>';
  333. }
  334. }
  335. }
  336. llxFooter();
  337. $db->close();
  338. ?>