dolibarr 21.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 * 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";
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("BoxLastModifiedTicket");
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("BoxLastModifiedTicketDescription", $max);
68 $this->info_box_head = array(
69 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/ticket/list.php?sortfield=t.tms&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("BoxLastModifiedTicketContent"),
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.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."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
88 $sql .= " WHERE t.entity IN (".getEntity('ticket').')';
89 // $sql.= " AND e.rowid = er.fk_event";
90 //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
91 if ($user->socid) {
92 $sql .= " AND t.fk_soc = ".((int) $user->socid);
93 }
94
95 $sql .= " ORDER BY t.tms 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 $datec = $this->db->jdate($objp->datec);
107 $datem = $this->db->jdate($objp->datem);
108
109 $ticket = new Ticket($this->db);
110 $ticket->id = $objp->id;
111 $ticket->track_id = $objp->track_id;
112 $ticket->ref = $objp->ref;
113 $ticket->subject = $objp->subject;
114 $ticket->date_creation = $datec;
115 $ticket->date_modification = $datem;
116 //$ticket->fk_statut = $objp->status;
117 //$ticket->fk_statut = $objp->status;
118 $ticket->status = $objp->status;
119 $ticket->statut = $objp->status;
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 = dol_print_email($objp->origin_email);
130 }
131
132
133 $r = 0;
134
135 // Ticket
136 $this->info_box_contents[$i][0] = array(
137 'td' => 'class="nowraponall"',
138 'text' => $ticket->getNomUrl(1),
139 'asis' => 1,
140 );
141 $r++;
142
143 // Subject
144 $this->info_box_contents[$i][$r] = array(
145 'td' => 'class="nowrap tdoverflowmax150"',
146 'text' => $objp->subject, // Some event have no ref
147 'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".$objp->track_id,
148 );
149 $r++;
150
151 // Customer
152 $this->info_box_contents[$i][$r] = array(
153 'td' => 'class="tdoverflowmax150"',
154 'text' => $link,
155 'asis' => 1,
156 );
157 $r++;
158
159 // Date creation
160 $this->info_box_contents[$i][$r] = array(
161 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
162 'text' => dol_print_date($datem, 'dayhour', 'tzuserrel')
163 );
164 $r++;
165
166 // Statut
167 $this->info_box_contents[$i][$r] = array(
168 'td' => 'class="right nowraponall"',
169 'text' => $ticket->getLibStatut(3)
170 );
171 $r++;
172
173 $i++;
174 }
175
176 if ($num == 0) {
177 $this->info_box_contents[$i][0] = array(
178 'td' => '',
179 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastModifiedTicketNoRecordedTickets").'</span>'
180 );
181 }
182 } else {
183 dol_print_error($this->db);
184 }
185 } else {
186 $this->info_box_contents[0][0] = array(
187 'td' => '',
188 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
189 );
190 }
191 }
192
193
194
203 public function showBox($head = null, $contents = null, $nooutput = 0)
204 {
205 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
206 }
207}
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.