project.lib.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. <?php
  2. /* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  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. * or see http://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/lib/project.lib.php
  22. * \brief Functions used by project module
  23. * \ingroup project
  24. */
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  26. /**
  27. * Prepare array with list of tabs
  28. *
  29. * @param Object $object Object related to tabs
  30. * @return array Array of tabs to shoc
  31. */
  32. function project_prepare_head($object)
  33. {
  34. global $langs, $conf, $user;
  35. $h = 0;
  36. $head = array();
  37. $head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$object->id;
  38. $head[$h][1] = $langs->trans("Project");
  39. $head[$h][2] = 'project';
  40. $h++;
  41. $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
  42. $head[$h][1] = $langs->trans("ProjectContact");
  43. $head[$h][2] = 'contact';
  44. $h++;
  45. if (! empty($conf->fournisseur->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled)
  46. || ! empty($conf->facture->enabled) || ! empty($conf->contrat->enabled)
  47. || ! empty($conf->ficheinter->enabled) || ! empty($conf->agenda->enabled) || ! empty($conf->deplacement->enabled))
  48. {
  49. $head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$object->id;
  50. $head[$h][1] = $langs->trans("ProjectReferers");
  51. $head[$h][2] = 'element';
  52. $h++;
  53. }
  54. // Show more tabs from modules
  55. // Entries must be declared in modules descriptor with line
  56. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  57. // $this->tabs = array('entity:-tabname); to remove a tab
  58. complete_head_from_modules($conf,$langs,$object,$head,$h,'project');
  59. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  60. {
  61. $nbNote = 0;
  62. if(!empty($object->note_private)) $nbNote++;
  63. if(!empty($object->note_public)) $nbNote++;
  64. $head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
  65. $head[$h][1] = $langs->trans('Notes');
  66. if($nbNote > 0) $head[$h][1].= ' ('.$nbNote.')';
  67. $head[$h][2] = 'notes';
  68. $h++;
  69. }
  70. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  71. $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
  72. $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$'));
  73. $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
  74. $head[$h][1] = $langs->trans('Documents');
  75. if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')';
  76. $head[$h][2] = 'document';
  77. $h++;
  78. // Then tab for sub level of projet, i mean tasks
  79. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id;
  80. $head[$h][1] = $langs->trans("Tasks");
  81. $head[$h][2] = 'tasks';
  82. $h++;
  83. /* Now this is a filter in the Task tab.
  84. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id.'&mode=mine';
  85. $head[$h][1] = $langs->trans("MyTasks");
  86. $head[$h][2] = 'mytasks';
  87. $h++;
  88. */
  89. $head[$h][0] = DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id;
  90. $head[$h][1] = $langs->trans("Gantt");
  91. $head[$h][2] = 'gantt';
  92. $h++;
  93. complete_head_from_modules($conf,$langs,$object,$head,$h,'project','remove');
  94. return $head;
  95. }
  96. /**
  97. * Prepare array with list of tabs
  98. *
  99. * @param Object $object Object related to tabs
  100. * @return array Array of tabs to shoc
  101. */
  102. function task_prepare_head($object)
  103. {
  104. global $langs, $conf, $user;
  105. $h = 0;
  106. $head = array();
  107. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
  108. $head[$h][1] = $langs->trans("Card");
  109. $head[$h][2] = 'task_task';
  110. $h++;
  111. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
  112. $head[$h][1] = $langs->trans("TaskRessourceLinks");
  113. $head[$h][2] = 'task_contact';
  114. $h++;
  115. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
  116. $head[$h][1] = $langs->trans("TimeSpent");
  117. $head[$h][2] = 'task_time';
  118. $h++;
  119. // Show more tabs from modules
  120. // Entries must be declared in modules descriptor with line
  121. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  122. // $this->tabs = array('entity:-tabname); to remove a tab
  123. complete_head_from_modules($conf,$langs,$object,$head,$h,'task');
  124. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  125. {
  126. $nbNote = 0;
  127. if(!empty($object->note_private)) $nbNote++;
  128. if(!empty($object->note_public)) $nbNote++;
  129. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
  130. $head[$h][1] = $langs->trans('Notes');
  131. if($nbNote > 0) $head[$h][1].= ' ('.$nbNote.')';
  132. $head[$h][2] = 'task_notes';
  133. $h++;
  134. }
  135. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
  136. $filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->project->ref) . '/' .dol_sanitizeFileName($object->ref);
  137. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  138. $listoffiles=dol_dir_list($filesdir,'files',1,'','thumbs');
  139. $head[$h][1] = (count($listoffiles)?$langs->trans('DocumentsNb',count($listoffiles)):$langs->trans('Documents'));
  140. $head[$h][2] = 'task_document';
  141. $h++;
  142. complete_head_from_modules($conf,$langs,$object,$head,$h,'task','remove');
  143. return $head;
  144. }
  145. /**
  146. * Prepare array with list of tabs
  147. *
  148. * @return array Array of tabs to shoc
  149. */
  150. function project_admin_prepare_head()
  151. {
  152. global $langs, $conf, $user;
  153. $h = 0;
  154. $head = array();
  155. $h = 0;
  156. $head[$h][0] = DOL_URL_ROOT."/projet/admin/project.php";
  157. $head[$h][1] = $langs->trans("Projects");
  158. $head[$h][2] = 'project';
  159. $h++;
  160. complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin');
  161. $head[$h][0] = DOL_URL_ROOT."/projet/admin/project_extrafields.php";
  162. $head[$h][1] = $langs->trans("ExtraFieldsProject");
  163. $head[$h][2] = 'attributes';
  164. $h++;
  165. $head[$h][0] = DOL_URL_ROOT.'/projet/admin/project_task_extrafields.php';
  166. $head[$h][1] = $langs->trans("ExtraFieldsProjectTask");
  167. $head[$h][2] = 'attributes_task';
  168. $h++;
  169. complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin','remove');
  170. return $head;
  171. }
  172. /**
  173. * Show task lines with a particular parent
  174. *
  175. * @param string &$inc Counter that count number of lines legitimate to show (for return)
  176. * @param int $parent Id of parent task to start
  177. * @param array &$lines Array of all tasks
  178. * @param int &$level Level of task
  179. * @param string $var Color
  180. * @param int $showproject Show project columns
  181. * @param int &$taskrole Array of roles of user for each tasks
  182. * @param int $projectsListId List of id of project allowed to user (string separated with comma)
  183. * @param int $addordertick Add a tick to move task
  184. * @return void
  185. */
  186. function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='', $addordertick=0)
  187. {
  188. global $user, $bc, $langs;
  189. global $projectstatic, $taskstatic;
  190. $lastprojectid=0;
  191. $projectsArrayId=explode(',',$projectsListId);
  192. $numlines=count($lines);
  193. // We declare counter as global because we want to edit them into recursive call
  194. global $total_projectlinesa_spent,$total_projectlinesa_planned,$total_projectlinesa_spent_if_planned;
  195. if ($level == 0)
  196. {
  197. $total_projectlinesa_spent=0;
  198. $total_projectlinesa_planned=0;
  199. $total_projectlinesa_spent_if_planned=0;
  200. }
  201. for ($i = 0 ; $i < $numlines ; $i++)
  202. {
  203. if ($parent == 0) $level = 0;
  204. // Process line
  205. // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
  206. if ($lines[$i]->fk_parent == $parent)
  207. {
  208. // Show task line.
  209. $showline=1;
  210. $showlineingray=0;
  211. // If there is filters to use
  212. if (is_array($taskrole))
  213. {
  214. // If task not legitimate to show, search if a legitimate task exists later in tree
  215. if (! isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent)
  216. {
  217. // So search if task has a subtask legitimate to show
  218. $foundtaskforuserdeeper=0;
  219. searchTaskInChild($foundtaskforuserdeeper,$lines[$i]->id,$lines,$taskrole);
  220. //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
  221. if ($foundtaskforuserdeeper > 0)
  222. {
  223. $showlineingray=1; // We will show line but in gray
  224. }
  225. else
  226. {
  227. $showline=0; // No reason to show line
  228. }
  229. }
  230. }
  231. else
  232. {
  233. // Caller did not ask to filter on tasks of a specific user (this probably means he want also tasks of all users, into public project
  234. // or into all other projects if user has permission to).
  235. if (empty($user->rights->projet->all->lire))
  236. {
  237. // User is not allowed on this project and project is not public, so we hide line
  238. if (! in_array($lines[$i]->fk_project, $projectsArrayId))
  239. {
  240. // Note that having a user assigned to a task into a project user has no permission on, should not be possible
  241. // because assignement on task can be done only on contact of project.
  242. // If assignement was done and after, was removed from contact of project, then we can hide the line.
  243. $showline=0;
  244. }
  245. }
  246. }
  247. if ($showline)
  248. {
  249. // Break on a new project
  250. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
  251. {
  252. $var = !$var;
  253. $lastprojectid=$lines[$i]->fk_project;
  254. }
  255. print '<tr '.$bc[$var].' id="row-'.$lines[$i]->id.'">'."\n";
  256. if ($showproject)
  257. {
  258. // Project ref
  259. print "<td>";
  260. if ($showlineingray) print '<i>';
  261. $projectstatic->id=$lines[$i]->fk_project;
  262. $projectstatic->ref=$lines[$i]->projectref;
  263. $projectstatic->public=$lines[$i]->public;
  264. if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId)) print $projectstatic->getNomUrl(1);
  265. else print $projectstatic->getNomUrl(1,'nolink');
  266. if ($showlineingray) print '</i>';
  267. print "</td>";
  268. // Project status
  269. print '<td>';
  270. $projectstatic->statut=$lines[$i]->projectstatus;
  271. print $projectstatic->getLibStatut(2);
  272. print "</td>";
  273. }
  274. // Ref of task
  275. print '<td>';
  276. if ($showlineingray)
  277. {
  278. print '<i>'.img_object('','projecttask').' '.$lines[$i]->ref.'</i>';
  279. }
  280. else
  281. {
  282. $taskstatic->id=$lines[$i]->id;
  283. $taskstatic->ref=$lines[$i]->ref;
  284. $taskstatic->label=($taskrole[$lines[$i]->id]?$langs->trans("YourRole").': '.$taskrole[$lines[$i]->id]:'');
  285. print $taskstatic->getNomUrl(1,($showproject?'':'withproject'));
  286. }
  287. print '</td>';
  288. // Title of task
  289. print "<td>";
  290. if ($showlineingray) print '<i>';
  291. else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
  292. for ($k = 0 ; $k < $level ; $k++)
  293. {
  294. print "&nbsp; &nbsp; &nbsp;";
  295. }
  296. print $lines[$i]->label;
  297. if ($showlineingray) print '</i>';
  298. else print '</a>';
  299. print "</td>\n";
  300. // Date start
  301. print '<td align="center">';
  302. print dol_print_date($lines[$i]->date_start,'dayhour');
  303. print '</td>';
  304. // Date end
  305. print '<td align="center">';
  306. print dol_print_date($lines[$i]->date_end,'dayhour');
  307. print '</td>';
  308. // Planned Workload (in working hours)
  309. print '<td align="center">';
  310. $fullhour=convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
  311. $workingdelay=convertSecondToTime($lines[$i]->planned_workload,'all',86400,7); // TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
  312. if ($lines[$i]->planned_workload)
  313. {
  314. print $fullhour;
  315. // TODO Add delay taking account of working hours per day and working day per week
  316. //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
  317. }
  318. //else print '--:--';
  319. print '</td>';
  320. // Progress declared
  321. print '<td align="right">';
  322. print $lines[$i]->progress.' %';
  323. print '</td>';
  324. // Time spent
  325. print '<td align="right">';
  326. if ($showlineingray) print '<i>';
  327. else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
  328. if ($lines[$i]->duration) print convertSecondToTime($lines[$i]->duration,'allhourmin');
  329. else print '--:--';
  330. if ($showlineingray) print '</i>';
  331. else print '</a>';
  332. print '</td>';
  333. // Progress calculated
  334. // Note: ->duration is in fact time spent i think
  335. print '<td align="right">';
  336. if ($lines[$i]->planned_workload) print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload,2).' %';
  337. print '</td>';
  338. // Tick to drag and drop
  339. if ($addordertick)
  340. {
  341. print '<td align="center" class="tdlineupdown hideonsmartphone">&nbsp;</td>';
  342. }
  343. print "</tr>\n";
  344. if (! $showlineingray) $inc++;
  345. $level++;
  346. if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
  347. $level--;
  348. $total_projectlinesa_spent += $lines[$i]->duration;
  349. $total_projectlinesa_planned += $lines[$i]->planned_workload;
  350. if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
  351. }
  352. }
  353. else
  354. {
  355. //$level--;
  356. }
  357. }
  358. if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0) && $level==0)
  359. {
  360. print '<tr class="liste_total">';
  361. print '<td class="liste_total">'.$langs->trans("Total").'</td>';
  362. if ($showproject) print '<td></td><td></td>';
  363. print '<td></td>';
  364. print '<td></td>';
  365. print '<td></td>';
  366. print '<td align="center" class="nowrap liste_total">';
  367. print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
  368. print '</td>';
  369. print '<td></td>';
  370. print '<td align="right" class="nowrap liste_total">';
  371. print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
  372. print '</td>';
  373. print '<td align="right" class="nowrap liste_total">';
  374. if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent_if_planned / $total_projectlinesa_planned,2).' %';
  375. print '</td>';
  376. if ($addordertick) print '<td class="hideonsmartphone"></td>';
  377. print '</tr>';
  378. }
  379. return $inc;
  380. }
  381. /**
  382. * Output a task line
  383. *
  384. * @param string &$inc ?
  385. * @param string $parent ?
  386. * @param Object $lines ?
  387. * @param int &$level ?
  388. * @param string &$projectsrole ?
  389. * @param string &$tasksrole ?
  390. * @param int $mytask 0 or 1 to enable only if task is a task i am affected to
  391. * @return $inc
  392. */
  393. function projectLinesb(&$inc, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mytask=0)
  394. {
  395. global $user, $bc, $langs;
  396. global $form, $projectstatic, $taskstatic;
  397. $lastprojectid=0;
  398. $var=true;
  399. $numlines=count($lines);
  400. for ($i = 0 ; $i < $numlines ; $i++)
  401. {
  402. if ($parent == 0) $level = 0;
  403. if ($lines[$i]->fk_parent == $parent)
  404. {
  405. // Break on a new project
  406. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
  407. {
  408. $var = !$var;
  409. $lastprojectid=$lines[$i]->fk_project;
  410. }
  411. print "<tr ".$bc[$var].">\n";
  412. // Project
  413. print "<td>";
  414. $projectstatic->id=$lines[$i]->fk_project;
  415. $projectstatic->ref=$lines[$i]->projectref;
  416. $projectstatic->public=$lines[$i]->public;
  417. $projectstatic->label=$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project];
  418. print $projectstatic->getNomUrl(1);
  419. print "</td>";
  420. // Ref
  421. print '<td>';
  422. $taskstatic->id=$lines[$i]->id;
  423. $taskstatic->ref=$lines[$i]->id;
  424. print $taskstatic->getNomUrl(1);
  425. print '</td>';
  426. // Label task
  427. print "<td>";
  428. for ($k = 0 ; $k < $level ; $k++)
  429. {
  430. print "&nbsp;&nbsp;&nbsp;";
  431. }
  432. $taskstatic->id=$lines[$i]->id;
  433. $taskstatic->ref=$lines[$i]->label;
  434. print $taskstatic->getNomUrl(0);
  435. print "</td>\n";
  436. // Date start
  437. print '<td align="center">';
  438. print dol_print_date($lines[$i]->date_start,'dayhour');
  439. print '</td>';
  440. // Date end
  441. print '<td align="center">';
  442. print dol_print_date($lines[$i]->date_end,'dayhour');
  443. print '</td>';
  444. // Planned Workload
  445. print '<td align="right">';
  446. if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
  447. else print '--:--';
  448. print '</td>';
  449. // Progress declared %
  450. print '<td align="right">';
  451. print $lines[$i]->progress.' %';
  452. print '</td>';
  453. // Time spent
  454. print '<td align="right">';
  455. if ($lines[$i]->duration)
  456. {
  457. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  458. print convertSecondToTime($lines[$i]->duration,'allhourmin');
  459. print '</a>';
  460. }
  461. else print '--:--';
  462. print "</td>\n";
  463. $disabledproject=1;$disabledtask=1;
  464. //print "x".$lines[$i]->fk_project;
  465. //var_dump($lines[$i]);
  466. //var_dump($projectsrole[$lines[$i]->fk_project]);
  467. // If at least one role for project
  468. if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
  469. {
  470. $disabledproject=0;
  471. $disabledtask=0;
  472. }
  473. // If mytask and no role on task
  474. if ($mytask && empty($tasksrole[$lines[$i]->id]))
  475. {
  476. $disabledtask=1;
  477. }
  478. print '<td class="nowrap">';
  479. $s =$form->select_date('',$lines[$i]->id,'','','',"addtime",1,0,1,$disabledtask);
  480. $s.='&nbsp;&nbsp;&nbsp;';
  481. $s.=$form->select_duration($lines[$i]->id,'',$disabledtask,'text');
  482. $s.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled="disabled"':'').' value="'.$langs->trans("Add").'">';
  483. print $s;
  484. print '</td>';
  485. print '<td align="right">';
  486. if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("YouAreNotContactOfProject"));
  487. else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAffectedToYou"));
  488. print '</td>';
  489. print "</tr>\n";
  490. $inc++;
  491. $level++;
  492. if ($lines[$i]->id) projectLinesb($inc, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mytask);
  493. $level--;
  494. }
  495. else
  496. {
  497. //$level--;
  498. }
  499. }
  500. return $inc;
  501. }
  502. /**
  503. * Search in task lines with a particular parent if there is a task for a particular user (in taskrole)
  504. *
  505. * @param string &$inc Counter that count number of lines legitimate to show (for return)
  506. * @param int $parent Id of parent task to start
  507. * @param array &$lines Array of all tasks
  508. * @param string &$taskrole Array of task filtered on a particular user
  509. * @return int 1 if there is
  510. */
  511. function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
  512. {
  513. //print 'Search in line with parent id = '.$parent.'<br>';
  514. $numlines=count($lines);
  515. for ($i = 0 ; $i < $numlines ; $i++)
  516. {
  517. // Process line $lines[$i]
  518. if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent)
  519. {
  520. // If task is legitimate to show, no more need to search deeper
  521. if (isset($taskrole[$lines[$i]->id]))
  522. {
  523. //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
  524. $inc++;
  525. return $inc;
  526. }
  527. searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
  528. //print 'Found inc='.$inc.'<br>';
  529. if ($inc > 0) return $inc;
  530. }
  531. }
  532. return $inc;
  533. }
  534. /**
  535. * Return HTML table with list of projects and number of opened tasks
  536. *
  537. * @param DoliDB $db Database handler
  538. * @param int $socid Id thirdparty
  539. * @param int $projectsListId Id of project i have permission on
  540. * @param int $mytasks Limited to task i am contact to
  541. * @return void
  542. */
  543. function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0)
  544. {
  545. global $langs,$conf,$user,$bc;
  546. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  547. $projectstatic=new Project($db);
  548. $sortfield='';
  549. $sortorder='';
  550. print '<table class="noborder" width="100%">';
  551. print '<tr class="liste_titre">';
  552. print_liste_field_titre($langs->trans("Project"),"index.php","","","","",$sortfield,$sortorder);
  553. print_liste_field_titre($langs->trans("Tasks"),"","","","",'align="right"',$sortfield,$sortorder);
  554. print_liste_field_titre($langs->trans("Status"),"","","","",'align="right"',$sortfield,$sortorder);
  555. print "</tr>\n";
  556. $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut, COUNT(t.rowid) as nb";
  557. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  558. if ($mytasks)
  559. {
  560. $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
  561. $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
  562. $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
  563. }
  564. else
  565. {
  566. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  567. }
  568. $sql.= " WHERE p.entity = ".$conf->entity;
  569. $sql.= " AND p.rowid IN (".$projectsListId.")";
  570. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  571. if ($mytasks)
  572. {
  573. $sql.= " AND p.rowid = t.fk_projet";
  574. $sql.= " AND ec.element_id = t.rowid";
  575. $sql.= " AND ctc.rowid = ec.fk_c_type_contact";
  576. $sql.= " AND ctc.element = 'project_task'";
  577. $sql.= " AND ec.fk_socpeople = ".$user->id;
  578. }
  579. $sql.= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut";
  580. $sql.= " ORDER BY p.title, p.ref";
  581. $var=true;
  582. $resql = $db->query($sql);
  583. if ( $resql )
  584. {
  585. $num = $db->num_rows($resql);
  586. $i = 0;
  587. while ($i < $num)
  588. {
  589. $objp = $db->fetch_object($resql);
  590. $projectstatic->id = $objp->projectid;
  591. $projectstatic->user_author_id = $objp->fk_user_creat;
  592. $projectstatic->public = $objp->public;
  593. // Check is user has read permission on project
  594. $userAccess = $projectstatic->restrictedProjectArea($user);
  595. if ($userAccess >= 0)
  596. {
  597. $var=!$var;
  598. print "<tr ".$bc[$var].">";
  599. print '<td class="nowrap">';
  600. $projectstatic->ref=$objp->ref;
  601. print $projectstatic->getNomUrl(1);
  602. print ' - '.dol_trunc($objp->title,24).'</td>';
  603. print '<td align="right">'.$objp->nb.'</td>';
  604. $projectstatic->statut = $objp->fk_statut;
  605. print '<td align="right">'.$projectstatic->getLibStatut(3).'</td>';
  606. print "</tr>\n";
  607. }
  608. $i++;
  609. }
  610. $db->free($resql);
  611. }
  612. else
  613. {
  614. dol_print_error($db);
  615. }
  616. print "</table>";
  617. }