project.lib.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. <?php
  2. /* Copyright (C) 2006-2015 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 show
  31. */
  32. function project_prepare_head($object)
  33. {
  34. global $db, $langs, $conf, $user;
  35. $h = 0;
  36. $head = array();
  37. $head[$h][0] = DOL_URL_ROOT.'/projet/card.php?id='.$object->id;
  38. $head[$h][1] = $langs->trans("Project");
  39. $head[$h][2] = 'project';
  40. $h++;
  41. $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
  42. $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
  43. $head[$h][1] = $langs->trans("ProjectContact");
  44. if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
  45. $head[$h][2] = 'contact';
  46. $h++;
  47. if (! empty($conf->fournisseur->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled)
  48. || ! empty($conf->facture->enabled) || ! empty($conf->contrat->enabled)
  49. || ! empty($conf->ficheinter->enabled) || ! empty($conf->agenda->enabled) || ! empty($conf->deplacement->enabled))
  50. {
  51. $head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$object->id;
  52. $head[$h][1] = $langs->trans("ProjectOverview");
  53. $head[$h][2] = 'element';
  54. $h++;
  55. }
  56. // Show more tabs from modules
  57. // Entries must be declared in modules descriptor with line
  58. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  59. // $this->tabs = array('entity:-tabname); to remove a tab
  60. complete_head_from_modules($conf,$langs,$object,$head,$h,'project');
  61. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  62. {
  63. $nbNote = 0;
  64. if(!empty($object->note_private)) $nbNote++;
  65. if(!empty($object->note_public)) $nbNote++;
  66. $head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
  67. $head[$h][1] = $langs->trans('Notes');
  68. if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
  69. $head[$h][2] = 'notes';
  70. $h++;
  71. }
  72. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  73. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  74. $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
  75. $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
  76. $nbLinks=Link::count($db, $object->element, $object->id);
  77. $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
  78. $head[$h][1] = $langs->trans('Documents');
  79. if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
  80. $head[$h][2] = 'document';
  81. $h++;
  82. if (empty($conf->global->PROJECT_HIDE_TASKS))
  83. {
  84. // Then tab for sub level of projet, i mean tasks
  85. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id;
  86. $head[$h][1] = $langs->trans("Tasks");
  87. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  88. $taskstatic=new Task($db);
  89. $nbTasks=count($taskstatic->getTasksArray(0, 0, $object->id, 0, 0));
  90. if ($nbTasks > 0) $head[$h][1].= ' <span class="badge">'.($nbTasks).'</span>';
  91. $head[$h][2] = 'tasks';
  92. $h++;
  93. $head[$h][0] = DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id;
  94. $head[$h][1] = $langs->trans("Gantt");
  95. if ($nbTasks > 0) $head[$h][1].= ' <span class="badge">'.($nbTasks).'</span>';
  96. $head[$h][2] = 'gantt';
  97. $h++;
  98. }
  99. $head[$h][0] = DOL_URL_ROOT.'/projet/info.php?id='.$object->id;
  100. $head[$h][1].= $langs->trans("Events");
  101. if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
  102. {
  103. $head[$h][1].= '/';
  104. $head[$h][1].= $langs->trans("Agenda");
  105. }
  106. $head[$h][2] = 'agenda';
  107. $h++;
  108. complete_head_from_modules($conf,$langs,$object,$head,$h,'project','remove');
  109. return $head;
  110. }
  111. /**
  112. * Prepare array with list of tabs
  113. *
  114. * @param Object $object Object related to tabs
  115. * @return array Array of tabs to show
  116. */
  117. function task_prepare_head($object)
  118. {
  119. global $db, $langs, $conf, $user;
  120. $h = 0;
  121. $head = array();
  122. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
  123. $head[$h][1] = $langs->trans("Card");
  124. $head[$h][2] = 'task_task';
  125. $h++;
  126. $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
  127. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
  128. $head[$h][1] = $langs->trans("TaskRessourceLinks");
  129. if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
  130. $head[$h][2] = 'task_contact';
  131. $h++;
  132. // Is there timespent ?
  133. $nbTimeSpent=0;
  134. $sql = "SELECT t.rowid";
  135. $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
  136. $sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
  137. $sql .= " AND t.fk_task =".$object->id;
  138. $resql = $db->query($sql);
  139. if ($resql)
  140. {
  141. $obj = $db->fetch_object($resql);
  142. if ($obj) $nbTimeSpent=1;
  143. }
  144. else dol_print_error($db);
  145. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
  146. $head[$h][1] = $langs->trans("TimeSpent");
  147. if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
  148. $head[$h][2] = 'task_time';
  149. $h++;
  150. // Show more tabs from modules
  151. // Entries must be declared in modules descriptor with line
  152. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  153. // $this->tabs = array('entity:-tabname); to remove a tab
  154. complete_head_from_modules($conf,$langs,$object,$head,$h,'task');
  155. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  156. {
  157. $nbNote = 0;
  158. if(!empty($object->note_private)) $nbNote++;
  159. if(!empty($object->note_public)) $nbNote++;
  160. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
  161. $head[$h][1] = $langs->trans('Notes');
  162. if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
  163. $head[$h][2] = 'task_notes';
  164. $h++;
  165. }
  166. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
  167. $filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->project->ref) . '/' .dol_sanitizeFileName($object->ref);
  168. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  169. include_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  170. $nbFiles = count(dol_dir_list($filesdir,'files',0,'','(\.meta|_preview.*\.png)$'));
  171. $nbLinks=Link::count($db, $object->element, $object->id);
  172. $head[$h][1] = $langs->trans('Documents');
  173. if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
  174. $head[$h][2] = 'task_document';
  175. $h++;
  176. complete_head_from_modules($conf,$langs,$object,$head,$h,'task','remove');
  177. return $head;
  178. }
  179. /**
  180. * Prepare array with list of tabs
  181. *
  182. * @param string $mode Mode
  183. * @return array Array of tabs to show
  184. */
  185. function project_timesheet_prepare_head($mode)
  186. {
  187. global $langs, $conf, $user;
  188. $h = 0;
  189. $head = array();
  190. $h = 0;
  191. if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK))
  192. {
  193. $head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($mode?'?mode='.$mode:'');
  194. $head[$h][1] = $langs->trans("InputPerWeek");
  195. $head[$h][2] = 'inputperweek';
  196. $h++;
  197. }
  198. if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME))
  199. {
  200. $head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($mode?'?mode='.$mode:'');
  201. $head[$h][1] = $langs->trans("InputPerDay");
  202. $head[$h][2] = 'inputperday';
  203. $h++;
  204. }
  205. /*if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERACTION))
  206. {
  207. $head[$h][0] = DOL_URL_ROOT."/projet/activity/peraction.php".($mode?'?mode='.$mode:'');
  208. $head[$h][1] = $langs->trans("InputPerAction");
  209. $head[$h][2] = 'inputperaction';
  210. $h++;
  211. }*/
  212. complete_head_from_modules($conf,$langs,null,$head,$h,'project_timesheet');
  213. complete_head_from_modules($conf,$langs,null,$head,$h,'project_timesheet','remove');
  214. return $head;
  215. }
  216. /**
  217. * Prepare array with list of tabs
  218. *
  219. * @return array Array of tabs to show
  220. */
  221. function project_admin_prepare_head()
  222. {
  223. global $langs, $conf, $user;
  224. $h = 0;
  225. $head = array();
  226. $h = 0;
  227. $head[$h][0] = DOL_URL_ROOT."/projet/admin/project.php";
  228. $head[$h][1] = $langs->trans("Projects");
  229. $head[$h][2] = 'project';
  230. $h++;
  231. complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin');
  232. $head[$h][0] = DOL_URL_ROOT."/projet/admin/project_extrafields.php";
  233. $head[$h][1] = $langs->trans("ExtraFieldsProject");
  234. $head[$h][2] = 'attributes';
  235. $h++;
  236. $head[$h][0] = DOL_URL_ROOT.'/projet/admin/project_task_extrafields.php';
  237. $head[$h][1] = $langs->trans("ExtraFieldsProjectTask");
  238. $head[$h][2] = 'attributes_task';
  239. $h++;
  240. complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin','remove');
  241. return $head;
  242. }
  243. /**
  244. * Show task lines with a particular parent
  245. *
  246. * @param string $inc Line number (start to 0, then increased by recursive call)
  247. * @param string $parent Id of parent project to show (0 to show all)
  248. * @param Task[] $lines Array of lines
  249. * @param int $level Level (start to 0, then increased/decrease by recursive call), or -1 to show all level in order of $lines without the recursive groupment feature.
  250. * @param string $var Color
  251. * @param int $showproject Show project columns
  252. * @param int $taskrole Array of roles of user for each tasks
  253. * @param int $projectsListId List of id of project allowed to user (string separated with comma)
  254. * @param int $addordertick Add a tick to move task
  255. * @param int $projectidfortotallink 0 or Id of project to use on total line (link to see all time consumed for project)
  256. * @return void
  257. */
  258. function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='', $addordertick=0, $projectidfortotallink=0)
  259. {
  260. global $user, $bc, $langs;
  261. global $projectstatic, $taskstatic;
  262. $lastprojectid=0;
  263. $projectsArrayId=explode(',',$projectsListId);
  264. $numlines=count($lines);
  265. // We declare counter as global because we want to edit them into recursive call
  266. global $total_projectlinesa_spent,$total_projectlinesa_planned,$total_projectlinesa_spent_if_planned;
  267. if ($level == 0)
  268. {
  269. $total_projectlinesa_spent=0;
  270. $total_projectlinesa_planned=0;
  271. $total_projectlinesa_spent_if_planned=0;
  272. }
  273. for ($i = 0 ; $i < $numlines ; $i++)
  274. {
  275. if ($parent == 0 && $level >= 0) $level = 0; // if $level = -1, we dont' use sublevel recursion, we show all lines
  276. // Process line
  277. // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
  278. if ($lines[$i]->fk_parent == $parent || $level < 0) // if $level = -1, we dont' use sublevel recursion, we show all lines
  279. {
  280. // Show task line.
  281. $showline=1;
  282. $showlineingray=0;
  283. // If there is filters to use
  284. if (is_array($taskrole))
  285. {
  286. // If task not legitimate to show, search if a legitimate task exists later in tree
  287. if (! isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent)
  288. {
  289. // So search if task has a subtask legitimate to show
  290. $foundtaskforuserdeeper=0;
  291. searchTaskInChild($foundtaskforuserdeeper,$lines[$i]->id,$lines,$taskrole);
  292. //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
  293. if ($foundtaskforuserdeeper > 0)
  294. {
  295. $showlineingray=1; // We will show line but in gray
  296. }
  297. else
  298. {
  299. $showline=0; // No reason to show line
  300. }
  301. }
  302. }
  303. else
  304. {
  305. // 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
  306. // or into all other projects if user has permission to).
  307. if (empty($user->rights->projet->all->lire))
  308. {
  309. // User is not allowed on this project and project is not public, so we hide line
  310. if (! in_array($lines[$i]->fk_project, $projectsArrayId))
  311. {
  312. // Note that having a user assigned to a task into a project user has no permission on, should not be possible
  313. // because assignement on task can be done only on contact of project.
  314. // If assignement was done and after, was removed from contact of project, then we can hide the line.
  315. $showline=0;
  316. }
  317. }
  318. }
  319. if ($showline)
  320. {
  321. // Break on a new project
  322. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
  323. {
  324. $var = !$var;
  325. $lastprojectid=$lines[$i]->fk_project;
  326. }
  327. print '<tr '.$bc[$var].' id="row-'.$lines[$i]->id.'">'."\n";
  328. if ($showproject)
  329. {
  330. // Project ref
  331. print "<td>";
  332. //if ($showlineingray) print '<i>';
  333. $projectstatic->id=$lines[$i]->fk_project;
  334. $projectstatic->ref=$lines[$i]->projectref;
  335. $projectstatic->public=$lines[$i]->public;
  336. $projectstatic->title=$lines[$i]->projectlabel;
  337. if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId) || ! empty($user->rights->projet->all->lire)) print $projectstatic->getNomUrl(1);
  338. else print $projectstatic->getNomUrl(1,'nolink');
  339. //if ($showlineingray) print '</i>';
  340. print "</td>";
  341. // Project status
  342. print '<td>';
  343. $projectstatic->statut=$lines[$i]->projectstatus;
  344. print $projectstatic->getLibStatut(2);
  345. print "</td>";
  346. }
  347. // Ref of task
  348. print '<td>';
  349. if ($showlineingray)
  350. {
  351. print '<i>'.img_object('','projecttask').' '.$lines[$i]->ref.'</i>';
  352. }
  353. else
  354. {
  355. $taskstatic->id=$lines[$i]->id;
  356. $taskstatic->ref=$lines[$i]->ref;
  357. $taskstatic->label=($taskrole[$lines[$i]->id]?$langs->trans("YourRole").': '.$taskrole[$lines[$i]->id]:'');
  358. print $taskstatic->getNomUrl(1,'withproject');
  359. }
  360. print '</td>';
  361. // Title of task
  362. print "<td>";
  363. if ($showlineingray) print '<i>';
  364. //else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
  365. for ($k = 0 ; $k < $level ; $k++)
  366. {
  367. print "&nbsp; &nbsp; &nbsp;";
  368. }
  369. print $lines[$i]->label;
  370. if ($showlineingray) print '</i>';
  371. //else print '</a>';
  372. print "</td>\n";
  373. // Date start
  374. print '<td align="center">';
  375. print dol_print_date($lines[$i]->date_start,'dayhour');
  376. print '</td>';
  377. // Date end
  378. print '<td align="center">';
  379. $taskstatic->projectstatus = $lines[$i]->projectstatus;
  380. $taskstatic->progress = $lines[$i]->progress;
  381. $taskstatic->fk_statut = $lines[$i]->status;
  382. $taskstatic->datee = $lines[$i]->date_end;
  383. print dol_print_date($lines[$i]->date_end,'dayhour');
  384. if ($taskstatic->hasDelay()) print img_warning($langs->trans("Late"));
  385. print '</td>';
  386. $plannedworkloadoutputformat='allhourmin';
  387. $timespentoutputformat='allhourmin';
  388. if (! empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) $plannedworkloadoutputformat=$conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  389. if (! empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) $timespentoutputformat=$conf->global->PROJECT_TIME_SPENT_FORMAT;
  390. // Planned Workload (in working hours)
  391. print '<td align="right">';
  392. $fullhour=convertSecondToTime($lines[$i]->planned_workload,$plannedworkloadoutputformat);
  393. $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
  394. if ($lines[$i]->planned_workload != '')
  395. {
  396. print $fullhour;
  397. // TODO Add delay taking account of working hours per day and working day per week
  398. //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
  399. }
  400. //else print '--:--';
  401. print '</td>';
  402. // Time spent
  403. print '<td align="right">';
  404. if ($showlineingray) print '<i>';
  405. else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
  406. if ($lines[$i]->duration) print convertSecondToTime($lines[$i]->duration,$timespentoutputformat);
  407. else print '--:--';
  408. if ($showlineingray) print '</i>';
  409. else print '</a>';
  410. print '</td>';
  411. // Progress calculated (Note: ->duration is time spent)
  412. print '<td align="right">';
  413. if ($lines[$i]->planned_workload || $lines[$i]->duration)
  414. {
  415. if ($lines[$i]->planned_workload) print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload,2).' %';
  416. else print '<span class="opacitymedium">'.$langs->trans('WorkloadNotDefined').'</span>';
  417. }
  418. print '</td>';
  419. // Progress declared
  420. print '<td align="right">';
  421. if ($lines[$i]->progress != '')
  422. {
  423. print $lines[$i]->progress.' %';
  424. }
  425. print '</td>';
  426. // Tick to drag and drop
  427. if ($addordertick)
  428. {
  429. print '<td align="center" class="tdlineupdown hideonsmartphone">&nbsp;</td>';
  430. }
  431. print "</tr>\n";
  432. if (! $showlineingray) $inc++;
  433. if ($level >= 0) // Call sublevels
  434. {
  435. $level++;
  436. if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
  437. $level--;
  438. }
  439. $total_projectlinesa_spent += $lines[$i]->duration;
  440. $total_projectlinesa_planned += $lines[$i]->planned_workload;
  441. if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
  442. }
  443. }
  444. else
  445. {
  446. //$level--;
  447. }
  448. }
  449. if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0) && $level <= 0)
  450. {
  451. print '<tr class="liste_total nodrag nodrop">';
  452. print '<td class="liste_total">'.$langs->trans("Total").'</td>';
  453. if ($showproject) print '<td></td><td></td>';
  454. print '<td></td>';
  455. print '<td></td>';
  456. print '<td></td>';
  457. print '<td align="right" class="nowrap liste_total">';
  458. print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
  459. print '</td>';
  460. print '<td align="right" class="nowrap liste_total">';
  461. if ($projectidfortotallink > 0) print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject?'':'&withproject=1').'">';
  462. print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
  463. if ($projectidfortotallink > 0) print '</a>';
  464. print '</td>';
  465. print '<td align="right" class="nowrap liste_total">';
  466. if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned,2).' %';
  467. print '</td>';
  468. print '<td></td>';
  469. if ($addordertick) print '<td class="hideonsmartphone"></td>';
  470. print '</tr>';
  471. }
  472. return $inc;
  473. }
  474. /**
  475. * Output a task line into a pertime intput mode
  476. *
  477. * @param string $inc Line number (start to 0, then increased by recursive call)
  478. * @param string $parent Id of parent task to show (0 to show all)
  479. * @param User|null $fuser Restrict list to user if defined
  480. * @param Task[] $lines Array of lines
  481. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  482. * @param string $projectsrole Array of roles user has on project
  483. * @param string $tasksrole Array of roles user has on task
  484. * @param string $mine Show only task lines I am assigned to
  485. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
  486. * @param int $preselectedday Preselected day
  487. * @param boolean $var Var for css of lines
  488. * @return $inc
  489. */
  490. function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $preselectedday='', $var=false)
  491. {
  492. global $conf, $db, $user, $bc, $langs;
  493. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  494. $lastprojectid=0;
  495. $workloadforid=array();
  496. $lineswithoutlevel0=array();
  497. $numlines=count($lines);
  498. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  499. if ($parent == 0) // Always and only if at first level
  500. {
  501. for ($i = 0 ; $i < $numlines ; $i++)
  502. {
  503. if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
  504. }
  505. }
  506. //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  507. for ($i = 0 ; $i < $numlines ; $i++)
  508. {
  509. if ($parent == 0) $level = 0;
  510. if ($lines[$i]->fk_task_parent == $parent)
  511. {
  512. // If we want all or we have a role on task, we show it
  513. if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
  514. {
  515. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  516. // Break on a new project
  517. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
  518. {
  519. $lastprojectid=$lines[$i]->fk_project;
  520. if ($preselectedday)
  521. {
  522. $projectstatic->id = $lines[$i]->fk_project;
  523. }
  524. }
  525. if (empty($workloadforid[$projectstatic->id]))
  526. {
  527. if ($preselectedday)
  528. {
  529. $projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  530. $workloadforid[$projectstatic->id]=1;
  531. }
  532. }
  533. $projectstatic->id=$lines[$i]->fk_project;
  534. $projectstatic->ref=$lines[$i]->projectref;
  535. $projectstatic->title=$lines[$i]->projectlabel;
  536. $projectstatic->public=$lines[$i]->public;
  537. $taskstatic->id=$lines[$i]->id;
  538. print "<tr ".$bc[$var].">\n";
  539. // Ref
  540. print '<td>';
  541. $taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
  542. print $taskstatic->getNomUrl(1,'withproject');
  543. print '</td>';
  544. // Label task
  545. print "<td>";
  546. for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
  547. $taskstatic->id=$lines[$i]->id;
  548. $taskstatic->ref=$lines[$i]->label;
  549. $taskstatic->date_start=$lines[$i]->date_start;
  550. $taskstatic->date_end=$lines[$i]->date_end;
  551. print $taskstatic->getNomUrl(0,'withproject');
  552. //print "<br>";
  553. //for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
  554. //print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
  555. print "</td>\n";
  556. // Project
  557. print "<td>";
  558. print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  559. print "</td>";
  560. if (! empty($conf->global->PROJECT_LINES_PERDAY_SHOW_THIRDPARTY))
  561. {
  562. // Thirdparty
  563. print '<td class="tdoverflowmax100">';
  564. $thirdpartystatic->id=$lines[$i]->socid;
  565. $thirdpartystatic->name=$lines[$i]->thirdparty_name;
  566. print $thirdpartystatic->getNomUrl(1, 'project', 10);
  567. print '</td>';
  568. }
  569. // Planned Workload
  570. print '<td align="right">';
  571. if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
  572. else print '--:--';
  573. print '</td>';
  574. // Progress declared %
  575. print '<td align="right">';
  576. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
  577. print '</td>';
  578. // Time spent by everybody
  579. print '<td align="right">';
  580. // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user
  581. if ($lines[$i]->duration)
  582. {
  583. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  584. print convertSecondToTime($lines[$i]->duration,'allhourmin');
  585. print '</a>';
  586. }
  587. else print '--:--';
  588. print "</td>\n";
  589. // Time spent by user
  590. print '<td align="right">';
  591. $tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
  592. if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
  593. else print '--:--';
  594. print "</td>\n";
  595. $disabledproject=1;$disabledtask=1;
  596. //print "x".$lines[$i]->fk_project;
  597. //var_dump($lines[$i]);
  598. //var_dump($projectsrole[$lines[$i]->fk_project]);
  599. // If at least one role for project
  600. if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
  601. {
  602. $disabledproject=0;
  603. $disabledtask=0;
  604. }
  605. // If $restricteditformytask is on and I have no role on task, i disable edit
  606. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
  607. {
  608. $disabledtask=1;
  609. }
  610. // Form to add new time
  611. print '<td class="nowrap" align="center">';
  612. $tableCell=$form->select_date($preselectedday,$lines[$i]->id,1,1,2,"addtime",0,0,1,$disabledtask);
  613. print $tableCell;
  614. print '</td><td align="right">';
  615. $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id];
  616. $alreadyspent='';
  617. if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
  618. $tableCell='';
  619. $tableCell.='<span class="timesheetalreadyrecorded"><input type="text" class="center" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
  620. $tableCell.=' + ';
  621. //$tableCell.='&nbsp;&nbsp;&nbsp;';
  622. $tableCell.=$form->select_duration($lines[$i]->id.'duration','',$disabledtask,'text',0,1);
  623. //$tableCell.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled':'').' value="'.$langs->trans("Add").'">';
  624. print $tableCell;
  625. print '</td>';
  626. print '<td align="right">';
  627. if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("YouAreNotContactOfProject"));
  628. else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAffectedToYou"));
  629. print '</td>';
  630. print '<td align="right">';
  631. print '<textarea name="'.$lines[$i]->id.'note" rows="2" id="note">';
  632. print '</textarea>';
  633. print '</td>';
  634. print "</tr>\n";
  635. }
  636. $inc++;
  637. $level++;
  638. if ($lines[$i]->id > 0)
  639. {
  640. if ($parent == 0) projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var);
  641. else projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var);
  642. }
  643. $level--;
  644. }
  645. else
  646. {
  647. //$level--;
  648. }
  649. }
  650. return $inc;
  651. }
  652. /**
  653. * Output a task line into a perday intput mode
  654. *
  655. * @param string $inc Line output identificator (start to 0, then increased by recursive call)
  656. * @param int $firstdaytoshow First day to show
  657. * @param User|null $fuser Restrict list to user if defined
  658. * @param string $parent Id of parent task to show (0 to show all)
  659. * @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task)
  660. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  661. * @param string $projectsrole Array of roles user has on project
  662. * @param string $tasksrole Array of roles user has on task
  663. * @param string $mine Show only task lines I am assigned to
  664. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
  665. * @param boolean $var Var for css of lines
  666. * @return $inc
  667. */
  668. function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $var=false)
  669. {
  670. global $conf, $db, $user, $bc, $langs;
  671. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  672. $numlines=count($lines);
  673. $lastprojectid=0;
  674. $workloadforid=array();
  675. $lineswithoutlevel0=array();
  676. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  677. if ($parent == 0) // Always and only if at first level
  678. {
  679. for ($i = 0 ; $i < $numlines ; $i++)
  680. {
  681. if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
  682. }
  683. }
  684. //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  685. for ($i = 0 ; $i < $numlines ; $i++)
  686. {
  687. if ($parent == 0) $level = 0;
  688. if ($lines[$i]->fk_task_parent == $parent)
  689. {
  690. // If we want all or we have a role on task, we show it
  691. if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
  692. {
  693. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  694. // Break on a new project
  695. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
  696. {
  697. //$var = ! $var;
  698. $lastprojectid=$lines[$i]->fk_project;
  699. $projectstatic->id = $lines[$i]->fk_project;
  700. }
  701. if (empty($workloadforid[$projectstatic->id]))
  702. {
  703. $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  704. $workloadforid[$projectstatic->id]=1;
  705. }
  706. print "<tr ".$bc[$var].">\n";
  707. // Ref
  708. print '<td class="nowrap">';
  709. $taskstatic->id=$lines[$i]->id;
  710. $taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
  711. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  712. print '</td>';
  713. // Label task
  714. print "<td>";
  715. print '<!-- Task id = '.$lines[$i]->id.' -->';
  716. for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
  717. $taskstatic->id=$lines[$i]->id;
  718. $taskstatic->ref=$lines[$i]->label;
  719. $taskstatic->date_start=$lines[$i]->date_start;
  720. $taskstatic->date_end=$lines[$i]->date_end;
  721. print $taskstatic->getNomUrl(0, 'withproject', 'time');
  722. //print "<br>";
  723. //for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
  724. //print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
  725. print "</td>\n";
  726. // Project
  727. print '<td class="nowrap">'.$var;
  728. $projectstatic->id=$lines[$i]->fk_project;
  729. $projectstatic->ref=$lines[$i]->projectref;
  730. $projectstatic->title=$lines[$i]->projectlabel;
  731. $projectstatic->public=$lines[$i]->public;
  732. $projectstatic->thirdparty_name=$lines[$i]->thirdparty_name;
  733. print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  734. print "</td>";
  735. if (! empty($conf->global->PROJECT_LINES_PERWEEK_SHOW_THIRDPARTY))
  736. {
  737. // Thirdparty
  738. print '<td class="tdoverflowmax100">';
  739. $thirdpartystatic->id=$lines[$i]->thirdparty_id;
  740. $thirdpartystatic->name=$lines[$i]->thirdparty_name;
  741. print $thirdpartystatic->getNomUrl(1, 'project');
  742. print '</td>';
  743. }
  744. // Planned Workload
  745. print '<td align="right">';
  746. if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
  747. else print '--:--';
  748. print '</td>';
  749. // Progress declared %
  750. print '<td align="right">';
  751. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
  752. print '</td>';
  753. // Time spent by everybody
  754. print '<td align="right">';
  755. // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user
  756. if ($lines[$i]->duration)
  757. {
  758. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  759. print convertSecondToTime($lines[$i]->duration,'allhourmin');
  760. print '</a>';
  761. }
  762. else print '--:--';
  763. print "</td>\n";
  764. // Time spent by user
  765. print '<td align="right">';
  766. $tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
  767. if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
  768. else print '--:--';
  769. print "</td>\n";
  770. $disabledproject=1;$disabledtask=1;
  771. //print "x".$lines[$i]->fk_project;
  772. //var_dump($lines[$i]);
  773. //var_dump($projectsrole[$lines[$i]->fk_project]);
  774. // If at least one role for project
  775. if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
  776. {
  777. $disabledproject=0;
  778. $disabledtask=0;
  779. }
  780. // If $restricteditformytask is on and I have no role on task, i disable edit
  781. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
  782. {
  783. $disabledtask=1;
  784. }
  785. //var_dump($projectstatic->weekWorkLoadPerTask);
  786. // Fields to show current time
  787. $tableCell=''; $modeinput='hours';
  788. for ($idw = 0; $idw < 7; $idw++)
  789. {
  790. $tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd');
  791. $tmparray=dol_getdate($tmpday);
  792. $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
  793. $alreadyspent='';
  794. if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
  795. $alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']);
  796. $tableCell ='<td align="center" class="hide'.$idw.'">';
  797. if ($alreadyspent)
  798. {
  799. $tableCell.='<span class="timesheetalreadyrecorded"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
  800. //$placeholder=' placeholder="00:00"';
  801. $placeholder='';
  802. //$tableCell.='+';
  803. }
  804. $tableCell.='<input type="text" alt="'.($disabledtask?'':$alttitle).'" title="'.($disabledtask?'':$alttitle).'" '.($disabledtask?'disabled':$placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2" maxlength="5"';
  805. $tableCell.=' onkeypress="return regexEvent(this,event,\'timeChar\')"';
  806. $tableCell.= 'onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
  807. $tableCell.='</td>';
  808. print $tableCell;
  809. }
  810. print '<td align="right">';
  811. if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("YouAreNotContactOfProject"));
  812. else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAffectedToYou"));
  813. print '</td>';
  814. print "</tr>\n";
  815. }
  816. // Call to show task with a lower level (task under the current task)
  817. $inc++;
  818. $level++;
  819. if ($lines[$i]->id > 0)
  820. {
  821. if ($parent == 0) projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $var);
  822. else projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $var);
  823. }
  824. $level--;
  825. }
  826. else
  827. {
  828. //$level--;
  829. }
  830. }
  831. return $inc;
  832. }
  833. /**
  834. * Search in task lines with a particular parent if there is a task for a particular user (in taskrole)
  835. *
  836. * @param string $inc Counter that count number of lines legitimate to show (for return)
  837. * @param int $parent Id of parent task to start
  838. * @param array $lines Array of all tasks
  839. * @param string $taskrole Array of task filtered on a particular user
  840. * @return int 1 if there is
  841. */
  842. function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
  843. {
  844. //print 'Search in line with parent id = '.$parent.'<br>';
  845. $numlines=count($lines);
  846. for ($i = 0 ; $i < $numlines ; $i++)
  847. {
  848. // Process line $lines[$i]
  849. if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent)
  850. {
  851. // If task is legitimate to show, no more need to search deeper
  852. if (isset($taskrole[$lines[$i]->id]))
  853. {
  854. //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
  855. $inc++;
  856. return $inc;
  857. }
  858. searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
  859. //print 'Found inc='.$inc.'<br>';
  860. if ($inc > 0) return $inc;
  861. }
  862. }
  863. return $inc;
  864. }
  865. /**
  866. * Return HTML table with list of projects and number of opened tasks
  867. *
  868. * @param DoliDB $db Database handler
  869. * @param Form $form Object form
  870. * @param int $socid Id thirdparty
  871. * @param int $projectsListId Id of project I have permission on
  872. * @param int $mytasks Limited to task I am contact to
  873. * @param int $statut -1=No filter on statut, 0 or 1 = Filter on status
  874. * @param array $listofoppstatus List of opportunity status
  875. * @param array $hiddenfields List of info to not show ('projectlabel', 'declaredprogress', '...', )
  876. * @return void
  877. */
  878. function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks=0, $statut=-1, $listofoppstatus=array(),$hiddenfields=array())
  879. {
  880. global $langs,$conf,$user,$bc;
  881. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  882. $projectstatic=new Project($db);
  883. $thirdpartystatic=new Societe($db);
  884. $sortfield='';
  885. $sortorder='';
  886. $project_year_filter=0;
  887. $title=$langs->trans("Projects");
  888. if (strcmp($statut, '') && $statut >= 0) $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]);
  889. $arrayidtypeofcontact=array();
  890. print '<table class="noborder" width="100%">';
  891. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  892. if ($mytasks)
  893. {
  894. $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
  895. $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
  896. $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
  897. }
  898. else
  899. {
  900. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  901. }
  902. $sql.= " WHERE p.entity = ".$conf->entity;
  903. $sql.= " AND p.rowid IN (".$projectsListId.")";
  904. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  905. if ($mytasks)
  906. {
  907. $sql.= " AND p.rowid = t.fk_projet";
  908. $sql.= " AND ec.element_id = t.rowid";
  909. $sql.= " AND ec.fk_socpeople = ".$user->id;
  910. $sql.= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
  911. $sql.= " AND ctc.element = 'project_task'";
  912. }
  913. if ($statut >= 0)
  914. {
  915. $sql.= " AND p.fk_statut = ".$statut;
  916. }
  917. if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
  918. {
  919. $project_year_filter = GETPOST("project_year_filter");
  920. //Check if empty or invalid year. Wildcard ignores the sql check
  921. if ($project_year_filter != "*")
  922. {
  923. if (empty($project_year_filter) || !ctype_digit($project_year_filter))
  924. {
  925. $project_year_filter = date("Y");
  926. }
  927. $sql.= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter,12,false)).")";
  928. $sql.= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter,1,false)).")";
  929. }
  930. }
  931. // Get id of project we must show tasks
  932. $arrayidofprojects=array();
  933. $sql1 = "SELECT p.rowid as projectid";
  934. $sql1.= $sql;
  935. $resql = $db->query($sql1);
  936. if ($resql)
  937. {
  938. $i=0;
  939. $num = $db->num_rows($resql);
  940. while ($i < $num)
  941. {
  942. $objp = $db->fetch_object($resql);
  943. $arrayidofprojects[$objp->projectid]=$objp->projectid;
  944. $i++;
  945. }
  946. }
  947. else dol_print_error($db);
  948. if (empty($arrayidofprojects)) $arrayidofprojects[0]=-1;
  949. // Get list of project with calculation on tasks
  950. $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc, s.nom as socname, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount,";
  951. $sql2.= " p.dateo, p.datee,";
  952. $sql2.= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
  953. $sql2.= " FROM ".MAIN_DB_PREFIX."projet as p";
  954. $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  955. $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  956. $sql2.= " WHERE p.rowid IN (".join(',',$arrayidofprojects).")";
  957. $sql2.= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.nom, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount, p.dateo, p.datee";
  958. $sql2.= " ORDER BY p.title, p.ref";
  959. $var=true;
  960. $resql = $db->query($sql2);
  961. if ($resql)
  962. {
  963. $total_task = 0;
  964. $total_opp_amount = 0;
  965. $ponderated_opp_amount = 0;
  966. $num = $db->num_rows($resql);
  967. $i = 0;
  968. print '<tr class="liste_titre">';
  969. print_liste_field_titre($title.' <span class="badge">'.$num.'</span>',$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
  970. print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
  971. if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
  972. {
  973. print_liste_field_titre($langs->trans("OpportunityAmount"),"","","","",'align="right"',$sortfield,$sortorder);
  974. print_liste_field_titre($langs->trans("OpportunityStatus"),"","","","",'align="right"',$sortfield,$sortorder);
  975. }
  976. if (empty($conf->global->PROJECT_HIDE_TASKS))
  977. {
  978. print_liste_field_titre($langs->trans("Tasks"),"","","","",'align="right"',$sortfield,$sortorder);
  979. if (! in_array('plannedworkload', $hiddenfields)) print_liste_field_titre($langs->trans("PlannedWorkload"),"","","","",'align="right"',$sortfield,$sortorder);
  980. if (! in_array('declaredprogress', $hiddenfields)) print_liste_field_titre($langs->trans("ProgressDeclared"),"","","","",'align="right"',$sortfield,$sortorder);
  981. }
  982. print_liste_field_titre($langs->trans("Status"),"","","","",'align="right"',$sortfield,$sortorder);
  983. print "</tr>\n";
  984. while ($i < $num)
  985. {
  986. $objp = $db->fetch_object($resql);
  987. $projectstatic->id = $objp->projectid;
  988. $projectstatic->user_author_id = $objp->fk_user_creat;
  989. $projectstatic->public = $objp->public;
  990. // Check is user has read permission on project
  991. $userAccess = $projectstatic->restrictedProjectArea($user);
  992. if ($userAccess >= 0)
  993. {
  994. $projectstatic->ref=$objp->ref;
  995. $projectstatic->statut = $objp->status;
  996. $projectstatic->title = $objp->title;
  997. $projectstatic->datee = $db->jdate($objp->datee);
  998. $projectstatic->dateo = $db->jdate($objp->dateo);
  999. print '<tr class="oddeven">';
  1000. print '<td>';
  1001. print $projectstatic->getNomUrl(1);
  1002. if (! in_array('projectlabel', $hiddenfields)) print '<br>'.dol_trunc($objp->title,24);
  1003. print '</td>';
  1004. print '<td>';
  1005. if ($objp->fk_soc > 0)
  1006. {
  1007. $thirdpartystatic->id=$objp->fk_soc;
  1008. $thirdpartystatic->ref=$objp->socname;
  1009. $thirdpartystatic->name=$objp->socname;
  1010. print $thirdpartystatic->getNomUrl(1);
  1011. }
  1012. print '</td>';
  1013. if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
  1014. {
  1015. print '<td align="right">';
  1016. if ($objp->opp_amount) print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency);
  1017. print '</td>';
  1018. print '<td align="right">';
  1019. $code = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
  1020. if ($code) print $langs->trans("OppStatus".$code);
  1021. print '</td>';
  1022. }
  1023. if (empty($conf->global->PROJECT_HIDE_TASKS))
  1024. {
  1025. print '<td align="right">'.$objp->nb.'</td>';
  1026. $plannedworkload=$objp->planned_workload;
  1027. $total_plannedworkload+=$plannedworkload;
  1028. if (! in_array('plannedworkload', $hiddenfields))
  1029. {
  1030. print '<td align="right">'.($plannedworkload?convertSecondToTime($plannedworkload):'').'</td>';
  1031. }
  1032. if (! in_array('declaredprogress', $hiddenfields))
  1033. {
  1034. $declaredprogressworkload=$objp->declared_progess_workload;
  1035. $total_declaredprogressworkload+=$declaredprogressworkload;
  1036. print '<td align="right">';
  1037. //print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>";
  1038. print ($plannedworkload?round(100*$declaredprogressworkload/$plannedworkload,0).'%':'');
  1039. print '</td>';
  1040. }
  1041. }
  1042. print '<td align="right">'.$projectstatic->getLibStatut(3).'</td>';
  1043. print "</tr>\n";
  1044. $total_task = $total_task + $objp->nb;
  1045. $total_opp_amount = $total_opp_amount + $objp->opp_amount;
  1046. $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$objp->opp_status] * $objp->opp_amount / 100);
  1047. }
  1048. $i++;
  1049. }
  1050. print '<tr class="liste_total">';
  1051. print '<td colspan="2">'.$langs->trans("Total")."</td>";
  1052. if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
  1053. {
  1054. print '<td class="liste_total" align="right">'.price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency).'</td>';
  1055. print '<td class="liste_total" align="right">'.$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1).'</td>';
  1056. }
  1057. if (empty($conf->global->PROJECT_HIDE_TASKS))
  1058. {
  1059. print '<td class="liste_total" align="right">'.$total_task.'</td>';
  1060. if (! in_array('plannedworkload', $hiddenfields)) print '<td class="liste_total" align="right">'.($total_plannedworkload?convertSecondToTime($total_plannedworkload):'').'</td>';
  1061. if (! in_array('declaredprogress', $hiddenfields)) print '<td class="liste_total" align="right">'.($total_plannedworkload?round(100*$total_declaredprogressworkload/$total_plannedworkload,0).'%':'').'</td>';
  1062. }
  1063. print '<td class="liste_total"></td>';
  1064. print '</tr>';
  1065. $db->free($resql);
  1066. }
  1067. else
  1068. {
  1069. dol_print_error($db);
  1070. }
  1071. print "</table>";
  1072. if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
  1073. {
  1074. //Add the year filter input
  1075. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
  1076. print '<table width="100%">';
  1077. print '<tr>';
  1078. print '<td>'.$langs->trans("Year").'</td>';
  1079. print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="'.$project_year_filter.'"/>';
  1080. print "</tr>\n";
  1081. print '</table></form>';
  1082. }
  1083. }