dolibarr 22.0.5
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-2024 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//$result = 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;
115if (in_array('DOLUSERCOOKIE_ticket_by_status', $autosetarray)) {
116 $endyear = GETPOSTINT($param_year);
117 $shownb = GETPOST($param_shownb, 'alpha');
118 $showtot = GETPOST($param_showtot, 'alpha');
119} elseif (!empty($_COOKIE['DOLUSERCOOKIE_ticket_by_status'])) {
120 $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_ticket_by_status'], true);
121 $endyear = $tmparray['year'];
122 $shownb = empty($tmparray['shownb']) ? 0 : $tmparray['shownb'];
123 $showtot = empty($tmparray['showtot']) ? 0 : $tmparray['showtot'];
124}
125if (empty($shownb) && empty($showtot)) {
126 $showtot = 1;
127 $shownb = 0;
128}
129
130if (empty($endyear)) {
131 $endyear = $nowarray['year'];
132}
133
134$startyear = $endyear - 1;
135
136// Change default WIDTH and HEIGHT (we need a smaller than default for both desktop and smartphone)
137$WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '100%' : '80%';
138if (empty($conf->dol_optimize_smallscreen)) {
139 $HEIGHT = '200';
140} else {
141 $HEIGHT = '160';
142}
143
144print '<div class="clearboth"></div>';
145print '<div class="fichecenter fichecenterbis">';
146
147print '<div class="twocolumns">';
148
149print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
150
151/*
152 * Statistics area
153 */
154$tick = array(
155 'unread' => 0,
156 'read' => 0,
157 'needmoreinfo' => 0,
158 'answered' => 0,
159 'assigned' => 0,
160 'inprogress' => 0,
161 'waiting' => 0,
162 'closed' => 0,
163 'canceled' => 0,
164 'deleted' => 0,
165);
166
167$sql = "SELECT t.fk_statut, COUNT(t.fk_statut) as nb";
168$sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
169if (!$user->hasRight('societe', 'client', 'voir')) {
170 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
171}
172$sql .= ' WHERE t.entity IN ('.getEntity('ticket').')';
173$sql .= dolSqlDateFilter('datec', 0, 0, $endyear);
174
175if (!$user->hasRight('societe', 'client', 'voir')) {
176 $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
177}
178
179// External users restriction
180if ($user->socid > 0) {
181 $sql .= " AND t.fk_soc= ".((int) $user->socid);
182} else {
183 // For internals users,
184 if (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && !$user->hasRight('ticket', 'manage')) {
185 $sql .= " AND t.fk_user_assign = ".((int) $user->id);
186 }
187}
188$sql .= " GROUP BY t.fk_statut";
189
190$dataseries = array();
191$result = $db->query($sql);
192if ($result) {
193 while ($objp = $db->fetch_object($result)) {
194 $found = 0;
195 if ($objp->fk_statut == Ticket::STATUS_NOT_READ) {
196 $tick['unread'] = $objp->nb;
197 }
198 if ($objp->fk_statut == Ticket::STATUS_READ) {
199 $tick['read'] = $objp->nb;
200 }
201 if ($objp->fk_statut == Ticket::STATUS_NEED_MORE_INFO) {
202 $tick['needmoreinfo'] = $objp->nb;
203 }
204 if ($objp->fk_statut == Ticket::STATUS_ASSIGNED) {
205 $tick['assigned'] = $objp->nb;
206 }
207 if ($objp->fk_statut == Ticket::STATUS_IN_PROGRESS) {
208 $tick['inprogress'] = $objp->nb;
209 }
210 if ($objp->fk_statut == Ticket::STATUS_WAITING) {
211 $tick['waiting'] = $objp->nb;
212 }
213 if ($objp->fk_statut == Ticket::STATUS_CLOSED) {
214 $tick['closed'] = $objp->nb;
215 }
216 if ($objp->fk_statut == Ticket::STATUS_CANCELED) {
217 $tick['canceled'] = $objp->nb;
218 }
219 }
220
221 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; // This define $badgeStatusX
222
223 $colorseries = array();
224
225 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_NOT_READ]), 'data' => round($tick['unread']));
226 $colorseries[Ticket::STATUS_NOT_READ] = '-'.$badgeStatus0;
227 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_READ]), 'data' => round($tick['read']));
228 $colorseries[Ticket::STATUS_READ] = $badgeStatus1;
229 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_ASSIGNED]), 'data' => round($tick['assigned']));
230 $colorseries[Ticket::STATUS_ASSIGNED] = $badgeStatus3;
231 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_IN_PROGRESS]), 'data' => round($tick['inprogress']));
232 $colorseries[Ticket::STATUS_IN_PROGRESS] = $badgeStatus4;
233 if (getDolGlobalString('TICKET_INCLUDE_SUSPENDED_STATUS')) {
234 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_WAITING]), 'data' => round($tick['waiting']));
235 $colorseries[Ticket::STATUS_WAITING] = '-'.$badgeStatus4;
236 }
237 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_NEED_MORE_INFO]), 'data' => round($tick['needmoreinfo']));
238 $colorseries[Ticket::STATUS_NEED_MORE_INFO] = '-'.$badgeStatus3;
239 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_CANCELED]), 'data' => round($tick['canceled']));
240 $colorseries[Ticket::STATUS_CANCELED] = $badgeStatus9;
241 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_CLOSED]), 'data' => round($tick['closed']));
242 $colorseries[Ticket::STATUS_CLOSED] = $badgeStatus6;
243} else {
244 dol_print_error($db);
245}
246
247$stringtoshow = '<script type="text/javascript">
248 jQuery(document).ready(function() {
249 jQuery("#idsubimgDOLUSERCOOKIE_ticket_by_status").click(function() {
250 jQuery("#idfilterDOLUSERCOOKIE_ticket_by_status").toggle();
251 });
252 });
253 </script>';
254$stringtoshow .= '<div class="center hideobject" id="idfilterDOLUSERCOOKIE_ticket_by_status">'; // hideobject is to start hidden
255$stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
256$stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
257$stringtoshow .= '<input type="hidden" name="action" value="refresh">';
258$stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_ticket_by_status:year,shownb,showtot">';
259$stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
260$stringtoshow .= '<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', 0, 1).'">';
261$stringtoshow .= '</form>';
262$stringtoshow .= '</div>';
263
264if ($user->hasRight('ticket', 'read')) {
265 print '<div class="div-table-responsive-no-min">';
266 print '<table class="noborder centpercent">';
267 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>';
268
269 print '<tr><td class="center" colspan=2>';
270 print $stringtoshow;
271
272 // don't display graph if no series
273 $totalnb = 0;
274 if (!empty($dataseries) && count($dataseries) > 1) {
275 foreach ($dataseries as $key => $value) {
276 $totalnb += $value['data'];
277 }
278
279 $data = array();
280 foreach ($dataseries as $key => $value) {
281 $data[] = array($value['label'], $value['data']);
282 }
283 $px1 = new DolGraph();
284 $mesg = $px1->isGraphKo();
285 if (!$mesg) {
286 $px1->SetData($data);
287 $px1->SetDataColor(array_values($colorseries));
288
289 unset($data1);
290 $i = $startyear;
291 $legend = array();
292 while ($i <= $endyear) {
293 $legend[] = $i;
294 $i++;
295 }
296 $px1->setShowLegend(2);
297 $px1->SetType(array('pie'));
298 $px1->SetLegend($legend);
299 $px1->SetMaxValue($px1->GetCeilMaxValue());
300 //$px1->SetWidth($WIDTH);
301 $px1->SetHeight($HEIGHT);
302 $px1->SetYLabel($langs->trans("TicketStatByStatus"));
303 $px1->SetShading(3);
304 $px1->SetHorizTickIncrement(1);
305 $px1->SetCssPrefix("cssboxes");
306 $px1->mode = 'depth';
307 //$px1->SetTitle($langs->trans("TicketStatByStatus"));
308
309 $px1->draw($filenamenb, $fileurlnb);
310 print $px1->show($totalnb ? 0 : 1);
311 }
312 }
313 print '</td></tr>';
314 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$totalnb.'</td></tr>';
315 print '</table>';
316 print '</div>';
317}
318
319if ($user->hasRight('ticket', 'read')) {
320 // Build graphic number of object
321 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
322
323 print '<br>'."\n";
324}
325
326print $resultboxes['boxlista'];
327
328print '</div>'."\n";
329
330print '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
331
332if ($user->hasRight('ticket', 'read')) {
333 /*
334 * Latest unread tickets
335 */
336
337 $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,";
338 $sql .= " type.code as type_code, type.label as type_label,";
339 $sql .= " category.code as category_code, category.label as category_label,";
340 $sql .= " severity.code as severity_code, severity.label as severity_label";
341 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
342 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code = t.type_code AND type.entity = t.entity";
343 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code = t.category_code AND category.entity = t.entity";
344 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code = t.severity_code AND severity.entity = t.entity";
345 if (!$user->hasRight('societe', 'client', 'voir')) {
346 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
347 }
348
349 $sql .= ' WHERE t.entity IN ('.getEntity('ticket').')';
350 $sql .= " AND t.fk_statut = 0";
351 if (!$user->hasRight('societe', 'client', 'voir')) {
352 $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
353 }
354
355 if ($user->socid > 0) {
356 $sql .= " AND t.fk_soc= ".((int) $user->socid);
357 } else {
358 // Restricted to assigned user only
359 if (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && !$user->hasRight('ticket', 'manage')) {
360 $sql .= " AND t.fk_user_assign = ".((int) $user->id);
361 }
362 }
363 $sql .= $db->order("t.datec", "DESC");
364 $sql .= $db->plimit($max, 0);
365
366 //print $sql;
367 $result = $db->query($sql);
368 if ($result) {
369 $num = $db->num_rows($result);
370
371 $i = 0;
372
373 $tmpmax = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT_LAST_MODIFIED_TICKETS', $max);
374 $transRecordedType = $langs->trans("LatestNewTickets", $tmpmax);
375
376 print '<div class="div-table-responsive-no-min">';
377 print '<table class="noborder centpercent">';
378 print '<tr class="liste_titre"><th colspan="5">'.$transRecordedType;
379 print '<a href="'.DOL_URL_ROOT.'/ticket/list.php?search_fk_statut[]='.Ticket::STATUS_NOT_READ.'" title="'.$langs->trans("FullList").'">';
380 print '<span class="badge marginleftonlyshort">...</span>';
381 //print $langs->trans("FullList")
382 print '</a>';
383 print '</th>';
384 print '<th>';
385 print '</th>';
386 print '<th>';
387 print '</th>';
388 print '</tr>';
389 if ($num > 0) {
390 while ($i < $num) {
391 $objp = $db->fetch_object($result);
392
393 $object->id = $objp->rowid;
394 $object->ref = $objp->ref;
395 $object->track_id = $objp->track_id;
396 $object->status = $objp->status;
397 $object->progress = $objp->progress;
398 $object->subject = $objp->subject;
399
400 print '<tr class="oddeven">';
401
402 // Ref
403 print '<td class="nowraponall">';
404 print $object->getNomUrl(1);
405 print "</td>\n";
406
407 // Creation date
408 print '<td class="center nowraponall">';
409 print dol_print_date($db->jdate($objp->datec), 'dayhourreduceformat');
410 print "</td>";
411
412 // Subject
413 print '<td class="nowrap tdoverflowmax150">';
414 print '<a href="card.php?track_id='.$objp->track_id.'" title="'.dolPrintHTMLForAttribute($objp->subject).'">'.dol_trunc($objp->subject, 30).'</a>';
415 print "</td>\n";
416
417 // Type
418 print '<td class="nowrap tdoverflowmax100">';
419 $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$objp->type_code, 'c_ticket_type', 'code', 'label', $objp->type_code);
420 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
421 print '</td>';
422
423 // Category
424 print '<td class="nowrap">';
425 if (!empty($objp->category_code)) {
426 $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$objp->category_code, 'c_ticket_category', 'code', 'label', $objp->category_code);
427 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
428 }
429 //print $objp->category_label;
430 print "</td>";
431
432 // Severity = Priority
433 print '<td class="nowrap" title="'.$langs->trans("Priority").'">';
434 $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$objp->severity_code, 'c_ticket_severity', 'code', 'label', $objp->severity_code);
435 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
436 //print $objp->severity_label;
437 print "</td>";
438
439 print '<td class="nowraponall right">';
440 print $object->getLibStatut(5);
441 print "</td>";
442
443 print "</tr>\n";
444 $i++;
445 }
446
447 $db->free($result);
448 } else {
449 print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans('NoUnreadTicketsFound').'</span></td></tr>';
450 }
451
452 print "</table>";
453 print '</div>';
454
455 print '<br>';
456 } else {
457 dol_print_error($db);
458 }
459}
460
461print $resultboxes['boxlistb'];
462
463print '</div>';
464print '</div>';
465print '</div>';
466
467
468print '<div class="clearboth"></div>';
469
470$parameters = array('user' => $user);
471$reshook = $hookmanager->executeHooks('dashboardTickets', $parameters, $object); // Note that $action and $object may have been modified by hook
472
473
474// End of page
475llxFooter();
476$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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:382
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.