dolibarr  16.0.5
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  *
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 
26 require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27 
32 {
33 
34  public $boxcode = "box_last_ticket";
35  public $boximg = "ticket";
36  public $boxlabel;
37  public $depends = array("ticket");
38 
42  public $db;
43 
44  public $param;
45  public $info_box_head = array();
46  public $info_box_contents = array();
47 
53  public function __construct($db, $param = '')
54  {
55  global $langs;
56  $langs->load("boxes");
57  $this->db = $db;
58 
59  $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastTicket");
60  }
61 
68  public function loadBox($max = 5)
69  {
70  global $conf, $user, $langs;
71 
72  $this->max = $max;
73 
74  require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
75 
76  $text = $langs->trans("BoxLastTicketDescription", $max);
77  $this->info_box_head = array(
78  'text' => $text,
79  'limit' => dol_strlen($text),
80  );
81 
82  $this->info_box_contents[0][0] = array(
83  'td' => 'class="left"',
84  'text' => $langs->trans("BoxLastTicketContent"),
85  );
86 
87  if ($user->rights->ticket->read) {
88  $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,";
89  $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label,";
90  $sql .= " s.nom as company_name, s.email as socemail, s.client, s.fournisseur";
91  $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
92  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
93  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
94  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
95  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
96  $sql .= " WHERE t.entity IN (".getEntity('ticket').")";
97  // $sql.= " AND e.rowid = er.fk_event";
98  //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
99  if ($user->socid) {
100  $sql .= " AND t.fk_soc= ".((int) $user->socid);
101  }
102 
103  //$sql.= " AND t.fk_statut > 9";
104 
105  $sql .= " ORDER BY t.datec DESC, t.rowid DESC ";
106  $sql .= $this->db->plimit($max, 0);
107 
108  $resql = $this->db->query($sql);
109  if ($resql) {
110  $num = $this->db->num_rows($resql);
111 
112  $i = 0;
113 
114  while ($i < $num) {
115  $objp = $this->db->fetch_object($resql);
116 
117  $datec = $this->db->jdate($objp->datec);
118  //$dateterm = $this->db->jdate($objp->fin_validite);
119  //$dateclose = $this->db->jdate($objp->date_close);
120  //$late = '';
121 
122  $ticket = new Ticket($this->db);
123  $ticket->id = $objp->id;
124  $ticket->track_id = $objp->track_id;
125  $ticket->ref = $objp->ref;
126  $ticket->fk_statut = $objp->status;
127  $ticket->status = $objp->status;
128  $ticket->subject = $objp->subject;
129  if ($objp->fk_soc > 0) {
130  $thirdparty = new Societe($this->db);
131  $thirdparty->id = $objp->fk_soc;
132  $thirdparty->email = $objp->socemail;
133  $thirdparty->client = $objp->client;
134  $thirdparty->fournisseur = $objp->fournisseur;
135  $thirdparty->name = $objp->company_name;
136  $link = $thirdparty->getNomUrl(1);
137  } else {
138  $link = '<span title="'.$objp->origin_email.'">'.dol_print_email($objp->origin_email).'</span>';
139  }
140 
141  $r = 0;
142 
143  // Ticket
144  $this->info_box_contents[$i][$r] = array(
145  'td' => 'class="nowraponall"',
146  'text' => $ticket->getNomUrl(1),
147  'asis' => 1
148  );
149  $r++;
150 
151  // Subject
152  $this->info_box_contents[$i][$r] = array(
153  'td' => 'class="tdoverflowmax200"',
154  'text' => '<span title="'.dol_escape_htmltag($objp->subject).'">'.dol_escape_htmltag($objp->subject).'</span>', // Some event have no ref
155  'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".urlencode($objp->track_id),
156  );
157  $r++;
158 
159  // Customer
160  $this->info_box_contents[$i][$r] = array(
161  'td' => 'class="tdoverflowmax100"',
162  'text' => $link,
163  'asis' => 1,
164  );
165  $r++;
166 
167  // Date creation
168  $this->info_box_contents[$i][$r] = array(
169  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"',
170  'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'),
171  );
172  $r++;
173 
174  // Statut
175  $this->info_box_contents[$i][$r] = array(
176  'td' => 'class="right nowraponall"',
177  'text' => $ticket->getLibStatut(3),
178  );
179  $r++;
180 
181  $i++;
182  }
183 
184  if ($num == 0) {
185  $this->info_box_contents[$i][0] = array('td' => '', 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>');
186  }
187  } else {
188  dol_print_error($this->db);
189  }
190  } else {
191  $this->info_box_contents[0][0] = array('td' => '',
192  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>');
193  }
194  }
195 
204  public function showBox($head = null, $contents = null, $nooutput = 0)
205  {
206  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
207  }
208 }
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
box_last_ticket\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_last_ticket.php:204
box_last_ticket
Class to manage the box.
Definition: box_last_ticket.php:31
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
box_last_ticket\__construct
__construct($db, $param='')
Constructor.
Definition: box_last_ticket.php:53
dol_print_email
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
Definition: functions.lib.php:2960
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
Ticket
Class to generate the form for creating a new ticket.
Definition: html.formticket.class.php:31
box_last_ticket\loadBox
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_last_ticket.php:68
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34