PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/tasks.php

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