dolibarr 21.0.0-beta
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 MDW <mdeweerd@users.noreply.github.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
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
32require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticketstats.class.php';
33
34
43// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
44$hookmanager->initHooks(array('ticketsindex'));
45
46// Load translation files required by the page
47$langs->loadLangs(array('companies', 'other', 'ticket'));
48
51
52// Get parameters
53$id = GETPOSTINT('id');
54$msg_id = GETPOSTINT('msg_id');
55
56$action = GETPOST('action', 'aZ09');
57
58$socid = 0;
59if ($user->socid) {
60 $socid = $user->socid;
61}
62$userid = $user->id;
63
64$nowarray = dol_getdate(dol_now(), true);
65$nowyear = $nowarray['year'];
66$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
67$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
68$endyear = $year;
69
70// Initialize objects
71$object = new Ticket($db);
72
73// Security check
74//$result = restrictedArea($user, 'ticket|knowledgemanagement', 0, '', '', '', '');
75if (!$user->hasRight('ticket', 'read') && !$user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
76 accessforbidden('Not enough permissions');
77}
78
79$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
80
81
82/*
83 * Actions
84 */
85
86// None
87
88
89
90/*
91 * View
92 */
93
94$resultboxes = FormOther::getBoxesArea($user, "11"); // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
95
96$help_url = '';
97llxHeader('', $langs->trans('TicketsIndex'), $help_url, '', 0, 0, '', '', '', 'mod-ticket page-dashboard');
98
99$linkback = '';
100print load_fiche_titre($langs->trans('TicketsIndex'), $resultboxes['selectboxlist'], 'ticket');
101
102
103$dir = '';
104$prefix = '';
105$filenamenb = $dir."/".$prefix."ticketinyear-".$endyear.".png";
106$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticket&amp;file=ticketinyear-'.$endyear.'.png';
107
108$stats = new TicketStats($db, $socid, $userid);
109$param_year = 'DOLUSERCOOKIE_ticket_by_status_year';
110$param_shownb = 'DOLUSERCOOKIE_ticket_by_status_shownb';
111$param_showtot = 'DOLUSERCOOKIE_ticket_by_status_showtot';
112$autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
113if (in_array('DOLUSERCOOKIE_ticket_by_status', $autosetarray)) {
114 $endyear = GETPOSTINT($param_year);
115 $shownb = GETPOST($param_shownb, 'alpha');
116 $showtot = GETPOST($param_showtot, 'alpha');
117} elseif (!empty($_COOKIE['DOLUSERCOOKIE_ticket_by_status'])) {
118 $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_ticket_by_status'], true);
119 $endyear = $tmparray['year'];
120 $shownb = empty($tmparray['shownb']) ? 0 : $tmparray['shownb'];
121 $showtot = empty($tmparray['showtot']) ? 0 : $tmparray['showtot'];
122}
123if (empty($shownb) && empty($showtot)) {
124 $showtot = 1;
125 $shownb = 0;
126}
127
128if (empty($endyear)) {
129 $endyear = $nowarray['year'];
130}
131
132$startyear = $endyear - 1;
133
134// Change default WIDTH and HEIGHT (we need a smaller than default for both desktop and smartphone)
135$WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '100%' : '80%';
136if (empty($conf->dol_optimize_smallscreen)) {
137 $HEIGHT = '200';
138} else {
139 $HEIGHT = '160';
140}
141
142print '<div class="clearboth"></div>';
143print '<div class="fichecenter fichecenterbis">';
144
145print '<div class="twocolumns">';
146
147print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
148
149/*
150 * Statistics area
151 */
152$tick = array(
153 'unread' => 0,
154 'read' => 0,
155 'needmoreinfo' => 0,
156 'answered' => 0,
157 'assigned' => 0,
158 'inprogress' => 0,
159 'waiting' => 0,
160 'closed' => 0,
161 'canceled' => 0,
162 'deleted' => 0,
163);
164
165$sql = "SELECT t.fk_statut, COUNT(t.fk_statut) as nb";
166$sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
167if (!$user->hasRight('societe', 'client', 'voir')) {
168 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
169}
170$sql .= ' WHERE t.entity IN ('.getEntity('ticket').')';
171$sql .= dolSqlDateFilter('datec', 0, 0, $endyear);
172
173if (!$user->hasRight('societe', 'client', 'voir')) {
174 $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
175}
176
177// External users restriction
178if ($user->socid > 0) {
179 $sql .= " AND t.fk_soc= ".((int) $user->socid);
180} else {
181 // For internals users,
182 if (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && !$user->hasRight('ticket', 'manage')) {
183 $sql .= " AND t.fk_user_assign = ".((int) $user->id);
184 }
185}
186$sql .= " GROUP BY t.fk_statut";
187
188$result = $db->query($sql);
189if ($result) {
190 while ($objp = $db->fetch_object($result)) {
191 $found = 0;
192 if ($objp->fk_statut == Ticket::STATUS_NOT_READ) {
193 $tick['unread'] = $objp->nb;
194 }
195 if ($objp->fk_statut == Ticket::STATUS_READ) {
196 $tick['read'] = $objp->nb;
197 }
198 if ($objp->fk_statut == Ticket::STATUS_NEED_MORE_INFO) {
199 $tick['needmoreinfo'] = $objp->nb;
200 }
201 if ($objp->fk_statut == Ticket::STATUS_ASSIGNED) {
202 $tick['assigned'] = $objp->nb;
203 }
204 if ($objp->fk_statut == Ticket::STATUS_IN_PROGRESS) {
205 $tick['inprogress'] = $objp->nb;
206 }
207 if ($objp->fk_statut == Ticket::STATUS_WAITING) {
208 $tick['waiting'] = $objp->nb;
209 }
210 if ($objp->fk_statut == Ticket::STATUS_CLOSED) {
211 $tick['closed'] = $objp->nb;
212 }
213 if ($objp->fk_statut == Ticket::STATUS_CANCELED) {
214 $tick['canceled'] = $objp->nb;
215 }
216 }
217
218 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; // This define $badgeStatusX
219
220 $dataseries = array();
221 $colorseries = array();
222
223 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_NOT_READ]), 'data' => round($tick['unread']));
224 $colorseries[Ticket::STATUS_NOT_READ] = '-'.$badgeStatus0;
225 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_READ]), 'data' => round($tick['read']));
226 $colorseries[Ticket::STATUS_READ] = $badgeStatus1;
227 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_ASSIGNED]), 'data' => round($tick['assigned']));
228 $colorseries[Ticket::STATUS_ASSIGNED] = $badgeStatus3;
229 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_IN_PROGRESS]), 'data' => round($tick['inprogress']));
230 $colorseries[Ticket::STATUS_IN_PROGRESS] = $badgeStatus4;
231 if (getDolGlobalString('TICKET_INCLUDE_SUSPENDED_STATUS')) {
232 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_WAITING]), 'data' => round($tick['waiting']));
233 $colorseries[Ticket::STATUS_WAITING] = '-'.$badgeStatus4;
234 }
235 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_NEED_MORE_INFO]), 'data' => round($tick['needmoreinfo']));
236 $colorseries[Ticket::STATUS_NEED_MORE_INFO] = '-'.$badgeStatus3;
237 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_CANCELED]), 'data' => round($tick['canceled']));
238 $colorseries[Ticket::STATUS_CANCELED] = $badgeStatus9;
239 $dataseries[] = array('label' => $langs->transnoentitiesnoconv($object->labelStatusShort[Ticket::STATUS_CLOSED]), 'data' => round($tick['closed']));
240 $colorseries[Ticket::STATUS_CLOSED] = $badgeStatus6;
241} else {
242 dol_print_error($db);
243}
244
245$stringtoshow = '<script type="text/javascript">
246 jQuery(document).ready(function() {
247 jQuery("#idsubimgDOLUSERCOOKIE_ticket_by_status").click(function() {
248 jQuery("#idfilterDOLUSERCOOKIE_ticket_by_status").toggle();
249 });
250 });
251 </script>';
252$stringtoshow .= '<div class="center hideobject" id="idfilterDOLUSERCOOKIE_ticket_by_status">'; // hideobject is to start hidden
253$stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
254$stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
255$stringtoshow .= '<input type="hidden" name="action" value="refresh">';
256$stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_ticket_by_status:year,shownb,showtot">';
257$stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
258$stringtoshow .= '<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', 0, 1).'">';
259$stringtoshow .= '</form>';
260$stringtoshow .= '</div>';
261
262if ($user->hasRight('ticket', 'read')) {
263 print '<div class="div-table-responsive-no-min">';
264 print '<table class="noborder centpercent">';
265 print '<tr class="liste_titre"><th >'.$langs->trans("Statistics").' '.$endyear.' '.img_picto('', 'filter.png', 'id="idsubimgDOLUSERCOOKIE_ticket_by_status" class="linkobject"').'</th></tr>';
266
267 print '<tr><td class="center">';
268 print $stringtoshow;
269
270 // don't display graph if no series
271 if (!empty($dataseries) && count($dataseries) > 1) {
272 $totalnb = 0;
273 foreach ($dataseries as $key => $value) {
274 $totalnb += $value['data'];
275 }
276
277 $data = array();
278 foreach ($dataseries as $key => $value) {
279 $data[] = array($value['label'], $value['data']);
280 }
281 $px1 = new DolGraph();
282 $mesg = $px1->isGraphKo();
283 if (!$mesg) {
284 $px1->SetData($data);
285 $px1->SetDataColor(array_values($colorseries));
286
287 unset($data1);
288 $i = $startyear;
289 $legend = array();
290 while ($i <= $endyear) {
291 $legend[] = $i;
292 $i++;
293 }
294 $px1->setShowLegend(2);
295 $px1->SetType(array('pie'));
296 $px1->SetLegend($legend);
297 $px1->SetMaxValue($px1->GetCeilMaxValue());
298 //$px1->SetWidth($WIDTH);
299 $px1->SetHeight($HEIGHT);
300 $px1->SetYLabel($langs->trans("TicketStatByStatus"));
301 $px1->SetShading(3);
302 $px1->SetHorizTickIncrement(1);
303 $px1->SetCssPrefix("cssboxes");
304 $px1->mode = 'depth';
305 //$px1->SetTitle($langs->trans("TicketStatByStatus"));
306
307 $px1->draw($filenamenb, $fileurlnb);
308 print $px1->show($totalnb ? 0 : 1);
309 }
310 }
311 print '</td></tr>';
312
313 print '</table>';
314 print '</div>';
315}
316
317if ($user->hasRight('ticket', 'read')) {
318 // Build graphic number of object
319 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
320
321 print '<br>'."\n";
322}
323
324print $resultboxes['boxlista'];
325
326print '</div>'."\n";
327
328print '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
329
330if ($user->hasRight('ticket', 'read')) {
331 /*
332 * Latest unread tickets
333 */
334
335 $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,";
336 $sql .= " type.code as type_code, type.label as type_label,";
337 $sql .= " category.code as category_code, category.label as category_label,";
338 $sql .= " severity.code as severity_code, severity.label as severity_label";
339 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
340 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
341 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
342 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
343 if (!$user->hasRight('societe', 'client', 'voir')) {
344 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
345 }
346
347 $sql .= ' WHERE t.entity IN ('.getEntity('ticket').')';
348 $sql .= " AND t.fk_statut = 0";
349 if (!$user->hasRight('societe', 'client', 'voir')) {
350 $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
351 }
352
353 if ($user->socid > 0) {
354 $sql .= " AND t.fk_soc= ".((int) $user->socid);
355 } else {
356 // Restricted to assigned user only
357 if (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && !$user->hasRight('ticket', 'manage')) {
358 $sql .= " AND t.fk_user_assign = ".((int) $user->id);
359 }
360 }
361 $sql .= $db->order("t.datec", "DESC");
362 $sql .= $db->plimit($max, 0);
363
364 //print $sql;
365 $result = $db->query($sql);
366 if ($result) {
367 $num = $db->num_rows($result);
368
369 $i = 0;
370
371 $tmpmax = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT_LAST_MODIFIED_TICKETS', $max);
372 $transRecordedType = $langs->trans("LatestNewTickets", $tmpmax);
373
374 print '<div class="div-table-responsive-no-min">';
375 print '<table class="noborder centpercent">';
376 print '<tr class="liste_titre"><th colspan="5">'.$transRecordedType;
377 print '<a href="'.DOL_URL_ROOT.'/ticket/list.php?search_fk_statut[]='.Ticket::STATUS_NOT_READ.'" title="'.$langs->trans("FullList").'">';
378 print '<span class="badge marginleftonlyshort">...</span>';
379 //print $langs->trans("FullList")
380 print '</a>';
381 print '</th>';
382 print '<th>';
383 print '</th>';
384 print '<th>';
385 print '</th>';
386 print '</tr>';
387 if ($num > 0) {
388 while ($i < $num) {
389 $objp = $db->fetch_object($result);
390
391 $object->id = $objp->rowid;
392 $object->ref = $objp->ref;
393 $object->track_id = $objp->track_id;
394 $object->status = $objp->status;
395 $object->progress = $objp->progress;
396 $object->subject = $objp->subject;
397
398 print '<tr class="oddeven">';
399
400 // Ref
401 print '<td class="nowraponall">';
402 print $object->getNomUrl(1);
403 print "</td>\n";
404
405 // Creation date
406 print '<td class="center nowraponall">';
407 print dol_print_date($db->jdate($objp->datec), 'dayhourreduceformat');
408 print "</td>";
409
410 // Subject
411 print '<td class="nowrap tdoverflowmax150">';
412 print '<a href="card.php?track_id='.$objp->track_id.'" title="'.dolPrintHTMLForAttribute($objp->subject).'">'.dol_trunc($objp->subject, 30).'</a>';
413 print "</td>\n";
414
415 // Type
416 print '<td class="nowrap tdoverflowmax100">';
417 $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$objp->type_code, 'c_ticket_type', 'code', 'label', $objp->type_code);
418 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
419 print '</td>';
420
421 // Category
422 print '<td class="nowrap">';
423 if (!empty($objp->category_code)) {
424 $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$objp->category_code, 'c_ticket_category', 'code', 'label', $objp->category_code);
425 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
426 }
427 //print $objp->category_label;
428 print "</td>";
429
430 // Severity = Priority
431 print '<td class="nowrap" title="'.$langs->trans("Priority").'">';
432 $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$objp->severity_code, 'c_ticket_severity', 'code', 'label', $objp->severity_code);
433 print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
434 //print $objp->severity_label;
435 print "</td>";
436
437 print '<td class="nowraponall right">';
438 print $object->getLibStatut(5);
439 print "</td>";
440
441 print "</tr>\n";
442 $i++;
443 }
444
445 $db->free($result);
446 } else {
447 print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans('NoUnreadTicketsFound').'</span></td></tr>';
448 }
449
450 print "</table>";
451 print '</div>';
452
453 print '<br>';
454 } else {
455 dol_print_error($db);
456 }
457}
458
459print $resultboxes['boxlistb'];
460
461print '</div>';
462print '</div>';
463print '</div>';
464
465
466print '<div class="clearboth"></div>';
467
468$parameters = array('user' => $user);
469$reshook = $hookmanager->executeHooks('dashboardTickets', $parameters, $object); // Note that $action and $object may have been modified by hook
470
471
472// End of page
473llxFooter();
474$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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
llxFooter()
Footer empty.
Definition document.php:107
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)
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.
dolPrintHTMLForAttribute($s)
Return a string ready to be output on an HTML attribute (alt, title, data-html, .....
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).
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.