dolibarr  13.0.2
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-2019 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, 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 
97  $sql .= " WHERE t.entity = ".$conf->entity;
98  // $sql.= " AND e.rowid = er.fk_event";
99  //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
100  if ($user->socid) {
101  $sql .= " AND t.fk_soc= ".$user->socid;
102  }
103 
104  //$sql.= " AND t.fk_statut > 9";
105 
106  $sql .= " ORDER BY t.datec DESC, t.rowid DESC ";
107  $sql .= $this->db->plimit($max, 0);
108 
109  $resql = $this->db->query($sql);
110  if ($resql) {
111  $num = $this->db->num_rows($resql);
112 
113  $i = 0;
114 
115  while ($i < $num) {
116  $objp = $this->db->fetch_object($resql);
117  $datec = $this->db->jdate($objp->datec);
118  $dateterm = $this->db->jdate($objp->fin_validite);
119  $dateclose = $this->db->jdate($objp->date_cloture);
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->fk_statut;
127  $ticket->subject = $objp->subject;
128  if ($objp->fk_soc > 0) {
129  $thirdparty = new Societe($this->db);
130  $thirdparty->id = $objp->fk_soc;
131  $thirdparty->email = $objp->socemail;
132  $thirdparty->client = $objp->client;
133  $thirdparty->fournisseur = $objp->fournisseur;
134  $thirdparty->name = $objp->company_name;
135  $link = $thirdparty->getNomUrl(1);
136  } else {
137  $link = '<span title="'.$objp->origin_email.'">'.dol_print_email($objp->origin_email).'</span>';
138  }
139 
140  $r = 0;
141 
142  // Ticket
143  $this->info_box_contents[$i][$r] = array(
144  'td' => 'class="nowraponall"',
145  'text' => $ticket->getNomUrl(1),
146  'asis' => 1
147  );
148  $r++;
149 
150  // Subject
151  $this->info_box_contents[$i][$r] = array(
152  'td' => 'class="tdoverflowmax200"',
153  'text' => '<span title="'.$objp->subject.'">'.$objp->subject.'</span>', // Some event have no ref
154  'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".$objp->track_id,
155  );
156  $r++;
157 
158  // Customer
159  $this->info_box_contents[$i][$r] = array(
160  'td' => 'class="tdoverflowmax100"',
161  'text' => $link,
162  'asis' => 1,
163  );
164  $r++;
165 
166  // Date creation
167  $this->info_box_contents[$i][$r] = array(
168  'td' => 'class="right"',
169  'text' => dol_print_date($datec, 'dayhour'),
170  );
171  $r++;
172 
173  // Statut
174  $this->info_box_contents[$i][$r] = array(
175  'td' => 'class="right nowraponall"',
176  'text' => $ticket->getLibStatut(3),
177  );
178  $r++;
179 
180  $i++;
181  }
182 
183  if ($num == 0) {
184  $this->info_box_contents[$i][0] = array('td' => 'class="center"', 'text' => $langs->trans("BoxLastTicketNoRecordedTickets"));
185  }
186  } else {
187  dol_print_error($this->db);
188  }
189  } else {
190  $this->info_box_contents[0][0] = array('td' => 'class="left"',
191  'text' => $langs->trans("ReadPermissionNotAllowed"));
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 }
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.
__construct($db, $param= '')
Constructor.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage ticket.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
Class to manage the box.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.