dolibarr 25.0.0-alpha
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-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 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
39require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
44
45// Load translation files required by the page
46$langs->loadLangs(array('projects', 'companies'));
47
48// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
49$hookmanager->initHooks(array('projectsindex'));
50
51$action = GETPOST('action', 'aZ09');
52$search_project_user = GETPOST('search_project_user');
53$mine = (GETPOST('mode', 'aZ09') == 'mine' || $search_project_user == $user->id) ? 1 : 0;
54if ($mine == 0 && $search_project_user === '') {
55 $search_project_user = getDolGlobalString('MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX');
56}
57if ($search_project_user == $user->id) {
58 $mine = 1;
59}
60
61$sortfield = GETPOST('sortfield', 'aZ09comma');
62$sortorder = GETPOST('sortorder', 'aZ09comma');
63
64$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
65
66// Security check
67$socid = 0;
68//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 assignment.
69if (!$user->hasRight('projet', 'lire')) {
71}
72
73
74/*
75 * Actions
76 */
77
78$parameters = array();
79$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
80if ($reshook < 0) {
81 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
82}
83if (empty($reshook)) {
84 if ($action == 'refresh_search_project_user' && $user->hasRight('projet', 'lire')) {
85 $search_project_user = GETPOSTINT('search_project_user');
86 $tabparam = array("MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX" => $search_project_user);
87
88 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
89 $result = dol_set_user_param($db, $conf, $user, $tabparam);
90 }
91}
92
93// Add box (when submit is done from a form when ajax disabled)
94include DOL_DOCUMENT_ROOT.'/core/actions_addbox.inc.php';
95
96
97/*
98 * View
99 */
100
101$companystatic = new Societe($db);
102$projectstatic = new Project($db);
103$form = new Form($db);
104$formfile = new FormFile($db);
105
106$projectset = ($mine ? $mine : (!$user->hasRight('projet', 'all', 'lire') ? 0 : 2));
107$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $projectset, 1);
108//var_dump($projectsListId);
109
110
111$title = $langs->trans('ProjectsArea');
112
113$help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
114
115// Load $resultboxes
116$resultboxes = FormOther::getBoxesArea($user, "8");
117
118llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project page-dashboard');
119
120
121//if ($mine) $title=$langs->trans("MyProjectsArea");
122
123
124// Title for combo list see all projects
125$titleall = $langs->trans("AllAllowedProjects");
126if ($user->hasRight('projet', 'all', 'lire') && !$socid) {
127 $titleall = $langs->trans("AllProjects");
128} else {
129 $titleall = $langs->trans("AllAllowedProjects").'<br><br>';
130}
131
132$morehtml = '<form name="projectform" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
133$morehtml .= '<input type="hidden" name="token" value="'.newToken().'">';
134$morehtml .= '<input type="hidden" name="action" value="refresh_search_project_user">';
135
136$morehtml .= '<select name="search_project_user" id="search_project_user">';
137$morehtml .= '<option name="all" value="0"'.($mine ? '' : ' selected').'>'.$titleall.'</option>';
138$morehtml .= '<option name="mine" value="'.$user->id.'"'.(($search_project_user == $user->id) ? ' selected' : '').'>'.$langs->trans("ProjectsImContactFor").'</option>';
139$morehtml .= '</select>';
140$morehtml .= ajax_combobox("search_project_user", array(), 0, 0, 'resolve', '-1', 'small');
141$morehtml .= '<input type="submit" class="button smallpaddingimp" name="refresh" value="'.$langs->trans("Refresh").'">';
142$morehtml .= '</form>';
143
144$morehtml .= $resultboxes['selectboxlist'];
145
146if ($mine) {
147 $htmltooltip = $langs->trans("MyProjectsDesc");
148} else {
149 if ($user->hasRight('projet', 'all', 'lire') && !$socid) {
150 $htmltooltip = $langs->trans("ProjectsDesc");
151 } else {
152 $htmltooltip = $langs->trans("ProjectsPublicDesc");
153 }
154}
155
156print_barre_liste($form->textwithpicto($title, $htmltooltip), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, -1, 'project', 0, $morehtml);
157
158
159// Get list of ponderated percent and colors for each status
160$theme_vars_file = dol_getThemeFilePath('theme_vars.inc.php');
161if ($theme_vars_file) {
162 include $theme_vars_file;
163}
172// Available from theme_vars:
173'
174@phan-var-force string $badgeStatus0
175@phan-var-force string $badgeStatus1
176@phan-var-force string $badgeStatus2
177@phan-var-force string $badgeStatus3
178@phan-var-force string $badgeStatus4
179@phan-var-force string $badgeStatus5
180@phan-var-force string $badgeStatus6
181@phan-var-force string $badgeStatus7
182@phan-var-force string $badgeStatus8
183@phan-var-force string $badgeStatus9
184';
185$listofoppstatus = array();
186$listofopplabel = array();
187$listofoppcode = array();
188$colorseries = array();
189$sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label";
190$sql .= " FROM ".MAIN_DB_PREFIX."c_lead_status as cls";
191$sql .= " WHERE active=1";
192$resql = $db->query($sql);
193if ($resql) {
194 $num = $db->num_rows($resql);
195 $i = 0;
196
197 while ($i < $num) {
198 $objp = $db->fetch_object($resql);
199 $listofoppstatus[$objp->rowid] = $objp->percent;
200 $listofopplabel[$objp->rowid] = $objp->label; // default label if translation from "OppStatus".code not found.
201 $listofoppcode[$objp->rowid] = $objp->code;
202 switch ($objp->code) {
203 case 'PROSP':
204 $colorseries[$objp->rowid] = "-".$badgeStatus0;
205 break;
206 case 'QUAL':
207 $colorseries[$objp->rowid] = "-".$badgeStatus1;
208 break;
209 case 'PROPO':
210 $colorseries[$objp->rowid] = $badgeStatus1;
211 break;
212 case 'NEGO':
213 $colorseries[$objp->rowid] = $badgeStatus4;
214 break;
215 case 'LOST':
216 $colorseries[$objp->rowid] = $badgeStatus9;
217 break;
218 case 'WON':
219 $colorseries[$objp->rowid] = $badgeStatus6;
220 break;
221 default:
222 $colorseries[$objp->rowid] = $badgeStatus2;
223 break;
224 }
225 $i++;
226 }
227} else {
228 dol_print_error($db);
229}
230
231
232print '<div class="fichecenter">';
233
234print '<div class="twocolumns">';
235
236print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
237
238
239// Statistics
240include DOL_DOCUMENT_ROOT.'/projet/graph_opportunities.inc.php';
241
242// List of draft projects
243print_projecttasks_array($db, $form, $socid, $projectsListId, 0, 0, $listofoppstatus, array('projectlabel', 'plannedworkload', 'declaredprogress', 'prospectionstatus', 'projectstatus'), $max);
244
245
246print $resultboxes['boxlista'];
247
248print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
249
250
251// Latest modified projects
252$sql = "SELECT p.rowid, p.ref, p.title, p.dateo as date_start, p.datee as date_end, p.fk_statut as status, p.tms as datem";
253$sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
254$sql .= ", s.code_client, s.code_compta, s.client";
255$sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
256$sql .= ", s.logo, s.email, s.entity";
257$sql .= ", s.canvas, s.status as thirdpartystatus";
258$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
259$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
260$sql .= " WHERE p.entity IN (".getEntity('project').")";
261if ($mine || !$user->hasRight('projet', 'all', 'lire')) {
262 $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")"; // If we have this test true, it also means projectset is not 2
263}
264if ($socid) {
265 $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
266}
267$sql .= " ORDER BY p.tms DESC";
268$sql .= $db->plimit($max, 0);
269
270$resql = $db->query($sql);
271if ($resql) {
272 startSimpleTable($langs->trans("LatestModifiedProjects", $max), "projet/list.php", "sortfield=p.tms&sortorder=DESC", 3, -1, 'project');
273
274 $num = $db->num_rows($resql);
275
276 if ($num) {
277 $i = 0;
278 while ($i < $num) {
279 $obj = $db->fetch_object($resql);
280
281 print '<tr class="oddeven">';
282 print '<td class="nowrap">';
283
284 $projectstatic->id = $obj->rowid;
285 $projectstatic->ref = $obj->ref;
286 $projectstatic->title = $obj->title;
287 $projectstatic->thirdparty_name = $obj->name;
288 $projectstatic->status = $obj->status;
289 $projectstatic->date_start = $db->jdate($obj->date_start);
290 $projectstatic->date_end = $db->jdate($obj->date_end);
291
292 $companystatic->id = $obj->socid;
293 $companystatic->name = $obj->name;
294 $companystatic->name_alias = $obj->name_alias;
295 $companystatic->client = $obj->client;
296 $companystatic->fournisseur = $obj->fournisseur;
297
298 //$companystatic->code_client = $obj->code_client;
299 $companystatic->code_compta = $obj->code_compta;
300 $companystatic->code_compta_client = $obj->code_compta;
301 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
302
303 $companystatic->logo = $obj->logo;
304 $companystatic->email = $obj->email;
305 $companystatic->entity = $obj->entity;
306 $companystatic->canvas = $obj->canvas;
307 $companystatic->status = $obj->thirdpartystatus;
308
309 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
310 print '<td width="96" class="nobordernopadding nowraponall">';
311 print $projectstatic->getNomUrl(1);
312 print '</td>';
313
314 print '<td width="16" class="nobordernopadding nowrap">';
315 print '&nbsp;';
316 print '</td>';
317
318 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
319 $filename = dol_sanitizeFileName($obj->ref);
320 $filedir = $conf->project->dir_output.'/'.dol_sanitizeFileName($obj->ref);
321 print $formfile->getDocumentsLink($projectstatic->element, $filename, $filedir);
322 print '</td></tr></table>';
323
324 print '</td>';
325
326 // Label
327 print '<td class="" title="'.dolPrintHTMLForAttribute($obj->title).'">';
328 print '<div class="twolinesmax-normallineheight minwidth100onall">';
329 print dolPrintHTML($projectstatic->title);
330 print '</div>';
331 print '</td>';
332
333 // Thirdparty
334 print '<td class="tdoverflowmax125" title="'.dolPrintHTMLForAttribute($companystatic->name).'">';
335 if ($companystatic->id > 0) {
336 print $companystatic->getNomUrl(1, 'company', 16);
337 }
338 print '</td>';
339
340 // Date
341 $datem = $db->jdate($obj->datem);
342 print '<td class="center" title="'.dolPrintHTMLForAttribute($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
343 print dol_print_date($datem, 'day', 'tzuserrel');
344 print '</td>';
345
346 // Status
347 print '<td class="right">'.$projectstatic->LibStatut($obj->status, 3).'</td>';
348 print '</tr>';
349 $i++;
350 }
351 } else {
352 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
353 }
354
355 finishSimpleTable(true);
356} else {
357 dol_print_error($db);
358}
359
360
361$companystatic = new Societe($db); // We need a clean new object for next loop because current one has some properties set.
362
363if (empty($sortfield)) {
364 $sortfield = 'nb';
365 $sortorder = 'desc';
366}
367
368// List of open projects per thirdparty
369$sql = "SELECT COUNT(p.rowid) as nb, SUM(p.opp_amount)";
370$sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
371$sql .= ", s.code_client, s.code_compta, s.client";
372$sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
373$sql .= ", s.logo, s.email, s.entity";
374$sql .= ", s.canvas, s.status";
375$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
376$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
377$sql .= " WHERE p.entity IN (".getEntity('project').")";
378$sql .= " AND p.fk_statut = 1";
379if ($mine || !$user->hasRight('projet', 'all', 'lire')) {
380 $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")"; // If we have this test true, it also means projectset is not 2
381}
382if ($socid > 0) {
383 $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
384}
385$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";
386$sql .= $db->order($sortfield, $sortorder);
387//$sql .= $db->plimit($max + 1, 0);
388
389$resql = $db->query($sql);
390if ($resql) {
391 $num = $db->num_rows($resql);
392 $i = 0;
393 $othernb = 0;
394
395 if ($num) {
396 // Open project per thirdparty
397 print '<div class="div-table-responsive-no-min">';
398 print '<table class="noborder centpercent">';
399 print '<tr class="liste_titre">';
400 print_liste_field_titre("OpenedProjectsByThirdparties", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder);
401 print_liste_field_titre("Number", $_SERVER["PHP_SELF"], "nb", "", "", '', $sortfield, $sortorder, 'right ');
402 print "</tr>\n";
403 }
404
405 while ($i < $num) {
406 $obj = $db->fetch_object($resql);
407
408 if ($i >= $max) {
409 $othernb += $obj->nb;
410 $i++;
411 continue;
412 }
413
414 print '<tr class="oddeven">';
415 print '<td class="nowraponall tdoverflowmax100">';
416 if ($obj->socid > 0) {
417 $companystatic->id = $obj->socid;
418 $companystatic->name = $obj->name;
419 $companystatic->name_alias = $obj->name_alias;
420 $companystatic->code_client = $obj->code_client;
421 $companystatic->code_compta = $obj->code_compta;
422 $companystatic->code_compta_client = $obj->code_compta;
423 $companystatic->client = $obj->client;
424 $companystatic->code_fournisseur = $obj->code_fournisseur;
425 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
426 $companystatic->fournisseur = $obj->fournisseur;
427 $companystatic->logo = $obj->logo;
428 $companystatic->email = $obj->email;
429 $companystatic->entity = $obj->entity;
430 $companystatic->canvas = $obj->canvas;
431 $companystatic->status = $obj->status;
432
433 print $companystatic->getNomUrl(1);
434 } else {
435 print $langs->trans("OthersNotLinkedToThirdParty");
436 }
437 print '</td>';
438 print '<td class="right">';
439 if ($obj->socid) {
440 print '<a href="'.DOL_URL_ROOT.'/projet/list.php?socid='.$obj->socid.'&search_status=1">'.$obj->nb.'</a>';
441 } else {
442 print '<a href="'.DOL_URL_ROOT.'/projet/list.php?search_societe='.urlencode('^$').'&search_status=1">'.$obj->nb.'</a>';
443 }
444 print '</td>';
445 print "</tr>\n";
446
447 $i++;
448 }
449 if ($othernb) {
450 print '<tr class="oddeven">';
451 print '<td class="nowrap">';
452 print '<span class="opacitymedium">'.$langs->trans("More").'...</span>';
453 print '</td>';
454 print '<td class="nowrap right">';
455 print $othernb;
456 print '</td>';
457 print "</tr>\n";
458 }
459
460 if ($num) {
461 print "</table>";
462 print '</div>';
463 }
464
465 $db->free($resql);
466} else {
467 dol_print_error($db);
468}
469
470if ((!getDolGlobalInt('PROJECT_USE_OPPORTUNITIES') || getDolGlobalInt('PROJECT_SHOW_OPEN_PROJECTS_LIST_ON_PROJECT_AREA')) && !getDolGlobalInt('PROJECT_HIDE_OPEN_PROJECTS_LIST_ON_PROJECT_AREA')) {
471 // 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
472 // we really want it and to allow interface backward compatibility.
473 print '<br>';
474
475 print_projecttasks_array($db, $form, $socid, $projectsListId, 0, 1, $listofoppstatus, array());
476}
477
478print $resultboxes['boxlistb'];
479
480print '</div></div></div>';
481
482$parameters = array('user' => $user);
483$reshook = $hookmanager->executeHooks('dashboardProjects', $parameters, $projectstatic); // Note that $action and $object may have been modified by hook
484
485// End of page
486llxFooter();
487$db->close();
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:477
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static getBoxesArea($user, $areacode)
Get array with HTML tabs with widgets/boxes of a particular area including personalized choices of us...
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_set_user_param($db, $conf, &$user, $tab, $entity=-1)
Save personal parameter.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_getThemeFilePath($file, $theme='')
Return the full filesystem path of a file located in the currently selected theme directory.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
startSimpleTable($header, $link="", $arguments="", $emptyColumns=0, $number=-1, $pictofulllist='')
Start a table with headers and a optional clickable number (don't forget to use "finishSimpleTable()"...
print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks=0, $status=-1, $listofoppstatus=array(), $hiddenfields=array(), $max=0)
Return HTML table with list of projects and number of opened tasks.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.