index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.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.'/projet/class/task.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('projects', 'companies'));
  32. $search_project_user = GETPOST('search_project_user','int');
  33. $mine = GETPOST('mode','aZ09')=='mine' ? 1 : 0;
  34. if ($search_project_user == $user->id) $mine = 1;
  35. // Security check
  36. $socid=0;
  37. //if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  38. if (!$user->rights->projet->lire) accessforbidden();
  39. $sortfield = GETPOST("sortfield",'alpha');
  40. $sortorder = GETPOST("sortorder",'alpha');
  41. /*
  42. * View
  43. */
  44. $companystatic=new Societe($db);
  45. $projectstatic=new Project($db);
  46. $userstatic=new User($db);
  47. $form=new Form($db);
  48. $formfile=new FormFile($db);
  49. $projectset = ($mine?$mine:(empty($user->rights->projet->all->lire)?0:2));
  50. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $projetset, 1);
  51. //var_dump($projectsListId);
  52. llxHeader("",$langs->trans("Projects"),"EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos");
  53. $title=$langs->trans("ProjectsArea");
  54. //if ($mine) $title=$langs->trans("MyProjectsArea");
  55. // Title for combo list see all projects
  56. $titleall=$langs->trans("AllAllowedProjects");
  57. if (! empty($user->rights->projet->all->lire) && ! $socid) $titleall=$langs->trans("AllProjects");
  58. else $titleall=$langs->trans("AllAllowedProjects").'<br><br>';
  59. $morehtml='';
  60. $morehtml.='<form name="projectform">';
  61. $morehtml.='<SELECT name="search_project_user">';
  62. $morehtml.='<option name="all" value="0"'.($mine?'':' selected').'>'.$titleall.'</option>';
  63. $morehtml.='<option name="mine" value="'.$user->id.'"'.(($search_project_user == $user->id)?' selected':'').'>'.$langs->trans("ProjectsImContactFor").'</option>';
  64. $morehtml.='</SELECT>';
  65. $morehtml.='<input type="submit" class="button" name="refresh" value="'.$langs->trans("Refresh").'">';
  66. print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, -1, 'title_project.png', 0, $morehtml);
  67. // Show description of content
  68. if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>';
  69. else
  70. {
  71. if (! empty($user->rights->projet->all->lire) && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>';
  72. else print $langs->trans("ProjectsPublicDesc").'<br><br>';
  73. }
  74. // Get list of ponderated percent for each status
  75. $listofoppstatus=array(); $listofopplabel=array(); $listofoppcode=array();
  76. $sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label";
  77. $sql.= " FROM ".MAIN_DB_PREFIX."c_lead_status as cls";
  78. $sql.= " WHERE active=1";
  79. $resql = $db->query($sql);
  80. if ( $resql )
  81. {
  82. $num = $db->num_rows($resql);
  83. $i = 0;
  84. while ($i < $num)
  85. {
  86. $objp = $db->fetch_object($resql);
  87. $listofoppstatus[$objp->rowid]=$objp->percent;
  88. $listofopplabel[$objp->rowid]=$objp->label;
  89. $listofoppcode[$objp->rowid]=$objp->code;
  90. $i++;
  91. }
  92. }
  93. else dol_print_error($db);
  94. print '<div class="fichecenter"><div class="fichethirdleft">';
  95. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  96. {
  97. // Search project
  98. if (! empty($conf->projet->enabled) && $user->rights->projet->lire)
  99. {
  100. $listofsearchfields['search_project']=array('text'=>'Project');
  101. }
  102. if (count($listofsearchfields))
  103. {
  104. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  105. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  106. print '<table class="noborder nohover centpercent">';
  107. $i=0;
  108. foreach($listofsearchfields as $key => $value)
  109. {
  110. if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  111. print '<tr '.$bc[false].'>';
  112. print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
  113. if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
  114. print '</tr>';
  115. $i++;
  116. }
  117. print '</table>';
  118. print '</form>';
  119. print '<br>';
  120. }
  121. }
  122. /*
  123. * Statistics
  124. */
  125. include DOL_DOCUMENT_ROOT.'/projet/graph_opportunities.inc.php';
  126. // List of draft projects
  127. print_projecttasks_array($db, $form, $socid, $projectsListId, 0, 0, $listofoppstatus, array('projectlabel', 'plannedworkload', 'declaredprogress'));
  128. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  129. $max=5;
  130. // Last modified projects
  131. $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.tms as datem,";
  132. $sql.= " s.rowid as socid, s.nom as name, s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.canvas";
  133. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  134. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  135. $sql.= " WHERE p.entity IN (".getEntity('project').")";
  136. if ($mine || empty($user->rights->projet->all->lire)) $sql.= " AND p.rowid IN (".$projectsListId.")"; // If we have this test true, it also means projectset is not 2
  137. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  138. $sql.= " ORDER BY p.tms DESC";
  139. $sql.= $db->plimit($max, 0);
  140. $resql=$db->query($sql);
  141. if ($resql)
  142. {
  143. print '<table class="noborder" width="100%">';
  144. print '<tr class="liste_titre">';
  145. print '<th colspan="4">'.$langs->trans("LatestModifiedProjects",$max).'</th></tr>';
  146. $num = $db->num_rows($resql);
  147. if ($num)
  148. {
  149. $i = 0;
  150. $var = true;
  151. while ($i < $num)
  152. {
  153. $obj = $db->fetch_object($resql);
  154. print '<tr class="oddeven">';
  155. print '<td width="20%" class="nowrap">';
  156. $projectstatic->id=$obj->rowid;
  157. $projectstatic->ref=$obj->ref;
  158. $projectstatic->title=$obj->title;
  159. $projectstatic->dateo=$obj->dateo;
  160. $projectstatic->datep=$obj->datep;
  161. $projectstatic->thirdparty_name=$obj->name;
  162. $companystatic->id=$obj->socid;
  163. $companystatic->name=$obj->name;
  164. $companystatic->email=$obj->email;
  165. $companystatic->client=$obj->client;
  166. $companystatic->fournisseur=$obj->fournisseur;
  167. $companystatic->code_client=$obj->code_client;
  168. $companystatic->code_fournisseur=$obj->code_fournisseur;
  169. $companystatic->canvas=$obj->canvas;
  170. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  171. print '<td width="96" class="nobordernopadding nowrap">';
  172. print $projectstatic->getNomUrl(1);
  173. print '</td>';
  174. print '<td width="16" class="nobordernopadding nowrap">';
  175. print '&nbsp;';
  176. print '</td>';
  177. print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
  178. $filename=dol_sanitizeFileName($obj->ref);
  179. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  180. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  181. print $formfile->getDocumentsLink($projectstatic->element, $filename, $filedir);
  182. print '</td></tr></table>';
  183. print '</td>';
  184. print '<td class="nowrap">';
  185. if ($companystatic->id > 0)
  186. {
  187. print $companystatic->getNomUrl(1,'company',16);
  188. }
  189. print '</td>';
  190. print '<td>'.dol_print_date($db->jdate($obj->datem),'day').'</td>';
  191. print '<td align="right">'.$projectstatic->LibStatut($obj->fk_statut,5).'</td>';
  192. print '</tr>';
  193. $i++;
  194. }
  195. }
  196. print "</table><br>";
  197. }
  198. else dol_print_error($db);
  199. // Open project per thirdparty
  200. print '<div class="div-table-responsive-no-min">';
  201. print '<table class="noborder" width="100%">';
  202. print '<tr class="liste_titre">';
  203. print_liste_field_titre("OpenedProjectsByThirdparties",$_SERVER["PHP_SELF"],"s.nom","","",'',$sortfield,$sortorder);
  204. print_liste_field_titre("NbOfProjects","","","","",'align="right"',$sortfield,$sortorder);
  205. print "</tr>\n";
  206. $sql = "SELECT COUNT(p.rowid) as nb, SUM(p.opp_amount)";
  207. $sql.= ", s.nom as name, s.rowid as socid";
  208. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  209. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  210. $sql.= " WHERE p.entity IN (".getEntity('project', $conf->entity).")";
  211. $sql.= " AND p.fk_statut = 1";
  212. if ($mine || empty($user->rights->projet->all->lire)) $sql.= " AND p.rowid IN (".$projectsListId.")"; // If we have this test true, it also means projectset is not 2
  213. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  214. $sql.= " GROUP BY s.nom, s.rowid";
  215. $sql.= $db->order($sortfield, $sortorder);
  216. $resql = $db->query($sql);
  217. if ( $resql )
  218. {
  219. $num = $db->num_rows($resql);
  220. $i = 0;
  221. while ($i < $num)
  222. {
  223. $obj = $db->fetch_object($resql);
  224. print '<tr class="oddeven">';
  225. print '<td class="nowrap">';
  226. if ($obj->socid)
  227. {
  228. $companystatic->id=$obj->socid;
  229. $companystatic->name=$obj->name;
  230. print $companystatic->getNomUrl(1);
  231. }
  232. else
  233. {
  234. print $langs->trans("OthersNotLinkedToThirdParty");
  235. }
  236. print '</td>';
  237. print '<td align="right">';
  238. if ($obj->socid) print '<a href="'.DOL_URL_ROOT.'/projet/list.php?socid='.$obj->socid.'&search_status=1">'.$obj->nb.'</a>';
  239. else print '<a href="'.DOL_URL_ROOT.'/projet/list.php?search_societe='.urlencode('^$').'&search_status=1">'.$obj->nb.'</a>';
  240. print '</td>';
  241. print "</tr>\n";
  242. $i++;
  243. }
  244. $db->free($resql);
  245. }
  246. else
  247. {
  248. dol_print_error($db);
  249. }
  250. print "</table>";
  251. print '</div>';
  252. if (! empty($conf->global->PROJECT_SHOW_PROJECT_LIST_ON_PROJECT_AREA))
  253. {
  254. // This list can be very long, so we don't show it by default on task area. We prefer to use the list page.
  255. // Add constant PROJECT_SHOW_PROJECT_LIST_ON_PROJECT_AREA to show this list
  256. print '<br>';
  257. print_projecttasks_array($db, $form, $socid, $projectsListId, 0, 1, $listofoppstatus, array());
  258. }
  259. print '</div></div></div>';
  260. // End of page
  261. llxFooter();
  262. $db->close();