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