PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/lib/project.lib.php

https://github.com/asterix14/dolibarr
PHP | 711 lines | 467 code | 97 blank | 147 comment | 109 complexity | dd66f1ed41e157da5321e25b8b7f0010 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  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 2 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. function project_prepare_head($object)
  27. {
  28. global $langs, $conf, $user;
  29. $h = 0;
  30. $head = array();
  31. $head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$object->id;
  32. $head[$h][1] = $langs->trans("Project");
  33. $head[$h][2] = 'project';
  34. $h++;
  35. $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
  36. $head[$h][1] = $langs->trans("ProjectContact");
  37. $head[$h][2] = 'contact';
  38. $h++;
  39. if ($conf->fournisseur->enabled || $conf->propal->enabled || $conf->commande->enabled || $conf->facture->enabled || $conf->contrat->enabled
  40. || $conf->ficheinter->enabled || $conf->agenda->enabled || $conf->deplacement->enabled)
  41. {
  42. $head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$object->id;
  43. $head[$h][1] = $langs->trans("Referers");
  44. $head[$h][2] = 'element';
  45. $h++;
  46. }
  47. // Show more tabs from modules
  48. // Entries must be declared in modules descriptor with line
  49. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  50. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  51. complete_head_from_modules($conf,$langs,$object,$head,$h,'project');
  52. $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
  53. /*$filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
  54. include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
  55. $listoffiles=dol_dir_list($filesdir,'files',1);
  56. $head[$h][1] = (count($listoffiles)?$langs->trans('DocumentsNb',count($listoffiles)):$langs->trans('Documents'));*/
  57. $head[$h][1] = $langs->trans('Documents');
  58. $head[$h][2] = 'document';
  59. $h++;
  60. $head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
  61. $head[$h][1] = $langs->trans('Notes');
  62. $head[$h][2] = 'note';
  63. $h++;
  64. // Then tab for sub level of projet, i mean tasks
  65. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id;
  66. $head[$h][1] = $langs->trans("Tasks");
  67. $head[$h][2] = 'tasks';
  68. $h++;
  69. /* Now this is a filter in the Task tab.
  70. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id.'&mode=mine';
  71. $head[$h][1] = $langs->trans("MyTasks");
  72. $head[$h][2] = 'mytasks';
  73. $h++;
  74. */
  75. $head[$h][0] = DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id;
  76. $head[$h][1] = $langs->trans("Gantt");
  77. $head[$h][2] = 'gantt';
  78. $h++;
  79. return $head;
  80. }
  81. /**
  82. * \file htdocs/core/lib/project.lib.php
  83. * \brief Ensemble de fonctions de base pour le module projet
  84. * \ingroup societe
  85. */
  86. function task_prepare_head($object)
  87. {
  88. global $langs, $conf, $user;
  89. $h = 0;
  90. $head = array();
  91. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id;
  92. $head[$h][1] = $langs->trans("Card");
  93. $head[$h][2] = 'task';
  94. $h++;
  95. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id;
  96. $head[$h][1] = $langs->trans("TaskRessourceLinks");
  97. $head[$h][2] = 'contact';
  98. $h++;
  99. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id;
  100. $head[$h][1] = $langs->trans("TimeSpent");
  101. $head[$h][2] = 'time';
  102. $h++;
  103. // Show more tabs from modules
  104. // Entries must be declared in modules descriptor with line
  105. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  106. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  107. complete_head_from_modules($conf,$langs,$object,$head,$h,'task');
  108. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id;
  109. /*$filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
  110. include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
  111. $listoffiles=dol_dir_list($filesdir,'files',1);
  112. $head[$h][1] = (count($listoffiles)?$langs->trans('DocumentsNb',count($listoffiles)):$langs->trans('Documents'));*/
  113. $head[$h][1] = $langs->trans('Documents');
  114. $head[$h][2] = 'document';
  115. $h++;
  116. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id;
  117. $head[$h][1] = $langs->trans('Notes');
  118. $head[$h][2] = 'note';
  119. $h++;
  120. return $head;
  121. }
  122. /**
  123. * Show a combo list with projects qualified for a third party
  124. *
  125. * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
  126. * @param int $selected Id project preselected
  127. * @param string $htmlname Nom de la zone html
  128. * @return int Nbre of project if OK, <0 if KO
  129. */
  130. function select_projects($socid=-1, $selected='', $htmlname='projectid')
  131. {
  132. global $db,$user,$conf,$langs;
  133. $hideunselectables = false;
  134. if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
  135. $projectstatic=new Project($db);
  136. $projectsListId = '';
  137. if (empty($user->rights->projet->all->lire))
  138. {
  139. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
  140. }
  141. // On recherche les projets
  142. $sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public';
  143. $sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
  144. $sql.= " WHERE p.entity = ".$conf->entity;
  145. if ($projectsListId) $sql.= " AND p.rowid in (".$projectsListId.")";
  146. if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
  147. //if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc='0' OR p.fk_soc IS NULL)"; // We will filter later
  148. $sql.= " ORDER BY p.title ASC";
  149. //print $sql;
  150. //var_dump($user->rights);
  151. dol_syslog("project.lib::select_projects sql=".$sql);
  152. $resql=$db->query($sql);
  153. if ($resql)
  154. {
  155. print '<select class="flat" name="'.$htmlname.'">';
  156. print '<option value="0">&nbsp;</option>';
  157. $num = $db->num_rows($resql);
  158. $i = 0;
  159. if ($num)
  160. {
  161. while ($i < $num)
  162. {
  163. $obj = $db->fetch_object($resql);
  164. // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
  165. if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
  166. {
  167. // Do nothing
  168. }
  169. else
  170. {
  171. $labeltoshow=dol_trunc($obj->ref,16);
  172. //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
  173. //else $labeltoshow.=' ('.$langs->trans("Private").')';
  174. if (!empty($selected) && $selected == $obj->rowid && $obj->fk_statut > 0)
  175. {
  176. print '<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.'</option>';
  177. }
  178. else
  179. {
  180. $disabled=0;
  181. if (! $obj->fk_statut > 0)
  182. {
  183. $disabled=1;
  184. $labeltoshow.=' - '.$langs->trans("Draft");
  185. }
  186. if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
  187. {
  188. $disabled=1;
  189. $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
  190. }
  191. if ($hideunselectables && $disabled)
  192. {
  193. $resultat='';
  194. }
  195. else
  196. {
  197. $resultat='<option value="'.$obj->rowid.'"';
  198. if ($disabled) $resultat.=' disabled="disabled"';
  199. //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
  200. //else $labeltoshow.=' ('.$langs->trans("Private").')';
  201. $resultat.='>'.$labeltoshow;
  202. if (! $disabled) $resultat.=' - '.dol_trunc($obj->title,12);
  203. $resultat.='</option>';
  204. }
  205. print $resultat;
  206. }
  207. }
  208. $i++;
  209. }
  210. }
  211. print '</select>';
  212. $db->free($resql);
  213. return $num;
  214. }
  215. else
  216. {
  217. dol_print_error($db);
  218. return -1;
  219. }
  220. }
  221. /**
  222. * Output a task line
  223. * @param $inc
  224. * @param $parent
  225. * @param $lines
  226. * @param $level
  227. * @param $projectsrole
  228. * @param $tasksrole
  229. * @param $mytask 0 or 1 to enable only if task is a task i am affected to
  230. * @return $inc
  231. */
  232. function PLinesb(&$inc, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mytask=0)
  233. {
  234. global $user, $bc, $langs;
  235. global $form;
  236. $lastprojectid=0;
  237. $projectstatic = new Project($db);
  238. $taskstatic = new Task($db);
  239. $var=true;
  240. $numlines=count($lines);
  241. for ($i = 0 ; $i < $numlines ; $i++)
  242. {
  243. if ($parent == 0) $level = 0;
  244. if ($lines[$i]->fk_parent == $parent)
  245. {
  246. // Break on a new project
  247. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
  248. {
  249. $var = !$var;
  250. $lastprojectid=$lines[$i]->fk_project;
  251. }
  252. print "<tr $bc[$var]>\n";
  253. // Project
  254. print "<td>";
  255. $projectstatic->id=$lines[$i]->fk_project;
  256. $projectstatic->ref=$lines[$i]->projectref;
  257. $projectstatic->public=$lines[$i]->public;
  258. $projectstatic->label=$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project];
  259. print $projectstatic->getNomUrl(1);
  260. print "</td>";
  261. // Ref
  262. print '<td>';
  263. $taskstatic->id=$lines[$i]->id;
  264. $taskstatic->ref=$lines[$i]->id;
  265. print $taskstatic->getNomUrl(1);
  266. print '</td>';
  267. // Label task
  268. print "<td>";
  269. for ($k = 0 ; $k < $level ; $k++)
  270. {
  271. print "&nbsp;&nbsp;&nbsp;";
  272. }
  273. print $lines[$i]->label;
  274. print "</td>\n";
  275. // Time spent
  276. print '<td align="right">';
  277. if ($lines[$i]->duration) print ConvertSecondToTime($lines[$i]->duration,'all');
  278. else print '--:--';
  279. print "</td>\n";
  280. $disabledproject=1;$disabledtask=1;
  281. //print "x".$lines[$i]->fk_project;
  282. //var_dump($lines[$i]);
  283. //var_dump($projectsrole[$lines[$i]->fk_project]);
  284. // If at least one role for project
  285. if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
  286. {
  287. $disabledproject=0;
  288. $disabledtask=0;
  289. }
  290. // If mytask and no role on task
  291. if ($mytask && empty($tasksrole[$lines[$i]->id]))
  292. {
  293. $disabledtask=1;
  294. }
  295. print '<td nowrap="nowrap">';
  296. print $form->select_date('',$lines[$i]->id,'','','',"addtime",1,0,1,$disabledtask);
  297. print '&nbsp;&nbsp;&nbsp;';
  298. print $form->select_duration($lines[$i]->id,'',$disabledtask);
  299. print '&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled="disabled"':'').' value="'.$langs->trans("Add").'">';
  300. if ($disabledtask) print '('.$langs->trans("TaskIsNotAffectedToYou").')';
  301. if ((! $lines[$i]->public) && $disabledproject) print '('.$langs->trans("YouAreNotContactOfProject").')';
  302. print '</td>';
  303. print "<td>&nbsp;";
  304. print '</td>';
  305. print "</tr>\n";
  306. $inc++;
  307. $level++;
  308. if ($lines[$i]->id) PLinesb($inc, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mytask);
  309. $level--;
  310. }
  311. else
  312. {
  313. //$level--;
  314. }
  315. }
  316. return $inc;
  317. }
  318. /**
  319. * Show task lines with a particular parent
  320. * @param $inc Counter that count number of lines legitimate to show (for return)
  321. * @param $parent Id of parent task to start
  322. * @param $lines Array of all tasks
  323. * @param $level Level of task
  324. * @param $var Color
  325. * @param $showproject Show project columns
  326. * @param $taskrole Array of roles of user for each tasks
  327. * @param $projectsListId List of id of project allowed to user (separated with comma)
  328. */
  329. function PLines(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='')
  330. {
  331. global $user, $bc, $langs;
  332. $lastprojectid=0;
  333. $projectstatic = new Project($db);
  334. $taskstatic = new Task($db);
  335. $projectsArrayId=explode(',',$projectsListId);
  336. $numlines=count($lines);
  337. $total=0;
  338. for ($i = 0 ; $i < $numlines ; $i++)
  339. {
  340. if ($parent == 0) $level = 0;
  341. // Process line
  342. // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
  343. if ($lines[$i]->fk_parent == $parent)
  344. {
  345. // Show task line.
  346. $showline=1;
  347. $showlineingray=0;
  348. // If there is filters to use
  349. if (is_array($taskrole))
  350. {
  351. // If task not legitimate to show, search if a legitimate task exists later in tree
  352. if (! isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent)
  353. {
  354. // So search if task has a subtask legitimate to show
  355. $foundtaskforuserdeeper=0;
  356. SearchTaskInChild($foundtaskforuserdeeper,$lines[$i]->id,$lines,$taskrole);
  357. //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
  358. if ($foundtaskforuserdeeper > 0)
  359. {
  360. $showlineingray=1; // We will show line but in gray
  361. }
  362. else
  363. {
  364. $showline=0; // No reason to show line
  365. }
  366. }
  367. }
  368. if ($showline)
  369. {
  370. // Break on a new project
  371. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
  372. {
  373. $var = !$var;
  374. $lastprojectid=$lines[$i]->fk_project;
  375. }
  376. print "<tr ".$bc[$var].">\n";
  377. // Project
  378. if ($showproject)
  379. {
  380. print "<td>";
  381. //var_dump($taskrole);
  382. if ($showlineingray) print '<i>';
  383. $projectstatic->id=$lines[$i]->fk_project;
  384. $projectstatic->ref=$lines[$i]->projectref;
  385. $projectstatic->public=$lines[$i]->public;
  386. if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId)) print $projectstatic->getNomUrl(1);
  387. else print $projectstatic->getNomUrl(1,'nolink');
  388. if ($showlineingray) print '</i>';
  389. print "</td>";
  390. }
  391. // Ref of task
  392. print '<td>';
  393. if ($showlineingray)
  394. {
  395. print '<i>'.img_object('','projecttask').' '.$lines[$i]->id.'</i>';
  396. }
  397. else
  398. {
  399. $taskstatic->id=$lines[$i]->id;
  400. $taskstatic->ref=$lines[$i]->id;
  401. $taskstatic->label=($taskrole[$lines[$i]->id]?$langs->trans("YourRole").': '.$taskrole[$lines[$i]->id]:'');
  402. print $taskstatic->getNomUrl(1);
  403. }
  404. print '</td>';
  405. // Title of task
  406. print "<td>";
  407. if ($showlineingray) print '<i>';
  408. else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'">';
  409. for ($k = 0 ; $k < $level ; $k++)
  410. {
  411. print "&nbsp; &nbsp; &nbsp;";
  412. }
  413. print $lines[$i]->label;
  414. if ($showlineingray) print '</i>';
  415. else print '</a>';
  416. print "</td>\n";
  417. // Progress
  418. print '<td align="right">';
  419. print $lines[$i]->progress.' %';
  420. print '</td>';
  421. // Time spent
  422. print '<td align="right">';
  423. if ($showlineingray) print '<i>';
  424. else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  425. if ($lines[$i]->duration) print ConvertSecondToTime($lines[$i]->duration,'all');
  426. else print '--:--';
  427. if ($showlineingray) print '</i>';
  428. else print '</a>';
  429. print '</td>';
  430. print "</tr>\n";
  431. if (! $showlineingray) $inc++;
  432. $level++;
  433. if ($lines[$i]->id) PLines($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId);
  434. $level--;
  435. $total += $lines[$i]->duration;
  436. }
  437. }
  438. else
  439. {
  440. //$level--;
  441. }
  442. }
  443. if ($total>0)
  444. {
  445. print '<tr class="liste_total"><td class="liste_total">'.$langs->trans("Total").'</td>';
  446. print '<td></td>';
  447. print '<td></td>';
  448. print '<td align="right" nowrap="nowrap" class="liste_total">'.ConvertSecondToTime($total).'</td></tr>';
  449. }
  450. return $inc;
  451. }
  452. /**
  453. * Search in task lines with a particular parent if there is a task for a particular user (in taskrole)
  454. * @param $inc Counter that count number of lines legitimate to show (for return)
  455. * @param $parent Id of parent task to start
  456. * @param $lines Array of all tasks
  457. * @param $taskrole Array of task filtered on a particular user
  458. * @return int 1 if there is
  459. */
  460. function SearchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
  461. {
  462. //print 'Search in line with parent id = '.$parent.'<br>';
  463. $numlines=count($lines);
  464. for ($i = 0 ; $i < $numlines ; $i++)
  465. {
  466. // Process line $lines[$i]
  467. if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent)
  468. {
  469. // If task is legitimate to show, no more need to search deeper
  470. if (isset($taskrole[$lines[$i]->id]))
  471. {
  472. //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
  473. $inc++;
  474. return $inc;
  475. }
  476. SearchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
  477. //print 'Found inc='.$inc.'<br>';
  478. if ($inc > 0) return $inc;
  479. }
  480. }
  481. return $inc;
  482. }
  483. /**
  484. * Clean task not linked to a parent
  485. * @param $db Database handler
  486. * @return int Nb of records deleted
  487. */
  488. function clean_orphelins($db)
  489. {
  490. $nb=0;
  491. // There is orphelins. We clean that
  492. $listofid=array();
  493. // Get list of id in array listofid
  494. $sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task';
  495. $resql = $db->query($sql);
  496. if ($resql)
  497. {
  498. $num = $db->num_rows($resql);
  499. $i = 0;
  500. while ($i < $num && $i < 100)
  501. {
  502. $obj = $db->fetch_object($resql);
  503. $listofid[]=$obj->rowid;
  504. $i++;
  505. }
  506. }
  507. else
  508. {
  509. dol_print_error($db);
  510. }
  511. if (count($listofid))
  512. {
  513. // Removed orphelins records
  514. print 'Some orphelins were found and restored to be parents so records are visible again: ';
  515. print join(',',$listofid);
  516. $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
  517. $sql.= " SET fk_task_parent = 0";
  518. $sql.= " WHERE fk_task_parent NOT IN (".join(',',$listofid).")";
  519. $resql = $db->query($sql);
  520. if ($resql)
  521. {
  522. $nb=$db->affected_rows($sql);
  523. return $nb;
  524. }
  525. else
  526. {
  527. return -1;
  528. }
  529. }
  530. }
  531. /**
  532. * Return HTML table with list of projects and number of opened tasks
  533. *
  534. * @param $db
  535. * @param $socid
  536. * @param $projectsListId Id of project i have permission on
  537. * @param $mytasks Limited to task i am contact to
  538. */
  539. function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0)
  540. {
  541. global $langs,$conf,$user,$bc;
  542. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  543. $projectstatic=new Project($db);
  544. $sortfield='';
  545. $sortorder='';
  546. print '<table class="noborder" width="100%">';
  547. print '<tr class="liste_titre">';
  548. print_liste_field_titre($langs->trans("Project"),"index.php","","","","",$sortfield,$sortorder);
  549. print_liste_field_titre($langs->trans("NbOpenTasks"),"","","","",'align="right"',$sortfield,$sortorder);
  550. print_liste_field_titre($langs->trans("Status"),"","","","",'align="right"',$sortfield,$sortorder);
  551. print "</tr>\n";
  552. $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut, COUNT(t.rowid) as nb";
  553. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  554. if ($mytasks)
  555. {
  556. $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
  557. $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
  558. $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
  559. }
  560. else
  561. {
  562. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  563. }
  564. $sql.= " WHERE p.entity = ".$conf->entity;
  565. $sql.= " AND p.rowid IN (".$projectsListId.")";
  566. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  567. if ($mytasks)
  568. {
  569. $sql.= " AND p.rowid = t.fk_projet";
  570. $sql.= " AND ec.element_id = t.rowid";
  571. $sql.= " AND ctc.rowid = ec.fk_c_type_contact";
  572. $sql.= " AND ctc.element = 'project_task'";
  573. $sql.= " AND ec.fk_socpeople = ".$user->id;
  574. }
  575. $sql.= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut";
  576. $sql.= " ORDER BY p.title, p.ref";
  577. $var=true;
  578. $resql = $db->query($sql);
  579. if ( $resql )
  580. {
  581. $num = $db->num_rows($resql);
  582. $i = 0;
  583. while ($i < $num)
  584. {
  585. $objp = $db->fetch_object($resql);
  586. $projectstatic->id = $objp->projectid;
  587. $projectstatic->user_author_id = $objp->fk_user_creat;
  588. $projectstatic->public = $objp->public;
  589. // Check is user has read permission on project
  590. $userAccess = $projectstatic->restrictedProjectArea($user,1);
  591. if ($userAccess >= 0)
  592. {
  593. $var=!$var;
  594. print "<tr ".$bc[$var].">";
  595. print '<td nowrap="nowrap">';
  596. $projectstatic->ref=$objp->ref;
  597. print $projectstatic->getNomUrl(1);
  598. print ' - '.$objp->title.'</td>';
  599. print '<td align="right">'.$objp->nb.'</td>';
  600. $projectstatic->statut = $objp->fk_statut;
  601. print '<td align="right">'.$projectstatic->getLibStatut(3).'</td>';
  602. print "</tr>\n";
  603. }
  604. $i++;
  605. }
  606. $db->free($resql);
  607. }
  608. else
  609. {
  610. dol_print_error($db);
  611. }
  612. print "</table>";
  613. }
  614. ?>