index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/projet/index.php
  22. * \ingroup projet
  23. * \brief Main project home page
  24. */
  25. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. $hookmanager = new HookManager($db);
  33. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  34. $hookmanager->initHooks(array('projectsindex'));
  35. // Load translation files required by the page
  36. $langs->loadLangs(array('projects', 'companies'));
  37. $action = GETPOST('action', 'aZ09');
  38. $search_project_user = GETPOST('search_project_user', 'int');
  39. $mine = GETPOST('mode', 'aZ09') == 'mine' ? 1 : 0;
  40. if ($mine == 0 && $search_project_user === '') {
  41. $search_project_user = (empty($user->conf->MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX) ? '' : $user->conf->MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX);
  42. }
  43. if ($search_project_user == $user->id) {
  44. $mine = 1;
  45. }
  46. // Security check
  47. $socid = 0;
  48. //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  49. if (!$user->hasRight('projet', 'lire')) {
  50. accessforbidden();
  51. }
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  55. /*
  56. * Actions
  57. */
  58. $parameters = array();
  59. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  60. if ($reshook < 0) {
  61. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  62. }
  63. if (empty($reshook)) {
  64. if ($action == 'refresh_search_project_user') {
  65. $search_project_user = GETPOST('search_project_user', 'int');
  66. $tabparam = array("MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX" => $search_project_user);
  67. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  68. $result = dol_set_user_param($db, $conf, $user, $tabparam);
  69. }
  70. }
  71. /*
  72. * View
  73. */
  74. $companystatic = new Societe($db);
  75. $projectstatic = new Project($db);
  76. $form = new Form($db);
  77. $formfile = new FormFile($db);
  78. $projectset = ($mine ? $mine : (empty($user->rights->projet->all->lire) ? 0 : 2));
  79. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $projectset, 1);
  80. //var_dump($projectsListId);
  81. $title = $langs->trans('ProjectsArea');
  82. $help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
  83. llxHeader('', $title, $help_url);
  84. //if ($mine) $title=$langs->trans("MyProjectsArea");
  85. // Title for combo list see all projects
  86. $titleall = $langs->trans("AllAllowedProjects");
  87. if ($user->hasRight('projet', 'all', 'lire') && !$socid) {
  88. $titleall = $langs->trans("AllProjects");
  89. } else {
  90. $titleall = $langs->trans("AllAllowedProjects").'<br><br>';
  91. }
  92. $morehtml = '';
  93. $morehtml .= '<form name="projectform" method="POST">';
  94. $morehtml .= '<input type="hidden" name="token" value="'.newToken().'">';
  95. $morehtml .= '<input type="hidden" name="action" value="refresh_search_project_user">';
  96. $morehtml .= '<SELECT name="search_project_user" id="search_project_user">';
  97. $morehtml .= '<option name="all" value="0"'.($mine ? '' : ' selected').'>'.$titleall.'</option>';
  98. $morehtml .= '<option name="mine" value="'.$user->id.'"'.(($search_project_user == $user->id) ? ' selected' : '').'>'.$langs->trans("ProjectsImContactFor").'</option>';
  99. $morehtml .= '</SELECT>';
  100. $morehtml .= ajax_combobox("search_project_user", array(), 0, 0, 'resolve', '-1', 'small');
  101. $morehtml .= '<input type="submit" class="button smallpaddingimp" name="refresh" value="'.$langs->trans("Refresh").'">';
  102. $morehtml .= '</form>';
  103. if ($mine) {
  104. $tooltiphelp = $langs->trans("MyProjectsDesc");
  105. } else {
  106. if ($user->hasRight('projet', 'all', 'lire') && !$socid) {
  107. $tooltiphelp = $langs->trans("ProjectsDesc");
  108. } else {
  109. $tooltiphelp = $langs->trans("ProjectsPublicDesc");
  110. }
  111. }
  112. print_barre_liste($form->textwithpicto($title, $tooltiphelp), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, -1, 'project', 0, $morehtml);
  113. // Get list of ponderated percent and colors for each status
  114. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  115. $listofoppstatus = array(); $listofopplabel = array(); $listofoppcode = array(); $colorseries = array();
  116. $sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label";
  117. $sql .= " FROM ".MAIN_DB_PREFIX."c_lead_status as cls";
  118. $sql .= " WHERE active=1";
  119. $resql = $db->query($sql);
  120. if ($resql) {
  121. $num = $db->num_rows($resql);
  122. $i = 0;
  123. while ($i < $num) {
  124. $objp = $db->fetch_object($resql);
  125. $listofoppstatus[$objp->rowid] = $objp->percent;
  126. $listofopplabel[$objp->rowid] = $objp->label; // default label if translation from "OppStatus".code not found.
  127. $listofoppcode[$objp->rowid] = $objp->code;
  128. switch ($objp->code) {
  129. case 'PROSP':
  130. $colorseries[$objp->rowid] = "-".$badgeStatus0;
  131. break;
  132. case 'QUAL':
  133. $colorseries[$objp->rowid] = "-".$badgeStatus1;
  134. break;
  135. case 'PROPO':
  136. $colorseries[$objp->rowid] = $badgeStatus1;
  137. break;
  138. case 'NEGO':
  139. $colorseries[$objp->rowid] = $badgeStatus4;
  140. break;
  141. case 'LOST':
  142. $colorseries[$objp->rowid] = $badgeStatus9;
  143. break;
  144. case 'WON':
  145. $colorseries[$objp->rowid] = $badgeStatus6;
  146. break;
  147. default:
  148. $colorseries[$objp->rowid] = $badgeStatus2;
  149. break;
  150. }
  151. $i++;
  152. }
  153. } else {
  154. dol_print_error($db);
  155. }
  156. //var_dump($listofoppcode);
  157. print '<div class="fichecenter"><div class="fichethirdleft">';
  158. // Statistics
  159. include DOL_DOCUMENT_ROOT.'/projet/graph_opportunities.inc.php';
  160. // List of draft projects
  161. print_projecttasks_array($db, $form, $socid, $projectsListId, 0, 0, $listofoppstatus, array('projectlabel', 'plannedworkload', 'declaredprogress', 'prospectionstatus', 'projectstatus'), $max);
  162. print '</div><div class="fichetwothirdright">';
  163. // Latest modified projects
  164. $sql = "SELECT p.rowid, p.ref, p.title, p.dateo, p.datee, p.fk_statut as status, p.tms as datem";
  165. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  166. $sql .= ", s.code_client, s.code_compta, s.client";
  167. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  168. $sql .= ", s.logo, s.email, s.entity";
  169. $sql .= ", s.canvas, s.status as thirdpartystatus";
  170. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
  171. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  172. $sql .= " WHERE p.entity IN (".getEntity('project').")";
  173. if ($mine || !$user->hasRight('projet', 'all', 'lire')) {
  174. $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")"; // If we have this test true, it also means projectset is not 2
  175. }
  176. if ($socid) {
  177. $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
  178. }
  179. $sql .= " ORDER BY p.tms DESC";
  180. $sql .= $db->plimit($max, 0);
  181. $resql = $db->query($sql);
  182. if ($resql) {
  183. print '<div class="div-table-responsive-no-min">';
  184. print '<table class="noborder centpercent">';
  185. print '<tr class="liste_titre">';
  186. print '<th colspan="5">'.$langs->trans("LatestModifiedProjects", $max).'</th>';
  187. print '</tr>';
  188. $num = $db->num_rows($resql);
  189. if ($num) {
  190. $i = 0;
  191. while ($i < $num) {
  192. $obj = $db->fetch_object($resql);
  193. print '<tr class="oddeven">';
  194. print '<td class="nowrap">';
  195. $projectstatic->id = $obj->rowid;
  196. $projectstatic->ref = $obj->ref;
  197. $projectstatic->title = $obj->title;
  198. $projectstatic->thirdparty_name = $obj->name;
  199. $projectstatic->status = $obj->status;
  200. $companystatic->id = $obj->socid;
  201. $companystatic->name = $obj->name;
  202. //$companystatic->name_alias = $obj->name_alias;
  203. //$companystatic->code_client = $obj->code_client;
  204. $companystatic->code_compta = $obj->code_compta;
  205. $companystatic->client = $obj->client;
  206. //$companystatic->code_fournisseur = $obj->code_fournisseur;
  207. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  208. $companystatic->fournisseur = $obj->fournisseur;
  209. $companystatic->logo = $obj->logo;
  210. $companystatic->email = $obj->email;
  211. $companystatic->entity = $obj->entity;
  212. $companystatic->canvas = $obj->canvas;
  213. $companystatic->status = $obj->thirdpartystatus;
  214. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  215. print '<td width="96" class="nobordernopadding nowraponall">';
  216. print $projectstatic->getNomUrl(1);
  217. print '</td>';
  218. print '<td width="16" class="nobordernopadding nowrap">';
  219. print '&nbsp;';
  220. print '</td>';
  221. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  222. $filename = dol_sanitizeFileName($obj->ref);
  223. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  224. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  225. print $formfile->getDocumentsLink($projectstatic->element, $filename, $filedir);
  226. print '</td></tr></table>';
  227. print '</td>';
  228. // Label
  229. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->title).'">';
  230. print $projectstatic->title;
  231. print '</td>';
  232. // Thirdparty
  233. print '<td class="nowrap">';
  234. if ($companystatic->id > 0) {
  235. print $companystatic->getNomUrl(1, 'company', 16);
  236. }
  237. print '</td>';
  238. // Date
  239. $datem = $db->jdate($obj->datem);
  240. print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
  241. print dol_print_date($datem, 'day', 'tzuserrel');
  242. print '</td>';
  243. // Status
  244. print '<td class="right">'.$projectstatic->LibStatut($obj->status, 3).'</td>';
  245. print '</tr>';
  246. $i++;
  247. }
  248. } else {
  249. print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  250. }
  251. print "</table></div>";
  252. } else {
  253. dol_print_error($db);
  254. }
  255. $companystatic = new Societe($db); // We need a clean new object for next loop because current one has some properties set.
  256. // List of open projects per thirdparty
  257. $sql = "SELECT COUNT(p.rowid) as nb, SUM(p.opp_amount)";
  258. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  259. $sql .= ", s.code_client, s.code_compta, s.client";
  260. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  261. $sql .= ", s.logo, s.email, s.entity";
  262. $sql .= ", s.canvas, s.status";
  263. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
  264. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  265. $sql .= " WHERE p.entity IN (".getEntity('project').")";
  266. $sql .= " AND p.fk_statut = 1";
  267. if ($mine || !$user->hasRight('projet', 'all', 'lire')) {
  268. $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")"; // If we have this test true, it also means projectset is not 2
  269. }
  270. if ($socid > 0) {
  271. $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
  272. }
  273. $sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.code_compta, s.client, s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur, s.logo, s.email, s.entity, s.canvas, s.status";
  274. $sql .= $db->order($sortfield, $sortorder);
  275. //$sql .= $db->plimit($max + 1, 0);
  276. $resql = $db->query($sql);
  277. if ($resql) {
  278. $num = $db->num_rows($resql);
  279. $i = 0;
  280. $othernb = 0;
  281. if ($num) {
  282. print '<br>';
  283. // Open project per thirdparty
  284. print '<div class="div-table-responsive-no-min">';
  285. print '<table class="noborder centpercent">';
  286. print '<tr class="liste_titre">';
  287. print_liste_field_titre("OpenedProjectsByThirdparties", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder);
  288. print_liste_field_titre("NbOfProjects", $_SERVER["PHP_SELF"], "nb", "", "", '', $sortfield, $sortorder, 'right ');
  289. print "</tr>\n";
  290. }
  291. while ($i < $num) {
  292. $obj = $db->fetch_object($resql);
  293. if ($i >= $max) {
  294. $othernb += $obj->nb;
  295. $i++;
  296. continue;
  297. }
  298. print '<tr class="oddeven">';
  299. print '<td class="nowraponall tdoverflowmax100">';
  300. if ($obj->socid > 0) {
  301. $companystatic->id = $obj->socid;
  302. $companystatic->name = $obj->name;
  303. $companystatic->name_alias = $obj->name_alias;
  304. $companystatic->code_client = $obj->code_client;
  305. $companystatic->code_compta = $obj->code_compta;
  306. $companystatic->client = $obj->client;
  307. $companystatic->code_fournisseur = $obj->code_fournisseur;
  308. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  309. $companystatic->fournisseur = $obj->fournisseur;
  310. $companystatic->logo = $obj->logo;
  311. $companystatic->email = $obj->email;
  312. $companystatic->entity = $obj->entity;
  313. $companystatic->canvas = $obj->canvas;
  314. $companystatic->status = $obj->status;
  315. print $companystatic->getNomUrl(1);
  316. } else {
  317. print $langs->trans("OthersNotLinkedToThirdParty");
  318. }
  319. print '</td>';
  320. print '<td class="right">';
  321. if ($obj->socid) {
  322. print '<a href="'.DOL_URL_ROOT.'/projet/list.php?socid='.$obj->socid.'&search_status=1">'.$obj->nb.'</a>';
  323. } else {
  324. print '<a href="'.DOL_URL_ROOT.'/projet/list.php?search_societe='.urlencode('^$').'&search_status=1">'.$obj->nb.'</a>';
  325. }
  326. print '</td>';
  327. print "</tr>\n";
  328. $i++;
  329. }
  330. if ($othernb) {
  331. print '<tr class="oddeven">';
  332. print '<td class="nowrap">';
  333. print '<span class="opacitymedium">'.$langs->trans("More").'...</span>';
  334. print '</td>';
  335. print '<td class="nowrap right">';
  336. print $othernb;
  337. print '</td>';
  338. print "</tr>\n";
  339. }
  340. if ($num) {
  341. print "</table>";
  342. print '</div>';
  343. }
  344. $db->free($resql);
  345. } else {
  346. dol_print_error($db);
  347. }
  348. if (!getDolGlobalInt('PROJECT_USE_OPPORTUNITIES') || getDolGlobalInt('PROJECT_SHOW_OPEN_PROJECTS_LIST_ON_PROJECT_AREA')) {
  349. // This list is surely very long and useless when we are using opportunities, so we hide it for this use case, but we allow to show it if
  350. // we really want it and to allow interface backward compatibility.
  351. print '<br>';
  352. print_projecttasks_array($db, $form, $socid, $projectsListId, 0, 1, $listofoppstatus, array());
  353. }
  354. print '</div></div>';
  355. $parameters = array('user' => $user);
  356. $reshook = $hookmanager->executeHooks('dashboardProjects', $parameters, $projectstatic); // Note that $action and $object may have been modified by hook
  357. // End of page
  358. llxFooter();
  359. $db->close();