project.lib.php 46 KB

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