dolibarr 21.0.0-beta
box_graph_nb_ticket_last_x_days.php
Go to the documentation of this file.
1<?php
2/* Module descriptor for ticket system
3 * Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
4 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
5 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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
27require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
28
33{
34 public $boxcode = "box_graph_nb_ticket_last_x_days";
35 public $boximg = "ticket";
36 public $boxlabel;
37 public $depends = array("ticket");
38
39 public $widgettype = 'graph';
40
46 public function __construct($db, $param = '')
47 {
48 global $langs;
49 $langs->load("boxes");
50 $this->db = $db;
51
52 $this->boxlabel = $langs->transnoentitiesnoconv("BoxNumberOfTicketByDay");
53 }
54
61 public function loadBox($max = 5)
62 {
63 global $conf, $user, $langs;
64 $dataseries = array();
65 $graphtoshow = "";
66
67 $badgeStatus0 = '#cbd3d3'; // draft
68 $badgeStatus1 = '#bc9526'; // validated
69 $badgeStatus1b = '#bc9526'; // validated
70 $badgeStatus2 = '#9c9c26'; // approved
71 $badgeStatus3 = '#bca52b';
72 $badgeStatus4 = '#25a580'; // Color ok
73 $badgeStatus4b = '#25a580'; // Color ok
74 $badgeStatus5 = '#cad2d2';
75 $badgeStatus6 = '#cad2d2';
76 $badgeStatus7 = '#baa32b';
77 $badgeStatus8 = '#993013';
78 $badgeStatus9 = '#e7f0f0';
79 if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php')) {
80 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
81 }
82 $this->max = $max;
83
84
85 $param_day = 'DOLUSER_ticket_last_days';
86 if (GETPOST($param_day)) {
87 if (GETPOST($param_day) >= 15) {
88 $days = 14;
89 } else {
90 $days = GETPOST($param_day);
91 }
92 } else {
93 $days = 7;
94 }
95 require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
96 $text = $langs->trans("BoxTicketLastXDays", $days).'&nbsp;'.img_picto('', 'filter.png', 'id="idsubimgDOLUSER_ticket_last_days" class="linkobject"');
97 $this->info_box_head = array(
98 'text' => $text,
99 'limit' => dol_strlen($text)
100 );
101 $today = dol_now();
102 $intervaltoadd = 1;
103 $minimumdatec = dol_time_plus_duree($today, -1 * ($days - 1), 'd');
104 $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc');
105
106 if ($user->hasRight('ticket', 'read')) {
107 $sql = "SELECT CAST(t.datec AS DATE) as datec, COUNT(t.datec) as nb";
108 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
109 $sql .= " WHERE CAST(t.datec AS DATE) > '".$this->db->idate($minimumdatec)."'";
110 $sql .= " GROUP BY CAST(t.datec AS DATE)";
111
112 $resql = $this->db->query($sql);
113 if ($resql) {
114 $num = $this->db->num_rows($resql);
115 $i = 0;
116 while ($i < $num) {
117 $objp = $this->db->fetch_object($resql);
118 while ($minimumdatecformated < $objp->datec) {
119 $dataseries[] = array('label' => dol_print_date($minimumdatec, 'day'), 'data' => 0);
120 $minimumdatec = dol_time_plus_duree($minimumdatec, $intervaltoadd, 'd');
121 $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc');
122 }
123 $dataseries[] = array('label' => dol_print_date($this->db->jdate($objp->datec), 'day'), 'data' => $objp->nb);
124 $minimumdatec = dol_time_plus_duree($minimumdatec, $intervaltoadd, 'd');
125 $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc');
126 $i++;
127 }
128 while (count($dataseries) < $days) {
129 $dataseries[] = array('label' => dol_print_date($minimumdatec, 'day'), 'data' => 0);
130 $minimumdatec = dol_time_plus_duree($minimumdatec, $intervaltoadd, 'd');
131 $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc');
132 $i++;
133 }
134 } else {
135 dol_print_error($this->db);
136 }
137 $stringtoshow = '<div class="div-table-responsive-no-min">';
138 $stringtoshow .= '<script nonce="'.getNonce().'" type="text/javascript">
139 jQuery(document).ready(function() {
140 jQuery("#idsubimgDOLUSER_ticket_last_days").click(function() {
141 jQuery("#idfilterDOLUSER_ticket_last_days").toggle();
142 });
143 });
144 </script>';
145 $stringtoshow .= '<div class="center hideobject" id="idfilterDOLUSER_ticket_last_days">'; // hideobject is to start hidden
146 $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
147 $stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
148 $stringtoshow .= '<input type="hidden" name="action" value="refresh">';
149 $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_ticket_last_days:days">';
150 $stringtoshow .= ' <input class="flat" size="4" type="text" name="'.$param_day.'" value="'.$days.'">'.$langs->trans("Days");
151 $stringtoshow .= '<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', 0, 1).'">';
152 $stringtoshow .= '</form>';
153 $stringtoshow .= '</div>';
154
155 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
156 $px1 = new DolGraph();
157
158 $mesg = $px1->isGraphKo();
159 $totalnb = 0;
160 if (!$mesg) {
161 $data = array();
162 foreach ($dataseries as $value) {
163 $data[] = array($value['label'], $value['data']);
164 $totalnb += $value['data'];
165 }
166 $px1->SetData($data);
167 //$px1->setShowLegend(2);
168 $px1->setShowLegend(0);
169 $px1->SetType(array('bars'));
170 $px1->SetLegend(array($langs->trans('BoxNumberOfTicketByDay')));
171 $px1->SetMaxValue($px1->GetCeilMaxValue());
172 $px1->SetHeight(192);
173 $px1->SetShading(3);
174 $px1->SetHorizTickIncrement(1);
175 $px1->SetCssPrefix("cssboxes");
176 $px1->mode = 'depth';
177
178 $px1->draw('idgraphticketlastxdays');
179 $graphtoshow = $px1->show($totalnb ? 0 : 1);
180 }
181 if ($totalnb) {
182 $stringtoshow .= $graphtoshow;
183 }
184 $stringtoshow .= '</div>';
185 if ($totalnb) {
186 $this->info_box_contents[][] = array(
187 'td' => 'center',
188 'text' => $stringtoshow
189 );
190 } else {
191 $this->info_box_contents[0][0] = array(
192 'td' => 'class="center"',
193 'text' => '<span class="opacitymedium">'.$stringtoshow.$langs->trans("BoxNoTicketLastXDays", $days).'</span>'
194 );
195 }
196 } else {
197 $this->info_box_contents[0][0] = array(
198 'td' => 'class="left"',
199 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
200 );
201 }
202 }
203
204
205
214 public function showBox($head = null, $contents = null, $nooutput = 0)
215 {
216 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
217 }
218}
Class to build graphs.
Class ModeleBoxes.
Class to manage the box to show new daily tickets.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79