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

/htdocs/projet/tasks.php

https://github.com/asterix14/dolibarr
PHP | 346 lines | 222 code | 62 blank | 62 comment | 42 complexity | 6c5a686ba72c01a84ec4d832ab0d9d32 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-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.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. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  31. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  32. // Security check
  33. $socid=0;
  34. if ($user->societe_id > 0) $socid = $user->societe_id;
  35. //$result = restrictedArea($user, 'projet', $projectid);
  36. if (!$user->rights->projet->lire) accessforbidden();
  37. $langs->load("users");
  38. $langs->load("projects");
  39. $progress=GETPOST('progress');
  40. $description=GETPOST('description');
  41. $userAccess=0;
  42. /*
  43. * Actions
  44. */
  45. if ($_POST["action"] == 'createtask' && $user->rights->projet->creer)
  46. {
  47. $error=0;
  48. $date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']);
  49. $date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']);
  50. if (empty($_POST["cancel"]))
  51. {
  52. if (empty($_POST['label']))
  53. {
  54. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
  55. $_GET["action"]='create';
  56. $error++;
  57. }
  58. else if (empty($_POST['task_parent']))
  59. {
  60. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("ChildOfTask"));
  61. $_GET["action"]='create';
  62. $error++;
  63. }
  64. if (! $error)
  65. {
  66. $tmparray=explode('_',$_POST['task_parent']);
  67. $projectid=$tmparray[0];
  68. if (empty($projectid)) $projectid = $_POST["id"]; // If projectid is ''
  69. $task_parent=$tmparray[1];
  70. if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
  71. $task = new Task($db);
  72. $task->fk_project = $projectid;
  73. $task->label = $_POST["label"];
  74. $task->description = $_POST['description'];
  75. $task->fk_task_parent = $task_parent;
  76. $task->date_c = dol_now();
  77. $task->date_start = $date_start;
  78. $task->date_end = $date_end;
  79. $task->progress = $_POST['progress'];
  80. $taskid = $task->create($user);
  81. if ($taskid > 0)
  82. {
  83. $result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
  84. }
  85. }
  86. if (! $error)
  87. {
  88. if (empty($projectid))
  89. {
  90. Header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($_REQUEST["mode"])?'':'?mode='.$_REQUEST["mode"]));
  91. exit;
  92. }
  93. else
  94. {
  95. Header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$taskid);
  96. exit;
  97. }
  98. }
  99. }
  100. else
  101. {
  102. if (empty($_GET["id"]) && empty($_POST["id"]))
  103. {
  104. // We go back on task list
  105. Header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($_REQUEST["mode"])?'':'?mode='.$_REQUEST["mode"]));
  106. exit;
  107. }
  108. }
  109. }
  110. /*
  111. * View
  112. */
  113. $form=new Form($db);
  114. $formother=new FormOther($db);
  115. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  116. llxHeader("",$langs->trans("Tasks"),$help_url);
  117. $task = new Task($db);
  118. $id = (! empty($_GET['id']))?$_GET['id']:$_POST['id'];
  119. $ref= $_GET['ref'];
  120. if ($id > 0 || ! empty($ref))
  121. {
  122. $project = new Project($db);
  123. $project->fetch($_REQUEST["id"],$_GET["ref"]);
  124. if ($project->societe->id > 0) $result=$project->societe->fetch($project->societe->id);
  125. // To verify role of users
  126. $userAccess = $project->restrictedProjectArea($user);
  127. }
  128. if ($_GET["action"] == 'create' && $user->rights->projet->creer && (empty($project->societe->id) || $userAccess))
  129. {
  130. print_fiche_titre($langs->trans("NewTask"));
  131. dol_htmloutput_errors($mesg);
  132. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  133. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  134. print '<input type="hidden" name="action" value="createtask">';
  135. if ($_GET['id']) print '<input type="hidden" name="id" value="'.$_GET['id'].'">';
  136. if ($_GET['mode']) print '<input type="hidden" name="mode" value="'.$_GET['mode'].'">';
  137. print '<table class="border" width="100%">';
  138. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
  139. print '<input type="text" size="25" name="label" class="flat" value="'.$_POST["label"].'">';
  140. print '</td></tr>';
  141. // List of projects
  142. print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfTask").'</td><td>';
  143. print $formother->selectProjectTasks('',$projectid?$projectid:$_GET["id"], 'task_parent', 0, 0, 1, 1);
  144. print '</td></tr>';
  145. print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
  146. print $form->select_users($user->id,'userid',1);
  147. print '</td></tr>';
  148. // Date start
  149. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  150. print $form->select_date(($date_start?$date_start:''),'dateo',0,0,0,'',1,1);
  151. print '</td></tr>';
  152. // Date end
  153. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  154. print $form->select_date(($date_end?$date_end:-1),'datee',0,0,0,'',1,1);
  155. print '</td></tr>';
  156. // Progress
  157. print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
  158. print $formother->select_percent($progress,'progress');
  159. print '</td></tr>';
  160. // Description
  161. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  162. print '<td>';
  163. print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$description.'</textarea>';
  164. print '</td></tr>';
  165. print '</table>';
  166. print '<center><br>';
  167. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  168. print ' &nbsp; &nbsp; ';
  169. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  170. print '</center>';
  171. print '</form>';
  172. }
  173. else
  174. {
  175. /*
  176. * Fiche projet en mode visu
  177. */
  178. $userstatic=new User($db);
  179. $tab='tasks';
  180. $head=project_prepare_head($project);
  181. dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project'));
  182. $param=($_REQUEST["mode"]=='mine'?'&mode=mine':'');
  183. print '<table class="border" width="100%">';
  184. // Ref
  185. print '<tr><td width="30%">';
  186. print $langs->trans("Ref");
  187. print '</td><td>';
  188. // Define a complementary filter for search of next/prev ref.
  189. $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
  190. $project->next_prev_filter=" rowid in (".$projectsListId.")";
  191. print $form->showrefnav($project,'ref','',1,'ref','ref','',$param);
  192. print '</td></tr>';
  193. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$project->title.'</td></tr>';
  194. print '<tr><td>'.$langs->trans("Company").'</td><td>';
  195. if (! empty($project->societe->id)) print $project->societe->getNomUrl(1);
  196. else print '&nbsp;';
  197. print '</td>';
  198. print '</tr>';
  199. // Visibility
  200. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  201. if ($project->public) print $langs->trans('SharedProject');
  202. else print $langs->trans('PrivateProject');
  203. print '</td></tr>';
  204. // Statut
  205. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'</td></tr>';
  206. print '</table>';
  207. print '</div>';
  208. /*
  209. * Actions
  210. */
  211. print '<div class="tabsAction">';
  212. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  213. {
  214. if ($project->public || $userAccess)
  215. {
  216. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$project->id.'&action=create'.$param.'">'.$langs->trans('AddTask').'</a>';
  217. }
  218. else
  219. {
  220. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  221. }
  222. }
  223. else
  224. {
  225. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NoPermission").'">'.$langs->trans('AddTask').'</a>';
  226. }
  227. print '</div>';
  228. print '<br>';
  229. // Link to switch in "my task" / "all task"
  230. print '<table width="100%"><tr><td align="right">';
  231. if ($_REQUEST["mode"] == 'mine')
  232. {
  233. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">'.$langs->trans("DoNotShowMyTasksOnly").'</a>';
  234. //print ' - ';
  235. //print $langs->trans("ShowMyTaskOnly");
  236. }
  237. else
  238. {
  239. //print $langs->trans("DoNotShowMyTaskOnly");
  240. //print ' - ';
  241. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'&mode=mine">'.$langs->trans("ShowMyTasksOnly").'</a>';
  242. }
  243. print '</td></tr></table>';
  244. // Get list of tasks in tasksarray and taskarrayfiltered
  245. // We need all tasks (even not limited to a user because a task to user
  246. // can have a parent that is not affected to him).
  247. $tasksarray=$task->getTasksArray(0, 0, $project->id, $socid, 0);
  248. // We load also tasks limited to a particular user
  249. $tasksrole=($_REQUEST["mode"]=='mine' ? $task->getUserRolesForProjectsOrTasks(0,$user,$project->id,0) : '');
  250. //var_dump($tasksarray);
  251. //var_dump($tasksrole);
  252. print '<table class="noborder" width="100%">';
  253. print '<tr class="liste_titre">';
  254. if ($projectstatic->id) print '<td>'.$langs->trans("Project").'</td>';
  255. print '<td width="80">'.$langs->trans("RefTask").'</td>';
  256. print '<td>'.$langs->trans("LabelTask").'</td>';
  257. print '<td align="right">'.$langs->trans("Progress").'</td>';
  258. print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
  259. print "</tr>\n";
  260. if (count($tasksarray) > 0)
  261. {
  262. // Show all lines in taskarray (recursive function to go down on tree)
  263. $j=0;
  264. $nboftaskshown=PLines($j, 0, $tasksarray, $level, true, 0, $tasksrole);
  265. }
  266. else
  267. {
  268. print '<tr><td colspan="'.($projectstatic->id?"5":"4").'">'.$langs->trans("NoTasks").'</td></tr>';
  269. }
  270. print "</table>";
  271. // Test if database is clean. If not we clean it.
  272. //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
  273. if ($_REQUEST["mode"]=='mine')
  274. {
  275. if ($nboftaskshown < count($tasksrole)) clean_orphelins($db);
  276. }
  277. else
  278. {
  279. if ($nboftaskshown < count($tasksarray)) clean_orphelins($db);
  280. }
  281. }
  282. $db->close();
  283. llxFooter();
  284. ?>