PageRenderTime 31ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/tasks.php

https://bitbucket.org/speedealing/speedealing
PHP | 399 lines | 256 code | 74 blank | 69 comment | 49 complexity | bb7491e5a5d510812500183f22688240 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) 2004-2012 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. $langs->load("users");
  31. $langs->load("projects");
  32. $action = GETPOST('action', 'alpha');
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $backtopage=GETPOST('backtopage','alpha');
  36. $mode = GETPOST('mode', 'alpha');
  37. $mine = ($mode == 'mine' ? 1 : 0);
  38. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  39. $object = new Project($db);
  40. if ($ref)
  41. {
  42. $object->fetch(0,$ref);
  43. $id=$object->id;
  44. }
  45. // Security check
  46. $socid=0;
  47. if ($user->societe_id > 0) $socid = $user->societe_id;
  48. $result = restrictedArea($user, 'projet', $id);
  49. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  50. $hookmanager->initHooks(array('projecttaskcard'));
  51. $progress=GETPOST('progress', 'int');
  52. $label=GETPOST('label', 'alpha');
  53. $description=GETPOST('description');
  54. $userAccess=0;
  55. /*
  56. * Actions
  57. */
  58. if ($action == 'createtask' && $user->rights->projet->creer)
  59. {
  60. $error=0;
  61. $date_start = dol_mktime(0,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']);
  62. $date_end = dol_mktime(0,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']);
  63. if (empty($_POST["cancel"]))
  64. {
  65. if (empty($label))
  66. {
  67. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
  68. $action='create';
  69. $error++;
  70. }
  71. else if (empty($_POST['task_parent']))
  72. {
  73. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("ChildOfTask"));
  74. $action='create';
  75. $error++;
  76. }
  77. if (! $error)
  78. {
  79. $tmparray=explode('_',$_POST['task_parent']);
  80. $projectid=$tmparray[0];
  81. if (empty($projectid)) $projectid = $id; // If projectid is ''
  82. $task_parent=$tmparray[1];
  83. if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
  84. $task = new Task($db);
  85. $task->fk_project = $projectid;
  86. $task->label = $label;
  87. $task->description = $description;
  88. $task->fk_task_parent = $task_parent;
  89. $task->date_c = dol_now();
  90. $task->date_start = $date_start;
  91. $task->date_end = $date_end;
  92. $task->progress = $progress;
  93. $taskid = $task->create($user);
  94. if ($taskid > 0)
  95. {
  96. $result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
  97. }
  98. }
  99. if (! $error)
  100. {
  101. if (! empty($backtopage))
  102. {
  103. header("Location: ".$backtopage);
  104. exit;
  105. }
  106. else if (empty($projectid))
  107. {
  108. header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($mode)?'':'?mode='.$mode));
  109. exit;
  110. }
  111. }
  112. }
  113. else
  114. {
  115. if (! empty($backtopage))
  116. {
  117. header("Location: ".$backtopage);
  118. exit;
  119. }
  120. else if (empty($id))
  121. {
  122. // We go back on task list
  123. header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($mode)?'':'?mode='.$mode));
  124. exit;
  125. }
  126. }
  127. }
  128. /*
  129. * View
  130. */
  131. $form=new Form($db);
  132. $formother=new FormOther($db);
  133. $taskstatic = new Task($db);
  134. $userstatic=new User($db);
  135. llxHeader("",$langs->trans("Tasks"));
  136. if ($id > 0 || ! empty($ref))
  137. {
  138. $object->fetch($id, $ref);
  139. if ($object->societe->id > 0) $result=$object->societe->fetch($object->societe->id);
  140. // To verify role of users
  141. //$userAccess = $object->restrictedProjectArea($user,'read');
  142. $userWrite = $object->restrictedProjectArea($user,'write');
  143. //$userDelete = $object->restrictedProjectArea($user,'delete');
  144. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  145. $tab=GETPOST('tab')?GETPOST('tab'):'tasks';
  146. $head=project_prepare_head($object);
  147. dol_fiche_head($head, $tab, $langs->trans("Project"),0,($object->public?'projectpub':'project'));
  148. $param=($mode=='mine'?'&mode=mine':'');
  149. print '<table class="border" width="100%">';
  150. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/liste.php">'.$langs->trans("BackToList").'</a>';
  151. // Ref
  152. print '<tr><td width="30%">';
  153. print $langs->trans("Ref");
  154. print '</td><td>';
  155. // Define a complementary filter for search of next/prev ref.
  156. if (! $user->rights->projet->all->lire)
  157. {
  158. $projectsListId = $object->getProjectsAuthorizedForUser($user,$mine,0);
  159. $object->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
  160. }
  161. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '', $param);
  162. print '</td></tr>';
  163. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->title.'</td></tr>';
  164. print '<tr><td>'.$langs->trans("Company").'</td><td>';
  165. if (! empty($object->societe->id)) print $object->societe->getNomUrl(1);
  166. else print '&nbsp;';
  167. print '</td>';
  168. print '</tr>';
  169. // Visibility
  170. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  171. if ($object->public) print $langs->trans('SharedProject');
  172. else print $langs->trans('PrivateProject');
  173. print '</td></tr>';
  174. // Statut
  175. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  176. // Date start
  177. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  178. print dol_print_date($object->date_start,'day');
  179. print '</td></tr>';
  180. // Date end
  181. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  182. print dol_print_date($object->date_end,'day');
  183. print '</td></tr>';
  184. print '</table>';
  185. dol_fiche_end();
  186. }
  187. if ($action == 'create' && $user->rights->projet->creer && (empty($object->societe->id) || $userWrite > 0))
  188. {
  189. if ($id > 0 || ! empty($ref)) print '<br>';
  190. print_fiche_titre($langs->trans("NewTask"));
  191. dol_htmloutput_errors($mesg);
  192. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  193. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  194. print '<input type="hidden" name="action" value="createtask">';
  195. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  196. if (! empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
  197. if (! empty($mode)) print '<input type="hidden" name="mode" value="'.$mode.'">';
  198. print '<table class="border" width="100%">';
  199. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
  200. print '<input type="text" size="25" name="label" class="flat" value="'.$label.'">';
  201. print '</td></tr>';
  202. // List of projects
  203. print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfTask").'</td><td>';
  204. print $formother->selectProjectTasks('',$projectid?$projectid:$object->id, 'task_parent', 0, 0, 1, 1);
  205. print '</td></tr>';
  206. print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
  207. print $form->select_users($user->id,'userid',1);
  208. print '</td></tr>';
  209. // Date start
  210. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  211. print $form->select_date(($date_start?$date_start:''),'dateo',0,0,0,'',1,1);
  212. print '</td></tr>';
  213. // Date end
  214. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  215. print $form->select_date(($date_end?$date_end:-1),'datee',0,0,0,'',1,1);
  216. print '</td></tr>';
  217. // Progress
  218. print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
  219. print $formother->select_percent($progress,'progress');
  220. print '</td></tr>';
  221. // Description
  222. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  223. print '<td>';
  224. print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$description.'</textarea>';
  225. print '</td></tr>';
  226. // Other options
  227. $parameters=array();
  228. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  229. print '</table>';
  230. print '<div align="center"><br>';
  231. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  232. print ' &nbsp; &nbsp; ';
  233. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  234. print '</div>';
  235. print '</form>';
  236. }
  237. else
  238. {
  239. /*
  240. * Fiche projet en mode visu
  241. */
  242. /*
  243. * Actions
  244. */
  245. print '<div class="tabsAction">';
  246. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  247. {
  248. if ($object->public || $userWrite > 0)
  249. {
  250. 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>';
  251. }
  252. else
  253. {
  254. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  255. }
  256. }
  257. else
  258. {
  259. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NoPermission").'">'.$langs->trans('AddTask').'</a>';
  260. }
  261. print '</div>';
  262. print '<br>';
  263. // Link to switch in "my task" / "all task"
  264. print '<table width="100%"><tr><td align="right">';
  265. if ($mode == 'mine')
  266. {
  267. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">'.$langs->trans("DoNotShowMyTasksOnly").'</a>';
  268. //print ' - ';
  269. //print $langs->trans("ShowMyTaskOnly");
  270. }
  271. else
  272. {
  273. //print $langs->trans("DoNotShowMyTaskOnly");
  274. //print ' - ';
  275. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mode=mine">'.$langs->trans("ShowMyTasksOnly").'</a>';
  276. }
  277. print '</td></tr></table>';
  278. // Get list of tasks in tasksarray and taskarrayfiltered
  279. // We need all tasks (even not limited to a user because a task to user
  280. // can have a parent that is not affected to him).
  281. $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0);
  282. // We load also tasks limited to a particular user
  283. $tasksrole=($mode=='mine' ? $taskstatic->getUserRolesForProjectsOrTasks(0,$user,$object->id,0) : '');
  284. //var_dump($tasksarray);
  285. //var_dump($tasksrole);
  286. if (! empty($conf->use_javascript_ajax))
  287. {
  288. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  289. }
  290. print '<table id="tablelines" class="noborder" width="100%">';
  291. print '<tr class="liste_titre">';
  292. // print '<td>'.$langs->trans("Project").'</td>';
  293. print '<td width="80">'.$langs->trans("RefTask").'</td>';
  294. print '<td>'.$langs->trans("LabelTask").'</td>';
  295. print '<td align="center">'.$langs->trans("DateStart").'</td>';
  296. print '<td align="center">'.$langs->trans("DateEnd").'</td>';
  297. print '<td align="right">'.$langs->trans("Progress").'</td>';
  298. print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
  299. print '<td>&nbsp;</td>';
  300. print "</tr>\n";
  301. if (count($tasksarray) > 0)
  302. {
  303. // Show all lines in taskarray (recursive function to go down on tree)
  304. $j=0;
  305. $nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, '', 1);
  306. }
  307. else
  308. {
  309. print '<tr><td colspan="'.(! empty($object->id) ? "5" : "4").'">'.$langs->trans("NoTasks").'</td></tr>';
  310. }
  311. print "</table>";
  312. // Test if database is clean. If not we clean it.
  313. //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
  314. if ($mode=='mine')
  315. {
  316. if ($nboftaskshown < count($tasksrole)) clean_orphelins($db);
  317. }
  318. else
  319. {
  320. if ($nboftaskshown < count($tasksarray)) clean_orphelins($db);
  321. }
  322. }
  323. llxFooter();
  324. $db->close();
  325. ?>