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