dolibarr  13.0.2
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2020 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 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33 
34 $hookmanager = new HookManager($db);
35 
36 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
37 $hookmanager->initHooks(array('projectsindex'));
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('projects', 'companies'));
41 
42 $action = GETPOST('action', 'aZ09');
43 $search_project_user = GETPOST('search_project_user', 'int');
44 $mine = GETPOST('mode', 'aZ09') == 'mine' ? 1 : 0;
45 if ($mine == 0 && $search_project_user === '') $search_project_user = $user->conf->MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX;
46 if ($search_project_user == $user->id) $mine = 1;
47 
48 // Security check
49 $socid = 0;
50 //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.
51 if (!$user->rights->projet->lire) accessforbidden();
52 
53 $sortfield = GETPOST("sortfield", 'alpha');
54 $sortorder = GETPOST("sortorder", 'alpha');
55 
56 $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
57 
58 
59 /*
60  * Actions
61  */
62 
63 $parameters = array();
64 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
65 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
66 if (empty($reshook)) {
67  if ($action == 'refresh_search_project_user') {
68  $search_project_user = GETPOST('search_project_user', 'int');
69  $tabparam = array("MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX" => $search_project_user);
70 
71  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
72  $result = dol_set_user_param($db, $conf, $user, $tabparam);
73  }
74 }
75 
76 
77 /*
78  * View
79  */
80 
81 $companystatic = new Societe($db);
82 $projectstatic = new Project($db);
83 $form = new Form($db);
84 $formfile = new FormFile($db);
85 
86 $projectset = ($mine ? $mine : (empty($user->rights->projet->all->lire) ? 0 : 2));
87 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $projectset, 1);
88 //var_dump($projectsListId);
89 
90 llxHeader("", $langs->trans("Projects"), "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos");
91 
92 $title = $langs->trans("ProjectsArea");
93 //if ($mine) $title=$langs->trans("MyProjectsArea");
94 
95 
96 // Title for combo list see all projects
97 $titleall = $langs->trans("AllAllowedProjects");
98 if (!empty($user->rights->projet->all->lire) && !$socid) $titleall = $langs->trans("AllProjects");
99 else $titleall = $langs->trans("AllAllowedProjects").'<br><br>';
100 
101 $morehtml = '';
102 $morehtml .= '<form name="projectform" method="POST">';
103 $morehtml .= '<input type="hidden" name="token" value="'.newToken().'">';
104 $morehtml .= '<input type="hidden" name="action" value="refresh_search_project_user">';
105 $morehtml .= '<SELECT name="search_project_user">';
106 $morehtml .= '<option name="all" value="0"'.($mine ? '' : ' selected').'>'.$titleall.'</option>';
107 $morehtml .= '<option name="mine" value="'.$user->id.'"'.(($search_project_user == $user->id) ? ' selected' : '').'>'.$langs->trans("ProjectsImContactFor").'</option>';
108 $morehtml .= '</SELECT>';
109 $morehtml .= '<input type="submit" class="button smallpaddingimp" name="refresh" value="'.$langs->trans("Refresh").'">';
110 $morehtml .= '</form>';
111 
112 if ($mine) $tooltiphelp = $langs->trans("MyProjectsDesc");
113 else {
114  if (!empty($user->rights->projet->all->lire) && !$socid) $tooltiphelp = $langs->trans("ProjectsDesc");
115  else $tooltiphelp = $langs->trans("ProjectsPublicDesc");
116 }
117 
118 print_barre_liste($form->textwithpicto($title, $tooltiphelp), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, -1, 'project', 0, $morehtml);
119 
120 
121 // Get list of ponderated percent and colors for each status
122 include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
123 $listofoppstatus = array(); $listofopplabel = array(); $listofoppcode = array(); $colorseries = array();
124 $sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label";
125 $sql .= " FROM ".MAIN_DB_PREFIX."c_lead_status as cls";
126 $sql .= " WHERE active=1";
127 $resql = $db->query($sql);
128 if ($resql)
129 {
130  $num = $db->num_rows($resql);
131  $i = 0;
132 
133  while ($i < $num)
134  {
135  $objp = $db->fetch_object($resql);
136  $listofoppstatus[$objp->rowid] = $objp->percent;
137  $listofopplabel[$objp->rowid] = $objp->label;
138  $listofoppcode[$objp->rowid] = $objp->code;
139  switch ($objp->code) {
140  case 'PROSP':
141  $colorseries[$objp->rowid] = "-".$badgeStatus0;
142  break;
143  case 'QUAL':
144  $colorseries[$objp->rowid] = "-".$badgeStatus1;
145  break;
146  case 'PROPO':
147  $colorseries[$objp->rowid] = $badgeStatus1;
148  break;
149  case 'NEGO':
150  $colorseries[$objp->rowid] = $badgeStatus4;
151  break;
152  case 'LOST':
153  $colorseries[$objp->rowid] = $badgeStatus9;
154  break;
155  case 'WON':
156  $colorseries[$objp->rowid] = $badgeStatus6;
157  break;
158  default:
159  $colorseries[$objp->rowid] = $badgeStatus2;
160  break;
161  }
162  $i++;
163  }
164 } else dol_print_error($db);
165 //var_dump($listofoppcode);
166 
167 
168 print '<div class="fichecenter"><div class="fichethirdleft">';
169 
170 
171 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
172 {
173  // Search project
174  if (!empty($conf->projet->enabled) && $user->rights->projet->lire)
175  {
176  $listofsearchfields['search_project'] = array('text'=>'Project');
177  }
178 
179  if (count($listofsearchfields))
180  {
181  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
182  print '<input type="hidden" name="token" value="'.newToken().'">';
183  print '<div class="div-table-responsive-no-min">';
184  print '<table class="noborder nohover centpercent">';
185  $i = 0;
186  foreach ($listofsearchfields as $key => $value)
187  {
188  if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
189  print '<tr>';
190  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>';
191  if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
192  print '</tr>';
193  $i++;
194  }
195  print '</table>';
196  print '</div>';
197  print '</form>';
198  print '<br>';
199  }
200 }
201 
202 
203 /*
204  * Statistics
205  */
206 include DOL_DOCUMENT_ROOT.'/projet/graph_opportunities.inc.php';
207 
208 
209 // List of draft projects
210 print_projecttasks_array($db, $form, $socid, $projectsListId, 0, 0, $listofoppstatus, array('projectlabel', 'plannedworkload', 'declaredprogress', 'prospectionstatus', 'projectstatus'));
211 
212 
213 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
214 
215 // Latest modified projects
216 $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut as status, p.tms as datem";
217 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
218 $sql .= ", s.code_client, s.code_compta, s.client";
219 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
220 $sql .= ", s.logo, s.email, s.entity";
221 $sql .= ", s.canvas, s.status as thirdpartystatus";
222 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
223 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
224 $sql .= " WHERE p.entity IN (".getEntity('project').")";
225 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
226 if ($socid) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
227 $sql .= " ORDER BY p.tms DESC";
228 $sql .= $db->plimit($max, 0);
229 
230 $resql = $db->query($sql);
231 if ($resql)
232 {
233  print '<div class="div-table-responsive-no-min">';
234  print '<table class="noborder centpercent">';
235  print '<tr class="liste_titre">';
236  print '<th colspan="4">'.$langs->trans("LatestModifiedProjects", $max).'</th>';
237  print '</tr>';
238 
239  $num = $db->num_rows($resql);
240 
241  if ($num)
242  {
243  $i = 0;
244  while ($i < $num)
245  {
246  $obj = $db->fetch_object($resql);
247 
248  print '<tr class="oddeven">';
249  print '<td class="nowrap">';
250 
251  $projectstatic->id = $obj->rowid;
252  $projectstatic->ref = $obj->ref;
253  $projectstatic->title = $obj->title;
254  $projectstatic->dateo = $obj->dateo;
255  $projectstatic->datep = $obj->datep;
256  $projectstatic->thirdparty_name = $obj->name;
257  $projectstatic->status = $obj->status;
258 
259  $companystatic->id = $obj->socid;
260  $companystatic->name = $obj->name;
261  //$companystatic->name_alias = $obj->name_alias;
262  //$companystatic->code_client = $obj->code_client;
263  $companystatic->code_compta = $obj->code_compta;
264  $companystatic->client = $obj->client;
265  //$companystatic->code_fournisseur = $obj->code_fournisseur;
266  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
267  $companystatic->fournisseur = $obj->fournisseur;
268  $companystatic->logo = $obj->logo;
269  $companystatic->email = $obj->email;
270  $companystatic->entity = $obj->entity;
271  $companystatic->canvas = $obj->canvas;
272  $companystatic->status = $obj->thirdpartystatus;
273 
274  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
275  print '<td width="96" class="nobordernopadding nowrap">';
276  print $projectstatic->getNomUrl(1);
277  print '</td>';
278 
279  print '<td width="16" class="nobordernopadding nowrap">';
280  print '&nbsp;';
281  print '</td>';
282 
283  print '<td width="16" class="right nobordernopadding hideonsmartphone">';
284  $filename = dol_sanitizeFileName($obj->ref);
285  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
286  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
287  print $formfile->getDocumentsLink($projectstatic->element, $filename, $filedir);
288  print '</td></tr></table>';
289 
290  print '</td>';
291 
292  print '<td class="nowrap">';
293  if ($companystatic->id > 0)
294  {
295  print $companystatic->getNomUrl(1, 'company', 16);
296  }
297  print '</td>';
298  print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
299  print '<td class="right">'.$projectstatic->LibStatut($obj->status, 3).'</td>';
300  print '</tr>';
301  $i++;
302  }
303  } else {
304  print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
305  }
306  print "</table></div>";
307 } else dol_print_error($db);
308 
309 
310 $companystatic = new Societe($db); // We need a clean new object for next loop because current one has some properties set.
311 
312 
313 $sql = "SELECT COUNT(p.rowid) as nb, SUM(p.opp_amount)";
314 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
315 $sql .= ", s.code_client, s.code_compta, s.client";
316 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
317 $sql .= ", s.logo, s.email, s.entity";
318 $sql .= ", s.canvas, s.status";
319 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
320 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
321 $sql .= " WHERE p.entity IN (".getEntity('project').")";
322 $sql .= " AND p.fk_statut = 1";
323 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
324 if ($socid) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
325 $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";
326 $sql .= $db->order($sortfield, $sortorder);
327 //$sql .= $db->plimit($max + 1, 0);
328 
329 $resql = $db->query($sql);
330 if ($resql)
331 {
332  $num = $db->num_rows($resql);
333  $i = 0;
334  $othernb = 0;
335 
336  if ($num) {
337  print '<br>';
338 
339  // Open project per thirdparty
340  print '<div class="div-table-responsive-no-min">';
341  print '<table class="noborder centpercent">';
342  print '<tr class="liste_titre">';
343  print_liste_field_titre("OpenedProjectsByThirdparties", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder);
344  print_liste_field_titre("NbOfProjects", $_SERVER["PHP_SELF"], "nb", "", "", '', $sortfield, $sortorder, 'right ');
345  print "</tr>\n";
346  }
347 
348  while ($i < $num)
349  {
350  $obj = $db->fetch_object($resql);
351 
352  if ($i >= $max) {
353  $othernb += $obj->nb;
354  $i++;
355  continue;
356  }
357 
358  print '<tr class="oddeven">';
359  print '<td class="nowraponall tdoverflowmax100">';
360  if ($obj->socid > 0)
361  {
362  $companystatic->id = $obj->socid;
363  $companystatic->name = $obj->name;
364  $companystatic->name_alias = $obj->name_alias;
365  $companystatic->code_client = $obj->code_client;
366  $companystatic->code_compta = $obj->code_compta;
367  $companystatic->client = $obj->client;
368  $companystatic->code_fournisseur = $obj->code_fournisseur;
369  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
370  $companystatic->fournisseur = $obj->fournisseur;
371  $companystatic->logo = $obj->logo;
372  $companystatic->email = $obj->email;
373  $companystatic->entity = $obj->entity;
374  $companystatic->canvas = $obj->canvas;
375  $companystatic->status = $obj->status;
376 
377  print $companystatic->getNomUrl(1);
378  } else {
379  print $langs->trans("OthersNotLinkedToThirdParty");
380  }
381  print '</td>';
382  print '<td class="right">';
383  if ($obj->socid) print '<a href="'.DOL_URL_ROOT.'/projet/list.php?socid='.$obj->socid.'&search_status=1">'.$obj->nb.'</a>';
384  else print '<a href="'.DOL_URL_ROOT.'/projet/list.php?search_societe='.urlencode('^$').'&search_status=1">'.$obj->nb.'</a>';
385  print '</td>';
386  print "</tr>\n";
387 
388  $i++;
389  }
390  if ($othernb) {
391  print '<tr class="oddeven">';
392  print '<td class="nowrap">';
393  print '<span class="opacitymedium">...</span>';
394  print '</td>';
395  print '<td class="nowrap right">';
396  print $othernb;
397  print '</td>';
398  print "</tr>\n";
399  }
400 
401  if ($num) {
402  print "</table>";
403  print '</div>';
404  }
405 
406  $db->free($resql);
407 } else {
408  dol_print_error($db);
409 }
410 
411 if (empty($conf->global->PROJECT_HIDE_PROJECT_LIST_ON_PROJECT_AREA))
412 {
413  // This list can be very long, so we allow to hide it to prefer to use the list page.
414  // Add constant PROJECT_HIDE_PROJECT_LIST_ON_PROJECT_AREA to hide this list
415 
416  print '<br>';
417 
418  print_projecttasks_array($db, $form, $socid, $projectsListId, 0, 1, $listofoppstatus, array());
419 }
420 
421 print '</div></div></div>';
422 
423 $parameters = array('user' => $user);
424 $reshook = $hookmanager->executeHooks('dashboardProjects', $parameters, $projectstatic); // Note that $action and $object may have been modified by hook
425 
426 // End of page
427 llxFooter();
428 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks=0, $status=-1, $listofoppstatus=array(), $hiddenfields=array())
Return HTML table with list of projects and number of opened tasks.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage projects.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
dol_set_user_param($db, $conf, &$user, $tab)
Save personnal parameter.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59