box_last_ticket.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. /**
  21. * \file htdocs/core/boxes/box_last_ticket.php
  22. * \ingroup ticket
  23. * \brief This box shows latest created tickets
  24. */
  25. require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
  26. /**
  27. * Class to manage the box
  28. */
  29. class box_last_ticket extends ModeleBoxes
  30. {
  31. public $boxcode = "box_last_ticket";
  32. public $boximg = "ticket";
  33. public $boxlabel;
  34. public $depends = array("ticket");
  35. /**
  36. * @var DoliDB Database handler.
  37. */
  38. public $db;
  39. public $param;
  40. public $info_box_head = array();
  41. public $info_box_contents = array();
  42. /**
  43. * Constructor
  44. * @param DoliDB $db Database handler
  45. * @param string $param More parameters
  46. */
  47. public function __construct($db, $param = '')
  48. {
  49. global $langs;
  50. $langs->load("boxes");
  51. $this->db = $db;
  52. $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastTicket");
  53. }
  54. /**
  55. * Load data into info_box_contents array to show array later.
  56. *
  57. * @param int $max Maximum number of records to load
  58. * @return void
  59. */
  60. public function loadBox($max = 5)
  61. {
  62. global $conf, $user, $langs;
  63. $this->max = $max;
  64. require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
  65. $text = $langs->trans("BoxLastTicketDescription", $max);
  66. $this->info_box_head = array(
  67. 'text' => $text,
  68. 'limit' => dol_strlen($text),
  69. );
  70. $this->info_box_contents[0][0] = array(
  71. 'td' => 'class="left"',
  72. 'text' => $langs->trans("BoxLastTicketContent"),
  73. );
  74. if ($user->rights->ticket->read) {
  75. $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,";
  76. $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label,";
  77. $sql .= " s.nom as company_name, s.email as socemail, s.client, s.fournisseur";
  78. $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
  79. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
  80. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
  81. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
  82. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
  83. $sql .= " WHERE t.entity IN (".getEntity('ticket').")";
  84. // $sql.= " AND e.rowid = er.fk_event";
  85. //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  86. if ($user->socid) {
  87. $sql .= " AND t.fk_soc= ".((int) $user->socid);
  88. }
  89. //$sql.= " AND t.fk_statut > 9";
  90. $sql .= " ORDER BY t.datec DESC, t.rowid DESC ";
  91. $sql .= $this->db->plimit($max, 0);
  92. $resql = $this->db->query($sql);
  93. if ($resql) {
  94. $num = $this->db->num_rows($resql);
  95. $i = 0;
  96. while ($i < $num) {
  97. $objp = $this->db->fetch_object($resql);
  98. $datec = $this->db->jdate($objp->datec);
  99. //$dateterm = $this->db->jdate($objp->fin_validite);
  100. //$dateclose = $this->db->jdate($objp->date_close);
  101. //$late = '';
  102. $ticket = new Ticket($this->db);
  103. $ticket->id = $objp->id;
  104. $ticket->track_id = $objp->track_id;
  105. $ticket->ref = $objp->ref;
  106. $ticket->fk_statut = $objp->status;
  107. $ticket->status = $objp->status;
  108. $ticket->subject = $objp->subject;
  109. if ($objp->fk_soc > 0) {
  110. $thirdparty = new Societe($this->db);
  111. $thirdparty->id = $objp->fk_soc;
  112. $thirdparty->email = $objp->socemail;
  113. $thirdparty->client = $objp->client;
  114. $thirdparty->fournisseur = $objp->fournisseur;
  115. $thirdparty->name = $objp->company_name;
  116. $link = $thirdparty->getNomUrl(1);
  117. } else {
  118. $link = '<span title="'.$objp->origin_email.'">'.dol_print_email($objp->origin_email).'</span>';
  119. }
  120. $r = 0;
  121. // Ticket
  122. $this->info_box_contents[$i][$r] = array(
  123. 'td' => 'class="nowraponall"',
  124. 'text' => $ticket->getNomUrl(1),
  125. 'asis' => 1
  126. );
  127. $r++;
  128. // Subject
  129. $this->info_box_contents[$i][$r] = array(
  130. 'td' => 'class="tdoverflowmax200"',
  131. 'text' => '<span title="'.dol_escape_htmltag($objp->subject).'">'.dol_escape_htmltag($objp->subject).'</span>', // Some event have no ref
  132. 'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".urlencode($objp->track_id),
  133. );
  134. $r++;
  135. // Customer
  136. $this->info_box_contents[$i][$r] = array(
  137. 'td' => 'class="tdoverflowmax100"',
  138. 'text' => $link,
  139. 'asis' => 1,
  140. );
  141. $r++;
  142. // Date creation
  143. $this->info_box_contents[$i][$r] = array(
  144. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"',
  145. 'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'),
  146. );
  147. $r++;
  148. // Statut
  149. $this->info_box_contents[$i][$r] = array(
  150. 'td' => 'class="right nowraponall"',
  151. 'text' => $ticket->getLibStatut(3),
  152. );
  153. $r++;
  154. $i++;
  155. }
  156. if ($num == 0) {
  157. $this->info_box_contents[$i][0] = array('td' => '', 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>');
  158. }
  159. } else {
  160. dol_print_error($this->db);
  161. }
  162. } else {
  163. $this->info_box_contents[0][0] = array('td' => '',
  164. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>');
  165. }
  166. }
  167. /**
  168. * Method to show box
  169. *
  170. * @param array $head Array with properties of box title
  171. * @param array $contents Array with properties of box lines
  172. * @param int $nooutput No print, only return string
  173. * @return string
  174. */
  175. public function showBox($head = null, $contents = null, $nooutput = 0)
  176. {
  177. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  178. }
  179. }