dolibarr 20.0.0
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 *
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_modified_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("BoxLastModifiedTicket");
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("BoxLastModifiedTicketDescription", $max);
67 $this->info_box_head = array(
68 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/ticket/list.php?sortfield=t.tms&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("BoxLastModifiedTicketContent"),
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.tms as datem, 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
87 $sql .= " WHERE t.entity IN (".getEntity('ticket').')';
88 // $sql.= " AND e.rowid = er.fk_event";
89 //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
90 if ($user->socid) {
91 $sql .= " AND t.fk_soc = ".((int) $user->socid);
92 }
93
94 $sql .= " ORDER BY t.tms DESC, t.rowid DESC";
95 $sql .= $this->db->plimit($max, 0);
96
97 $resql = $this->db->query($sql);
98 if ($resql) {
99 $num = $this->db->num_rows($resql);
100
101 $i = 0;
102
103 while ($i < $num) {
104 $objp = $this->db->fetch_object($resql);
105 $datec = $this->db->jdate($objp->datec);
106 $datem = $this->db->jdate($objp->datem);
107
108 $ticket = new Ticket($this->db);
109 $ticket->id = $objp->id;
110 $ticket->track_id = $objp->track_id;
111 $ticket->ref = $objp->ref;
112 $ticket->subject = $objp->subject;
113 $ticket->date_creation = $datec;
114 $ticket->date_modification = $datem;
115 //$ticket->fk_statut = $objp->status;
116 //$ticket->fk_statut = $objp->status;
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
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 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_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.