index.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  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. */
  19. /**
  20. * \file htdocs/projet/index.php
  21. * \ingroup projet
  22. * \brief Main project home page
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. $langs->load("projects");
  29. $langs->load("companies");
  30. $mine = GETPOST('mode')=='mine' ? 1 : 0;
  31. // Security check
  32. $socid=0;
  33. if ($user->societe_id > 0) $socid=$user->societe_id;
  34. if (!$user->rights->projet->lire) accessforbidden();
  35. $sortfield = GETPOST("sortfield",'alpha');
  36. $sortorder = GETPOST("sortorder",'alpha');
  37. /*
  38. * View
  39. */
  40. $socstatic=new Societe($db);
  41. $projectstatic=new Project($db);
  42. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,($mine?$mine:(empty($user->rights->projet->all->lire)?0:2)),1);
  43. //var_dump($projectsListId);
  44. llxHeader("",$langs->trans("Projects"),"EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos");
  45. $text=$langs->trans("Projects");
  46. if ($mine) $text=$langs->trans("MyProjects");
  47. print_fiche_titre($text);
  48. // Show description of content
  49. if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>';
  50. else
  51. {
  52. if (! empty($user->rights->projet->all->lire) && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>';
  53. else print $langs->trans("ProjectsPublicDesc").'<br><br>';
  54. }
  55. print '<div class="fichecenter"><div class="fichethirdleft">';
  56. // Search project
  57. if (! empty($conf->projet->enabled) && $user->rights->projet->lire)
  58. {
  59. $var=false;
  60. print '<form method="post" action="'.DOL_URL_ROOT.'/projet/list.php">';
  61. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  62. print '<table class="noborder nohover" width="100%">';
  63. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProject").'</td></tr>';
  64. print '<tr '.$bc[$var].'>';
  65. print '<td class="nowrap"><label for="sf_ref">'.$langs->trans("Ref").'</label>:</td><td><input type="text" class="flat" name="search_ref" id="sf_ref" size="18"></td>';
  66. print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  67. print '<tr '.$bc[$var].'><td class="nowrap"><label for="sall">'.$langs->trans("Other").'</label>:</td><td><input type="text" class="flat" name="search_all" id="search_all" size="18"></td>';
  68. print '</tr>';
  69. print "</table></form>\n";
  70. print "<br>\n";
  71. }
  72. print_projecttasks_array($db,$socid,$projectsListId,0,0);
  73. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  74. print '<table class="noborder" width="100%">';
  75. print '<tr class="liste_titre">';
  76. print_liste_field_titre($langs->trans("ThirdParties"),$_SERVER["PHP_SELF"],"s.nom","","","",$sortfield,$sortorder);
  77. print_liste_field_titre($langs->trans("NbOfProjects"),"","","","",'align="right"',$sortfield,$sortorder);
  78. print "</tr>\n";
  79. $sql = "SELECT count(p.rowid) as nb";
  80. $sql.= ", s.nom, s.rowid as socid";
  81. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  82. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  83. $sql.= " WHERE p.entity = ".$conf->entity;
  84. if ($mine || empty($user->rights->projet->all->lire)) $sql.= " AND p.rowid IN (".$projectsListId.")";
  85. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  86. $sql.= " GROUP BY s.nom, s.rowid";
  87. $var=true;
  88. $resql = $db->query($sql);
  89. if ( $resql )
  90. {
  91. $num = $db->num_rows($resql);
  92. $i = 0;
  93. while ($i < $num)
  94. {
  95. $obj = $db->fetch_object($resql);
  96. $var=!$var;
  97. print "<tr ".$bc[$var].">";
  98. print '<td class="nowrap">';
  99. if ($obj->socid)
  100. {
  101. $socstatic->id=$obj->socid;
  102. $socstatic->nom=$obj->nom;
  103. print $socstatic->getNomUrl(1);
  104. }
  105. else
  106. {
  107. print $langs->trans("OthersNotLinkedToThirdParty");
  108. }
  109. print '</td>';
  110. print '<td align="right"><a href="'.DOL_URL_ROOT.'/projet/list.php?socid='.$obj->socid.'">'.$obj->nb.'</a></td>';
  111. print "</tr>\n";
  112. $i++;
  113. }
  114. $db->free($resql);
  115. }
  116. else
  117. {
  118. dol_print_error($db);
  119. }
  120. print "</table>";
  121. print '</div></div></div>';
  122. // Tasks for all resources of all opened projects and time spent for each task/resource
  123. print '<div class="fichecenter">';
  124. $sql = "SELECT p.ref, p.title, p.rowid as projectid, t.label, t.rowid as taskid, u.rowid as userid, t.planned_workload, t.dateo, t.datee, SUM(tasktime.task_duration) as timespent";
  125. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  126. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  127. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."projet_task as t on t.fk_projet = p.rowid";
  128. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."projet_task_time as tasktime on tasktime.fk_task = t.rowid";
  129. $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u on tasktime.fk_user = u.rowid";
  130. $sql.= " WHERE p.entity = ".$conf->entity;
  131. if ($mine || ! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";
  132. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  133. $sql.= " AND p.fk_statut=1";
  134. $sql.= " GROUP BY p.title, p.rowid, t.label, t.rowid, u.rowid, t.planned_workload, t.dateo, t.datee";
  135. $sql.= " ORDER BY u.rowid, t.dateo, t.datee";
  136. $userstatic=new User($db);
  137. dol_syslog('projet:index.php: affectationpercent', LOG_DEBUG);
  138. $resql = $db->query($sql);
  139. if ( $resql )
  140. {
  141. $num = $db->num_rows($resql);
  142. $i = 0;
  143. if ($num > (empty($conf->global->PROJECT_LIMIT_TASK_PROJECT_AREA)?1000:$conf->global->PROJECT_LIMIT_TASK_PROJECT_AREA))
  144. {
  145. /* $langs->load("errors");
  146. print '<tr '.$bc[0].'>';
  147. print '<td colspan="9">';
  148. print $langs->trans("WarningTooManyDataPleaseUseMoreFilters");
  149. print '</td></tr>';*/
  150. }
  151. else
  152. {
  153. print '<br>';
  154. print_fiche_titre($langs->trans("TimeSpent"),'','').'<br>';
  155. print '<table class="noborder" width="100%">';
  156. print '<tr class="liste_titre">';
  157. print '<th>'.$langs->trans('TaskRessourceLinks').'</th>';
  158. print '<th>'.$langs->trans('Projects').'</th>';
  159. print '<th>'.$langs->trans('Task').'</th>';
  160. print '<th>'.$langs->trans('DateStart').'</th>';
  161. print '<th>'.$langs->trans('DateEnd').'</th>';
  162. print '<th>'.$langs->trans('TimeSpent').'</th>';
  163. print '</tr>';
  164. while ($i < $num)
  165. {
  166. $obj = $db->fetch_object($resql);
  167. $var=!$var;
  168. $username='';
  169. if ($obj->userid && $userstatic->id != $obj->userid) // We have a user and it is not last loaded user
  170. {
  171. $result=$userstatic->fetch($obj->userid);
  172. if (! $result) $userstatic->id=0;
  173. }
  174. if ($userstatic->id) $username = $userstatic->getNomUrl(0,0);
  175. print "<tr ".$bc[$var].">";
  176. print '<td>'.$username.'</td>';
  177. print '<td>';
  178. $projectstatic->id=$obj->projectid;
  179. $projectstatic->ref=$obj->ref;
  180. $projectstatic->title=$obj->title;
  181. print $projectstatic->getNomUrl(1,'',16);
  182. //print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$obj->projectid.'">'.$obj->title.'</a>';
  183. print '</td>';
  184. print '<td><a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$obj->taskid.'&withproject=1">'.$obj->label.'</a></td>';
  185. print '<td>'.dol_print_date($db->jdate($obj->dateo)).'</td>';
  186. print '<td>'.dol_print_date($db->jdate($obj->datee)).'</td>';
  187. /* I disable this because information is wrong. This percent has no meaning for a particular resource. What do we want ?
  188. * Percent of completion ?
  189. * If we want to show completion, we must remove "user" into list,
  190. if (empty($obj->planned_workload)) {
  191. $percentcompletion = $langs->trans("Unknown");
  192. } else {
  193. $percentcompletion = intval($obj->task_duration*100/$obj->planned_workload);
  194. }*/
  195. print '<td><a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$obj->taskid.'&withproject=1">';
  196. //print $percentcompletion.' %';
  197. print convertSecondToTime($obj->timespent, 'all');
  198. print '</a></td>';
  199. print "</tr>\n";
  200. $i++;
  201. }
  202. print "</table>";
  203. }
  204. $db->free($resql);
  205. }
  206. else
  207. {
  208. dol_print_error($db);
  209. }
  210. print '</div>';
  211. llxFooter();
  212. $db->close();