dolibarr 25.0.0-alpha
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 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
5 * Copyright (C) 2019-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2026 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_modified_ticket";
35 public $boximg = "ticket";
39 public $boxlabel;
40 public $depends = array("ticket");
41
47 public function __construct($db, $param = '') // @phpstan-ignore constructor.unusedParameter
48 {
49 global $langs;
50 $langs->load("boxes");
51 $this->db = $db;
52
53 $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastModifiedTicket");
54 }
55
62 public function loadBox($max = 5)
63 {
64 global $user, $langs;
65
66 $this->max = $max;
67
68 require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
69
70 $text = $langs->trans("BoxLastModifiedTicketDescription", $max);
71 $this->info_box_head = array(
72 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/ticket/list.php?sortfield=t.tms&sortorder=DESC"><span class="badge">...</span></a>',
73 'limit' => dol_strlen($text)
74 );
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";
79 $sql .= ", t.type_code, t.category_code, t.severity_code, t.datec, GREATEST(t.tms, tef.tms) as datem, 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."ticket_extrafields as tef ON tef.fk_object = t.rowid";
84 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code = t.type_code AND type.entity = t.entity";
85 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code = t.category_code AND category.entity = t.entity";
86 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code = t.severity_code AND severity.entity = t.entity";
87 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
88
89 $sql .= " WHERE t.entity IN (".getEntity('ticket').')';
90 // $sql.= " AND e.rowid = er.fk_event";
91 //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
92 if ($user->socid) {
93 $sql .= " AND t.fk_soc = ".((int) $user->socid);
94 }
95
96 $sql .= " ORDER BY datem 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 $datec = $this->db->jdate($objp->datec);
108 $datem = $this->db->jdate($objp->datem);
109
110 $ticket = new Ticket($this->db);
111 $ticket->id = $objp->id;
112 $ticket->track_id = $objp->track_id;
113 $ticket->ref = $objp->ref;
114 $ticket->subject = $objp->subject;
115 $ticket->date_creation = $datec;
116 $ticket->date_modification = $datem;
117 $ticket->status = $objp->status;
118 $ticket->statut = $objp->status;
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 = dol_print_email($objp->origin_email);
129 }
130
131
132 $r = 0;
133
134 // Ticket
135 $this->info_box_contents[$i][0] = 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="nowrap tdoverflowmax150"',
145 'text' => $objp->subject, // Some event have no ref
146 'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".$objp->track_id,
147 );
148 $r++;
149
150 // Customer
151 $this->info_box_contents[$i][$r] = array(
152 'td' => 'class="tdoverflowmax150"',
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("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
161 'text' => dol_print_date($datem, '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(
177 'td' => '',
178 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastModifiedTicketNoRecordedTickets").'</span>'
179 );
180 }
181 } else {
182 dol_print_error($this->db);
183 }
184 } else {
185 $this->info_box_contents[0][0] = array(
186 'td' => '',
187 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
188 );
189 }
190 }
191
192
193
202 public function showBox($head = null, $contents = null, $nooutput = 0)
203 {
204 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
205 }
206}
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_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
Class to generate the form for creating a new ticket.