dolibarr 19.0.3
box_last_modified_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 * 2016 Christophe Battarel <christophe@altairis.fr>
5 * Copyright (C) 2019-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_modified_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("BoxLastModifiedTicket");
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("BoxLastModifiedTicketDescription", $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("BoxLastModifiedTicketContent"),
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.tms as datem, 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
96 $sql .= " WHERE t.entity IN (".getEntity('ticket').')';
97 // $sql.= " AND e.rowid = er.fk_event";
98 //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
99 if ($user->socid) {
100 $sql .= " AND t.fk_soc = ".((int) $user->socid);
101 }
102
103 $sql .= " ORDER BY t.tms DESC, t.rowid DESC";
104 $sql .= $this->db->plimit($max, 0);
105
106 $resql = $this->db->query($sql);
107 if ($resql) {
108 $num = $this->db->num_rows($resql);
109
110 $i = 0;
111
112 while ($i < $num) {
113 $objp = $this->db->fetch_object($resql);
114 $datec = $this->db->jdate($objp->datec);
115 $datem = $this->db->jdate($objp->datem);
116
117 $ticket = new Ticket($this->db);
118 $ticket->id = $objp->id;
119 $ticket->track_id = $objp->track_id;
120 $ticket->ref = $objp->ref;
121 $ticket->subject = $objp->subject;
122 $ticket->date_creation = $datec;
123 $ticket->date_modification = $datem;
124 //$ticket->fk_statut = $objp->status;
125 //$ticket->fk_statut = $objp->status;
126 $ticket->status = $objp->status;
127 $ticket->statut = $objp->status;
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 = dol_print_email($objp->origin_email);
138 }
139
140
141 $r = 0;
142
143 // Ticket
144 $this->info_box_contents[$i][0] = array(
145 'td' => 'class="nowraponall"',
146 'text' => $ticket->getNomUrl(1),
147 'asis' => 1,
148 );
149 $r++;
150
151 // Subject
152 $this->info_box_contents[$i][$r] = array(
153 'td' => 'class="nowrap tdoverflowmax150"',
154 'text' => $objp->subject, // Some event have no ref
155 'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".$objp->track_id,
156 );
157 $r++;
158
159 // Customer
160 $this->info_box_contents[$i][$r] = array(
161 'td' => 'class="tdoverflowmax150"',
162 'text' => $link,
163 'asis' => 1,
164 );
165 $r++;
166
167 // Date creation
168 $this->info_box_contents[$i][$r] = array(
169 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
170 'text' => dol_print_date($datem, 'dayhour', 'tzuserrel')
171 );
172 $r++;
173
174 // Statut
175 $this->info_box_contents[$i][$r] = array(
176 'td' => 'class="right nowraponall"',
177 'text' => $ticket->getLibStatut(3)
178 );
179 $r++;
180
181 $i++;
182 }
183
184 if ($num == 0) {
185 $this->info_box_contents[$i][0] = array(
186 'td' => '',
187 'text'=>'<span class="opacitymedium">'.$langs->trans("BoxLastModifiedTicketNoRecordedTickets").'</span>'
188 );
189 }
190 } else {
191 dol_print_error($this->db);
192 }
193 } else {
194 $this->info_box_contents[0][0] = array(
195 'td' => '',
196 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
197 );
198 }
199 }
200
209 public function showBox($head = null, $contents = null, $nooutput = 0)
210 {
211 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
212 }
213}
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last modified 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.
__construct($db, $param='')
Constructor.
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.