project.lib.php 42 KB

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