dolibarr 21.0.0-beta
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 * 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_modified_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("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 $this->info_box_contents[0][0] = array(
77 'td' => 'class="left"',
78 'text' => $langs->trans("BoxLastModifiedTicketContent"),
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.tms as datem, 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
91 $sql .= " WHERE t.entity IN (".getEntity('ticket').')';
92 // $sql.= " AND e.rowid = er.fk_event";
93 //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
94 if ($user->socid) {
95 $sql .= " AND t.fk_soc = ".((int) $user->socid);
96 }
97
98 $sql .= " ORDER BY t.tms DESC, t.rowid DESC";
99 $sql .= $this->db->plimit($max, 0);
100
101 $resql = $this->db->query($sql);
102 if ($resql) {
103 $num = $this->db->num_rows($resql);
104
105 $i = 0;
106
107 while ($i < $num) {
108 $objp = $this->db->fetch_object($resql);
109 $datec = $this->db->jdate($objp->datec);
110 $datem = $this->db->jdate($objp->datem);
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->subject = $objp->subject;
117 $ticket->date_creation = $datec;
118 $ticket->date_modification = $datem;
119 //$ticket->fk_statut = $objp->status;
120 //$ticket->fk_statut = $objp->status;
121 $ticket->status = $objp->status;
122 $ticket->statut = $objp->status;
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 = dol_print_email($objp->origin_email);
133 }
134
135
136 $r = 0;
137
138 // Ticket
139 $this->info_box_contents[$i][0] = array(
140 'td' => 'class="nowraponall"',
141 'text' => $ticket->getNomUrl(1),
142 'asis' => 1,
143 );
144 $r++;
145
146 // Subject
147 $this->info_box_contents[$i][$r] = array(
148 'td' => 'class="nowrap tdoverflowmax150"',
149 'text' => $objp->subject, // Some event have no ref
150 'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".$objp->track_id,
151 );
152 $r++;
153
154 // Customer
155 $this->info_box_contents[$i][$r] = array(
156 'td' => 'class="tdoverflowmax150"',
157 'text' => $link,
158 'asis' => 1,
159 );
160 $r++;
161
162 // Date creation
163 $this->info_box_contents[$i][$r] = array(
164 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
165 'text' => dol_print_date($datem, 'dayhour', 'tzuserrel')
166 );
167 $r++;
168
169 // Statut
170 $this->info_box_contents[$i][$r] = array(
171 'td' => 'class="right nowraponall"',
172 'text' => $ticket->getLibStatut(3)
173 );
174 $r++;
175
176 $i++;
177 }
178
179 if ($num == 0) {
180 $this->info_box_contents[$i][0] = array(
181 'td' => '',
182 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastModifiedTicketNoRecordedTickets").'</span>'
183 );
184 }
185 } else {
186 dol_print_error($this->db);
187 }
188 } else {
189 $this->info_box_contents[0][0] = array(
190 'td' => '',
191 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
192 );
193 }
194 }
195
196
197
206 public function showBox($head = null, $contents = null, $nooutput = 0)
207 {
208 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
209 }
210}
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_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.