dolibarr 19.0.4
box_last_ticket.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) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
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
26require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27
32{
33 public $boxcode = "box_last_ticket";
34 public $boximg = "ticket";
35 public $boxlabel;
36 public $depends = array("ticket");
37
41 public $db;
42
43 public $param;
44 public $info_box_head = array();
45 public $info_box_contents = array();
46
52 public function __construct($db, $param = '')
53 {
54 global $langs;
55 $langs->load("boxes");
56 $this->db = $db;
57
58 $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastTicket");
59 }
60
67 public function loadBox($max = 5)
68 {
69 global $conf, $user, $langs;
70
71 $this->max = $max;
72
73 require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
74
75 $text = $langs->trans("BoxLastTicketDescription", $max);
76 $this->info_box_head = array(
77 'text' => $text,
78 'limit' => dol_strlen($text),
79 );
80
81 $this->info_box_contents[0][0] = array(
82 'td' => 'class="left"',
83 'text' => $langs->trans("BoxLastTicketContent"),
84 );
85
86 if ($user->hasRight('ticket', 'read')) {
87 $sql = "SELECT t.rowid as id, t.ref, t.track_id, t.fk_soc, t.fk_user_create, t.fk_user_assign, t.subject, t.message, t.fk_statut as status, t.type_code, t.category_code, t.severity_code, t.datec, t.date_read, t.date_close, t.origin_email,";
88 $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label,";
89 $sql .= " s.nom as company_name, s.email as socemail, s.client, s.fournisseur";
90 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
91 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
92 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
93 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
94 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
95 $sql .= " WHERE t.entity IN (".getEntity('ticket').")";
96 // $sql.= " AND e.rowid = er.fk_event";
97 //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
98 if ($user->socid) {
99 $sql .= " AND t.fk_soc= ".((int) $user->socid);
100 }
101
102 //$sql.= " AND t.fk_statut > 9";
103
104 $sql .= " ORDER BY t.datec DESC, t.rowid DESC ";
105 $sql .= $this->db->plimit($max, 0);
106
107 $resql = $this->db->query($sql);
108 if ($resql) {
109 $num = $this->db->num_rows($resql);
110
111 $i = 0;
112
113 while ($i < $num) {
114 $objp = $this->db->fetch_object($resql);
115
116 $datec = $this->db->jdate($objp->datec);
117 //$dateterm = $this->db->jdate($objp->fin_validite);
118 //$dateclose = $this->db->jdate($objp->date_close);
119 //$late = '';
120
121 $ticket = new Ticket($this->db);
122 $ticket->id = $objp->id;
123 $ticket->track_id = $objp->track_id;
124 $ticket->ref = $objp->ref;
125 $ticket->fk_statut = $objp->status;
126 $ticket->status = $objp->status;
127 $ticket->subject = $objp->subject;
128 if ($objp->fk_soc > 0) {
129 $thirdparty = new Societe($this->db);
130 $thirdparty->id = $objp->fk_soc;
131 $thirdparty->email = $objp->socemail;
132 $thirdparty->client = $objp->client;
133 $thirdparty->fournisseur = $objp->fournisseur;
134 $thirdparty->name = $objp->company_name;
135 $link = $thirdparty->getNomUrl(1);
136 } else {
137 $link = '<span title="'.$objp->origin_email.'">'.dol_print_email($objp->origin_email).'</span>';
138 }
139
140 $r = 0;
141
142 // Ticket
143 $this->info_box_contents[$i][$r] = array(
144 'td' => 'class="nowraponall"',
145 'text' => $ticket->getNomUrl(1),
146 'asis' => 1
147 );
148 $r++;
149
150 // Subject
151 $this->info_box_contents[$i][$r] = array(
152 'td' => 'class="tdoverflowmax200"',
153 'text' => '<span title="'.dol_escape_htmltag($objp->subject).'">'.dol_escape_htmltag($objp->subject).'</span>', // Some event have no ref
154 'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".urlencode($objp->track_id),
155 );
156 $r++;
157
158 // Customer
159 $this->info_box_contents[$i][$r] = array(
160 'td' => 'class="tdoverflowmax100"',
161 'text' => $link,
162 'asis' => 1,
163 );
164 $r++;
165
166 // Date creation
167 $this->info_box_contents[$i][$r] = array(
168 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"',
169 'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'),
170 );
171 $r++;
172
173 // Statut
174 $this->info_box_contents[$i][$r] = array(
175 'td' => 'class="right nowraponall"',
176 'text' => $ticket->getLibStatut(3),
177 );
178 $r++;
179
180 $i++;
181 }
182
183 if ($num == 0) {
184 $this->info_box_contents[$i][0] = array('td' => '', 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>');
185 }
186 } else {
187 dol_print_error($this->db);
188 }
189 } else {
190 $this->info_box_contents[0][0] = array('td' => '',
191 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>');
192 }
193 }
194
203 public function showBox($head = null, $contents = null, $nooutput = 0)
204 {
205 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
206 }
207}
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last created tickets.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
Class to generate the form for creating a new ticket.