dolibarr 21.0.0-alpha
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 * 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_last_ticket";
35 public $boximg = "ticket";
36 public $boxlabel;
37 public $depends = array("ticket");
38
44 public function __construct($db, $param = '')
45 {
46 global $langs;
47 $langs->load("boxes");
48 $this->db = $db;
49
50 $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastTicket");
51 }
52
59 public function loadBox($max = 5)
60 {
61 global $conf, $user, $langs;
62
63 $this->max = $max;
64
65 require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
66
67 $text = $langs->trans("BoxLastTicketDescription", $max);
68 $this->info_box_head = array(
69 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/ticket/list.php?sortfield=t.datec&sortorder=DESC"><span class="badge">...</span></a>',
70 'limit' => dol_strlen($text),
71 );
72
73 $this->info_box_contents[0][0] = array(
74 'td' => 'class="left"',
75 'text' => $langs->trans("BoxLastTicketContent"),
76 );
77
78 if ($user->hasRight('ticket', 'read')) {
79 $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,";
80 $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label,";
81 $sql .= " s.nom as company_name, s.email as socemail, s.client, s.fournisseur";
82 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
83 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
84 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
85 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
86 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
87 $sql .= " WHERE t.entity IN (".getEntity('ticket').")";
88 // $sql.= " AND e.rowid = er.fk_event";
89 //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
90 if ($user->socid) {
91 $sql .= " AND t.fk_soc= ".((int) $user->socid);
92 }
93
94 //$sql.= " AND t.fk_statut > 9";
95
96 $sql .= " ORDER BY t.datec DESC, t.rowid DESC ";
97 $sql .= $this->db->plimit($max, 0);
98
99 $resql = $this->db->query($sql);
100 if ($resql) {
101 $num = $this->db->num_rows($resql);
102
103 $i = 0;
104
105 while ($i < $num) {
106 $objp = $this->db->fetch_object($resql);
107
108 $datec = $this->db->jdate($objp->datec);
109 //$dateterm = $this->db->jdate($objp->fin_validite);
110 //$dateclose = $this->db->jdate($objp->date_close);
111 //$late = '';
112
113 $ticket = new Ticket($this->db);
114 $ticket->id = $objp->id;
115 $ticket->track_id = $objp->track_id;
116 $ticket->ref = $objp->ref;
117 $ticket->fk_statut = $objp->status;
118 $ticket->status = $objp->status;
119 $ticket->subject = $objp->subject;
120 if ($objp->fk_soc > 0) {
121 $thirdparty = new Societe($this->db);
122 $thirdparty->id = $objp->fk_soc;
123 $thirdparty->email = $objp->socemail;
124 $thirdparty->client = $objp->client;
125 $thirdparty->fournisseur = $objp->fournisseur;
126 $thirdparty->name = $objp->company_name;
127 $link = $thirdparty->getNomUrl(1);
128 } else {
129 $link = '<span title="'.$objp->origin_email.'">'.dol_print_email($objp->origin_email).'</span>';
130 }
131
132 $r = 0;
133
134 // Ticket
135 $this->info_box_contents[$i][$r] = array(
136 'td' => 'class="nowraponall"',
137 'text' => $ticket->getNomUrl(1),
138 'asis' => 1
139 );
140 $r++;
141
142 // Subject
143 $this->info_box_contents[$i][$r] = array(
144 'td' => 'class="tdoverflowmax200"',
145 'text' => '<span title="'.dol_escape_htmltag($objp->subject).'">'.dol_escape_htmltag($objp->subject).'</span>', // Some event have no ref
146 'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".urlencode($objp->track_id),
147 );
148 $r++;
149
150 // Customer
151 $this->info_box_contents[$i][$r] = array(
152 'td' => 'class="tdoverflowmax100"',
153 'text' => $link,
154 'asis' => 1,
155 );
156 $r++;
157
158 // Date creation
159 $this->info_box_contents[$i][$r] = array(
160 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"',
161 'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'),
162 );
163 $r++;
164
165 // Statut
166 $this->info_box_contents[$i][$r] = array(
167 'td' => 'class="right nowraponall"',
168 'text' => $ticket->getLibStatut(3),
169 );
170 $r++;
171
172 $i++;
173 }
174
175 if ($num == 0) {
176 $this->info_box_contents[$i][0] = array('td' => '', 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>');
177 }
178 } else {
179 dol_print_error($this->db);
180 }
181 } else {
182 $this->info_box_contents[0][0] = array('td' => '',
183 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>');
184 }
185 }
186
187
188
197 public function showBox($head = null, $contents = null, $nooutput = 0)
198 {
199 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
200 }
201}
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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).
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.