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