PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/tasks/task.php

https://github.com/asterix14/dolibarr
PHP | 301 lines | 186 code | 58 blank | 57 comment | 36 complexity | c0e39c180add9e72dea80e492f000860 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  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 2 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 projet
  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. $taskid = GETPOST("id");
  30. $taskref = GETPOST("ref");
  31. // Security check
  32. $socid=0;
  33. if ($user->societe_id > 0) $socid = $user->societe_id;
  34. if (!$user->rights->projet->lire) accessforbidden();
  35. /*
  36. * Actions
  37. */
  38. if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
  39. {
  40. $error=0;
  41. if (empty($_POST["label"]))
  42. {
  43. $error++;
  44. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
  45. }
  46. if (! $error)
  47. {
  48. $task = new Task($db);
  49. $task->fetch($_POST["id"]);
  50. $tmparray=explode('_',$_POST['task_parent']);
  51. $task_parent=$tmparray[1];
  52. if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
  53. $task->label = $_POST["label"];
  54. $task->description = $_POST['description'];
  55. $task->fk_task_parent = $task_parent;
  56. $task->date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']);
  57. $task->date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']);
  58. $task->progress = $_POST['progress'];
  59. $result=$task->update($user);
  60. $taskid=$task->id; // On retourne sur la fiche tache
  61. }
  62. else
  63. {
  64. $taskid=$_POST["id"];
  65. $_GET['action']='edit';
  66. }
  67. }
  68. if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->projet->supprimer)
  69. {
  70. $task = new Task($db);
  71. if ($task->fetch($_GET["id"]) >= 0 )
  72. {
  73. $projet = new Project($db);
  74. $result=$projet->fetch($task->fk_projet);
  75. if (! empty($projet->socid))
  76. {
  77. $projet->societe->fetch($projet->socid);
  78. }
  79. if ($task->delete($user) > 0)
  80. {
  81. Header("Location: index.php");
  82. exit;
  83. }
  84. else
  85. {
  86. $langs->load("errors");
  87. $mesg='<div class="error">'.$langs->trans($task->error).'</div>';
  88. $_POST["action"]='';
  89. }
  90. }
  91. }
  92. /*
  93. * View
  94. */
  95. llxHeader("",$langs->trans("Task"));
  96. $form = new Form($db);
  97. $formother = new FormOther($db);
  98. $project = new Project($db);
  99. if ($taskid)
  100. {
  101. $task = new Task($db);
  102. $projectstatic = new Project($db);
  103. if ($task->fetch($taskid) >= 0 )
  104. {
  105. $result=$projectstatic->fetch($task->fk_project);
  106. if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
  107. // To verify role of users
  108. //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
  109. //$arrayofuseridoftask=$task->getListContactId('internal');
  110. dol_htmloutput_mesg($mesg);
  111. $head=task_prepare_head($task);
  112. dol_fiche_head($head, 'task', $langs->trans("Task"),0,'projecttask');
  113. if ($_GET["action"] == 'edit' && $user->rights->projet->creer)
  114. {
  115. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  116. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  117. print '<input type="hidden" name="action" value="update">';
  118. print '<input type="hidden" name="id" value="'.$task->id.'">';
  119. print '<table class="border" width="100%">';
  120. // Ref
  121. print '<tr><td width="30%">'.$langs->trans("Ref").'</td>';
  122. print '<td>'.$task->ref.'</td></tr>';
  123. // Label
  124. print '<tr><td>'.$langs->trans("Label").'</td>';
  125. print '<td><input size="30" name="label" value="'.$task->label.'"></td></tr>';
  126. // Project
  127. print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
  128. print $projectstatic->getNomUrl(1);
  129. print '</td></tr>';
  130. // Third party
  131. print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
  132. if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
  133. else print '&nbsp;';
  134. print '</td></tr>';
  135. // Task parent
  136. print '<tr><td>'.$langs->trans("ChildOfTask").'</td><td>';
  137. print $formother->selectProjectTasks($task->fk_task_parent,$projectstatic->id, 'task_parent', $user->admin?0:1, 0);
  138. print '</td></tr>';
  139. // Date start
  140. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  141. print $form->select_date($task->date_start,'dateo');
  142. print '</td></tr>';
  143. // Date end
  144. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  145. print $form->select_date($task->date_end?$task->date_end:-1,'datee');
  146. print '</td></tr>';
  147. // Progress
  148. print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
  149. print $formother->select_percent($task->progress,'progress');
  150. print '</td></tr>';
  151. // Description
  152. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  153. print '<td>';
  154. print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$task->description.'</textarea>';
  155. print '</td></tr>';
  156. print '</table>';
  157. print '<center><br>';
  158. print '<input type="submit" class="button" name="update" value="'.$langs->trans("Modify").'"> &nbsp; ';
  159. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  160. print '<center>';
  161. print '</form>';
  162. }
  163. else
  164. {
  165. /*
  166. * Fiche tache en mode visu
  167. */
  168. if ($_GET["action"] == 'delete')
  169. {
  170. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],$langs->trans("DeleteATask"),$langs->trans("ConfirmDeleteATask"),"confirm_delete");
  171. if ($ret == 'html') print '<br>';
  172. }
  173. print '<table class="border" width="100%">';
  174. // Ref
  175. print '<tr><td width="30%">';
  176. print $langs->trans("Ref");
  177. print '</td><td colspan="3">';
  178. $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
  179. $task->next_prev_filter=" fk_projet in (".$projectsListId.")";
  180. print $form->showrefnav($task,'id','',1,'rowid','ref','','');
  181. print '</td>';
  182. print '</tr>';
  183. // Label
  184. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$task->label.'</td></tr>';
  185. // Project
  186. print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
  187. print $projectstatic->getNomUrl(1);
  188. print '</td></tr>';
  189. // Third party
  190. print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
  191. if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
  192. else print '&nbsp;';
  193. print '</td></tr>';
  194. // Date start
  195. print '<tr><td>'.$langs->trans("DateStart").'</td><td colspan="3">';
  196. print dol_print_date($task->date_start,'day');
  197. print '</td></tr>';
  198. // Date end
  199. print '<tr><td>'.$langs->trans("DateEnd").'</td><td colspan="3">';
  200. print dol_print_date($task->date_end,'day');
  201. print '</td></tr>';
  202. // Progress
  203. print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
  204. print $task->progress.' %';
  205. print '</td></tr>';
  206. // Description
  207. print '<td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
  208. print nl2br($task->description);
  209. print '</td></tr>';
  210. print '</table>';
  211. }
  212. dol_fiche_end();
  213. if ($_GET["action"] != 'edit')
  214. {
  215. /*
  216. * Actions
  217. */
  218. print '<div class="tabsAction">';
  219. // Modify
  220. if ($user->rights->projet->creer)
  221. {
  222. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$task->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
  223. }
  224. else
  225. {
  226. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Modify').'</a>';
  227. }
  228. // Delete
  229. if ($user->rights->projet->supprimer && ! $task->hasChildren())
  230. {
  231. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$task->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
  232. }
  233. else
  234. {
  235. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
  236. }
  237. print '</div>';
  238. }
  239. }
  240. }
  241. $db->close();
  242. llxFooter();
  243. ?>