dolibarr 23.0.3
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
3 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
4 * Copyright (C) 2021-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
33require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticketstats.class.php';
34
35
44// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
45$hookmanager->initHooks(array('ticketsindex'));
46
47// Load translation files required by the page
48$langs->loadLangs(array('companies', 'other', 'ticket'));
49
52
53// Get parameters
54$id = GETPOSTINT('id');
55$msg_id = GETPOSTINT('msg_id');
56
57$action = GETPOST('action', 'aZ09');
58
59$socid = 0;
60if ($user->socid) {
61 $socid = $user->socid;
62}
63$userid = $user->id;
64
65$nowarray = dol_getdate(dol_now(), true);
66$nowyear = $nowarray['year'];
67$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
68$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
69$endyear = $year;
70
71// Initialize objects
72$object = new Ticket($db);
73
74// Security check
75//restrictedArea($user, 'ticket|knowledgemanagement', 0, '', '', '', '');
76if (!$user->hasRight('ticket', 'read') && !$user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
77 accessforbidden('Not enough permissions');
78}
79
80$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
81
82
83/*
84 * Actions
85 */
86
87// None
88
89
90
91/*
92 * View
93 */
94
95$resultboxes = FormOther::getBoxesArea($user, "11"); // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
96
97$help_url = '';
98llxHeader('', $langs->trans('TicketsIndex'), $help_url, '', 0, 0, '', '', '', 'mod-ticket page-dashboard');
99
100$linkback = '';
101print load_fiche_titre($langs->trans('TicketsIndex'), $resultboxes['selectboxlist'], 'ticket');
102
103
104$dir = '';
105$prefix = '';
106$filenamenb = $dir."/".$prefix."ticketinyear-".$endyear.".png";
107$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticket&amp;file=ticketinyear-'.$endyear.'.png';
108
109$stats = new TicketStats($db, $socid, $userid);
110$param_year = 'DOLUSERCOOKIE_ticket_by_status_year';
111$param_shownb = 'DOLUSERCOOKIE_ticket_by_status_shownb';
112$param_showtot = 'DOLUSERCOOKIE_ticket_by_status_showtot';
113$autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
114$showtot = 0;
115$shownb = 0;
116if (in_array('DOLUSERCOOKIE_ticket_by_status', $autosetarray)) {
117 $endyear = GETPOSTINT($param_year);
118 $shownb = GETPOST($param_shownb, 'alpha');
119 $showtot = GETPOST($param_showtot, 'alpha');
120} elseif (!empty($_COOKIE['DOLUSERCOOKIE_ticket_by_status'])) {
121 $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_ticket_by_status'], true);
122 $endyear = $tmparray['year'];
123 $shownb = empty($tmparray['shownb']) ? 0 : $tmparray['shownb'];
124 $showtot = empty($tmparray['showtot']) ? 0 : $tmparray['showtot'];
125}
126if (empty($shownb) && empty($showtot)) {
127 $showtot = 1;
128 $shownb = 0;
129}
130
131if (empty($endyear)) {
132 $endyear = $nowarray['year'];
133}
134
135$startyear = $endyear - 1;
136
137// Change default WIDTH and HEIGHT (we need a smaller than default for both desktop and smartphone)
138$WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '100%' : '80%';
139if (empty($conf->dol_optimize_smallscreen)) {
140 $HEIGHT = '200';
141} else {
142 $HEIGHT = '160';
143}
144
145print '<div class="clearboth"></div>';
146print '<div class="fichecenter fichecenterbis">';
147
148print '<div class="twocolumns">';
149
150print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
151
152/*
153 * Statistics area
154 */
155$tick = array(
156 'unread' => 0,
157 'read' => 0,
158 'needmoreinfo' => 0,
159 'answered' => 0,
160 'assigned' => 0,
161 'inprogress' => 0,
162 'waiting' => 0,
163 'closed' => 0,
164 'canceled' => 0,
165 'deleted' => 0,
166);
167
168$sql = "SELECT t.fk_statut, COUNT(t.fk_statut) as nb";
169$sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
170if (!$user->hasRight('societe', 'client', 'voir')) {
171 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
172}
173$sql .= ' WHERE t.entity IN ('.getEntity('ticket').')';
174$sql .= dolSqlDateFilter('datec', 0, 0, $endyear);
175
176if (!$user->hasRight('societe', 'client', 'voir')) {
177 $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
178}
179
180// External users restriction
181if ($user->socid > 0) {
182 $sql .= " AND t.fk_soc= ".((int) $user->socid);
183} else {
184 // For internals users,
185 if (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && !$user->hasRight('ticket', 'manage')) {
186 $sql .= " AND t.fk_user_assign = ".((int) $user->id);
187 }
188}
189$sql .= " GROUP BY t.fk_statut";
190
191$dataseries = array();
192$result = $db->query($sql);
193if ($result) {
194 while ($objp = $db->fetch_object($result)) {
195 $found = 0;
196 if ($objp->fk_statut == Ticket::STATUS_NOT_READ) {
197 $tick['unread'] = $objp->nb;
198 }
199 if ($objp->fk_statut == Ticket::STATUS_READ) {
200 $tick['read'] = $objp->nb;
201 }
202 if ($objp->fk_statut == Ticket::STATUS_NEED_MORE_INFO) {
203 $tick['needmoreinfo'] = $objp->nb;
204 }
205 if ($objp->fk_statut == Ticket::STATUS_ASSIGNED) {
206 $tick['assigned'] = $objp->nb;
207 }
208 if ($objp->fk_statut == Ticket::STATUS_IN_PROGRESS) {
209 $tick['inprogress'] = $objp->nb;
210 }
211 if ($objp->fk_statut == Ticket::STATUS_WAITING) {
212 $tick['waiting'] = $objp->nb;
213 }
214 if ($objp->fk_statut == Ticket::STATUS_CLOSED) {
215 $tick['closed'] = $objp->nb;
216 }
217 if ($objp->fk_statut == Ticket::STATUS_CANCELED) {
218 $tick['canceled'] = $objp->nb;
219 }
220 }
221
232 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; // This define $badgeStatusX
233
234 $colorseries = array();
235
236 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_NOT_READ]), 'data' => round($tick['unread']));
237 $colorseries[Ticket::STATUS_NOT_READ] = '-'.$badgeStatus0;
238 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_READ]), 'data' => round($tick['read']));
239 $colorseries[Ticket::STATUS_READ] = $badgeStatus1;
240 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_ASSIGNED]), 'data' => round($tick['assigned']));
241 $colorseries[Ticket::STATUS_ASSIGNED] = $badgeStatus3;
242 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_IN_PROGRESS]), 'data' => round($tick['inprogress']));
243 $colorseries[Ticket::STATUS_IN_PROGRESS] = $badgeStatus4;
244 if (getDolGlobalString('TICKET_INCLUDE_SUSPENDED_STATUS')) {
245 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_WAITING]), 'data' => round($tick['waiting']));
246 $colorseries[Ticket::STATUS_WAITING] = '-'.$badgeStatus4;
247 }
248 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_NEED_MORE_INFO]), 'data' => round($tick['needmoreinfo']));
249 $colorseries[Ticket::STATUS_NEED_MORE_INFO] = '-'.$badgeStatus3;
250 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_CANCELED]), 'data' => round($tick['canceled']));
251 $colorseries[Ticket::STATUS_CANCELED] = $badgeStatus9;
252 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_CLOSED]), 'data' => round($tick['closed']));
253 $colorseries[Ticket::STATUS_CLOSED] = $badgeStatus6;
254} else {
255 dol_print_error($db);
256}
257
258$stringtoshow = '<script type="text/javascript">
259 jQuery(document).ready(function() {
260 jQuery("#idsubimgDOLUSERCOOKIE_ticket_by_status").click(function() {
261 jQuery("#idfilterDOLUSERCOOKIE_ticket_by_status").toggle();
262 });
263 });
264 </script>';
265$stringtoshow .= '<div class="center hideobject" id="idfilterDOLUSERCOOKIE_ticket_by_status">'; // hideobject is to start hidden
266$stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
267$stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
268$stringtoshow .= '<input type="hidden" name="action" value="refresh">';
269$stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_ticket_by_status:year,shownb,showtot">';
270$stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
271$stringtoshow .= '<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', 0, 1).'">';
272$stringtoshow .= '</form>';
273$stringtoshow .= '</div>';
274
275if ($user->hasRight('ticket', 'read')) {
276 print '<div class="div-table-responsive-no-min">';
277 print '<table class="noborder centpercent">';
278 print '<tr class="liste_titre"><th colspan=2>'.$langs->trans("Statistics").' '.$endyear.' '.img_picto('', 'filter.png', 'id="idsubimgDOLUSERCOOKIE_ticket_by_status" class="linkobject"').'</th></tr>';
279
280 print '<tr><td class="center" colspan=2>';
281 print $stringtoshow;
282
283 // don't display graph if no series
284 $totalnb = 0;
285 if (!empty($dataseries) && count($dataseries) > 1) {
286 foreach ($dataseries as $key => $value) {
287 $totalnb += $value['data'];
288 }
289
290 $data = array();
291 foreach ($dataseries as $key => $value) {
292 $data[] = array($value['label'], $value['data']);
293 }
294 $px1 = new DolGraph();
295 $mesg = $px1->isGraphKo();
296 if (!$mesg) {
297 $px1->SetData($data);
298 $px1->SetDataColor(array_values($colorseries));
299
300 unset($data1);
301 $i = $startyear;
302 $legend = array();
303 while ($i <= $endyear) {
304 $legend[] = $i;
305 $i++;
306 }
307 $px1->setShowLegend(2);
308 $px1->SetType(array('pie'));
309 $px1->SetLegend($legend);
310 $px1->SetMaxValue($px1->GetCeilMaxValue());
311 //$px1->SetWidth($WIDTH);
312 $px1->SetHeight($HEIGHT);
313 $px1->SetYLabel($langs->trans("TicketStatByStatus"));
314 $px1->SetShading(3);
315 $px1->SetHorizTickIncrement(1);
316 $px1->SetCssPrefix("cssboxes");
317 $px1->mode = 'depth';
318 //$px1->SetTitle($langs->trans("TicketStatByStatus"));
319
320 $px1->draw($filenamenb, $fileurlnb);
321 print $px1->show($totalnb ? 0 : 1);
322 }
323 }
324 print '</td></tr>';
325 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$totalnb.'</td></tr>';
326 print '</table>';
327 print '</div>';
328}
329
330if ($user->hasRight('ticket', 'read')) {
331 // Build graphic number of object
332 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
333
334 print '<br>'."\n";
335}
336
337print $resultboxes['boxlista'];
338
339print '</div>'."\n";
340
341print '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
342
343if ($user->hasRight('ticket', 'read')) {
344 /*
345 * Latest unread tickets
346 */
347
348 $sql = "SELECT t.rowid, t.ref, t.track_id, t.datec, t.subject, t.type_code, t.category_code, t.severity_code, t.fk_statut as status, t.progress,";
349 $sql .= " type.code as type_code, type.label as type_label,";
350 $sql .= " category.code as category_code, category.label as category_label,";
351 $sql .= " severity.code as severity_code, severity.label as severity_label";
352 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
353 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code = t.type_code AND type.entity = t.entity";
354 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code = t.category_code AND category.entity = t.entity";
355 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code = t.severity_code AND severity.entity = t.entity";
356 if (!$user->hasRight('societe', 'client', 'voir')) {
357 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
358 }
359
360 $sql .= ' WHERE t.entity IN ('.getEntity('ticket').')';
361 $sql .= " AND t.fk_statut = 0";
362 if (!$user->hasRight('societe', 'client', 'voir')) {
363 $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
364 }
365
366 if ($user->socid > 0) {
367 $sql .= " AND t.fk_soc= ".((int) $user->socid);
368 } else {
369 // Restricted to assigned user only
370 if (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && !$user->hasRight('ticket', 'manage')) {
371 $sql .= " AND t.fk_user_assign = ".((int) $user->id);
372 }
373 }
374 $sql .= $db->order("t.datec", "DESC");
375 $sql .= $db->plimit($max, 0);
376
377 //print $sql;
378 $result = $db->query($sql);
379 if ($result) {
380 $num = $db->num_rows($result);
381
382 $i = 0;
383
384 $tmpmax = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT_LAST_MODIFIED_TICKETS', $max);
385 $transRecordedType = $langs->trans("LatestNewTickets", $tmpmax);
386
387 print '<div class="div-table-responsive-no-min">';
388 print '<table class="noborder centpercent">';
389 print '<tr class="liste_titre"><th colspan="5">'.$transRecordedType;
390 print '<a href="'.DOL_URL_ROOT.'/ticket/list.php?search_fk_statut[]='.Ticket::STATUS_NOT_READ.'" title="'.$langs->trans("FullList").'">';
391 print '<span class="badge marginleftonlyshort">...</span>';
392 //print $langs->trans("FullList")
393 print '</a>';
394 print '</th>';
395 print '<th>';
396 print '</th>';
397 print '<th>';
398 print '</th>';
399 print '</tr>';
400 if ($num > 0) {
401 while ($i < $num) {
402 $objp = $db->fetch_object($result);
403
404 $object->id = $objp->rowid;
405 $object->ref = $objp->ref;
406 $object->track_id = $objp->track_id;
407 $object->status = $objp->status;
408 $object->progress = $objp->progress;
409 $object->subject = $objp->subject;
410
411 print '<tr class="oddeven">';
412
413 // Ref
414 print '<td class="nowraponall">';
415 print $object->getNomUrl(1);
416 print "</td>\n";
417
418 // Creation date
419 print '<td class="center nowraponall">';
420 print dol_print_date($db->jdate($objp->datec), 'dayhourreduceformat');
421 print "</td>";
422
423 // Subject
424 print '<td class="nowrap tdoverflowmax150">';
425 print '<a href="card.php?track_id='.$objp->track_id.'" title="'.dolPrintHTMLForAttribute($objp->subject).'">'.dol_trunc($objp->subject, 30).'</a>';
426 print "</td>\n";
427
428 // Type
429 print '<td class="nowrap tdoverflowmax100">';
430 $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$objp->type_code, 'c_ticket_type', 'code', 'label', $objp->type_code);
431 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
432 print '</td>';
433
434 // Category
435 print '<td class="nowrap">';
436 if (!empty($objp->category_code)) {
437 $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$objp->category_code, 'c_ticket_category', 'code', 'label', $objp->category_code);
438 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
439 }
440 //print $objp->category_label;
441 print "</td>";
442
443 // Severity = Priority
444 print '<td class="nowrap" title="'.$langs->trans("Priority").'">';
445 $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$objp->severity_code, 'c_ticket_severity', 'code', 'label', $objp->severity_code);
446 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
447 //print $objp->severity_label;
448 print "</td>";
449
450 print '<td class="nowraponall right">';
451 print $object->getLibStatut(5);
452 print "</td>";
453
454 print "</tr>\n";
455 $i++;
456 }
457
458 $db->free($result);
459 } else {
460 print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans('NoUnreadTicketsFound').'</span></td></tr>';
461 }
462
463 print "</table>";
464 print '</div>';
465
466 print '<br>';
467 } else {
468 dol_print_error($db);
469 }
470}
471
472print $resultboxes['boxlistb'];
473
474print '</div>';
475print '</div>';
476print '</div>';
477
478
479print '<div class="clearboth"></div>';
480
481$parameters = array('user' => $user);
482$reshook = $hookmanager->executeHooks('dashboardTickets', $parameters, $object); // Note that $action and $object may have been modified by hook
483
484
485// End of page
486llxFooter();
487$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
static getBoxesArea($user, $areacode)
Get array with HTML tabs with widgets/boxes of a particular area including personalized choices of us...
const STATUS_NOT_READ
Status.
Class to manage the ticket stats.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition date.lib.php:385
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Class to generate the form for creating a new ticket.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.