box_last_modified_ticket.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. /**
  21. * \file core/boxes/box_last_modified_ticket.php
  22. * \ingroup ticket
  23. * \brief This box shows latest modified 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_modified_ticket extends ModeleBoxes
  30. {
  31. public $boxcode = "box_last_modified_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("BoxLastModifiedTicket");
  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("BoxLastModifiedTicketDescription", $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("BoxLastModifiedTicketContent"),
  73. );
  74. if ($user->hasRight('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, t.type_code, t.category_code, t.severity_code, t.datec, t.tms as datem, 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 .= " ORDER BY t.tms DESC, t.rowid DESC";
  90. $sql .= $this->db->plimit($max, 0);
  91. $resql = $this->db->query($sql);
  92. if ($resql) {
  93. $num = $this->db->num_rows($resql);
  94. $i = 0;
  95. while ($i < $num) {
  96. $objp = $this->db->fetch_object($resql);
  97. $datec = $this->db->jdate($objp->datec);
  98. $datem = $this->db->jdate($objp->datem);
  99. $ticket = new Ticket($this->db);
  100. $ticket->id = $objp->id;
  101. $ticket->track_id = $objp->track_id;
  102. $ticket->ref = $objp->ref;
  103. $ticket->fk_statut = $objp->fk_statut;
  104. $ticket->subject = $objp->subject;
  105. $ticket->date_creation = $datec;
  106. $ticket->date_modification = $datem;
  107. $ticket->fk_statut = $objp->fk_statut;
  108. $ticket->fk_statut = $objp->fk_statut;
  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 = dol_print_email($objp->origin_email);
  119. }
  120. $r = 0;
  121. // Ticket
  122. $this->info_box_contents[$i][0] = 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="nowrap tdoverflowmax150"',
  131. 'text' => $objp->subject, // Some event have no ref
  132. 'url' => DOL_URL_ROOT."/ticket/card.php?track_id=".$objp->track_id,
  133. );
  134. $r++;
  135. // Customer
  136. $this->info_box_contents[$i][$r] = array(
  137. 'td' => 'class="tdoverflowmax150"',
  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("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  145. 'text' => dol_print_date($datem, '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("BoxLastModifiedTicketNoRecordedTickets").'</span>');
  158. }
  159. } else {
  160. dol_print_error($this->db);
  161. }
  162. } else {
  163. $this->info_box_contents[0][0] = array(
  164. 'td' => '',
  165. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
  166. );
  167. }
  168. }
  169. /**
  170. * Method to show box
  171. *
  172. * @param array $head Array with properties of box title
  173. * @param array $contents Array with properties of box lines
  174. * @param int $nooutput No print, only return string
  175. * @return string
  176. */
  177. public function showBox($head = null, $contents = null, $nooutput = 0)
  178. {
  179. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  180. }
  181. }