* Copyright (C) 2016 Christophe Battarel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * \file ticket/class/actions_ticket.class.php * \ingroup ticket * \brief File Class ticket */ require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php'; /** * Class Actions of the module ticket */ class ActionsTicket { /** * @var DoliDB Database handler. */ public $db; public $dao; public $mesg; /** * @var string Error code (or message) */ public $error; /** * @var string[] Error codes (or messages) */ public $errors = array(); //! Numero de l'erreur public $errno = 0; public $template_dir; public $template; /** * @var string ticket action label */ public $label; /** * @var string description */ public $description; /** * @var int ID */ public $fk_statut; /** * @var int Thirdparty ID */ public $fk_soc; /** * Constructor * * @param DoliDB $db Database handler */ public function __construct($db) { $this->db = $db; } /** * Instantiation of DAO class * * @return void */ public function getInstanceDao() { if (!is_object($this->dao)) { $this->dao = new Ticket($this->db); } } /** * Fetch object * * @param int $id ID of ticket * @param string $ref Reference of ticket * @param string $track_id Track ID of ticket (for public area) * @return void */ public function fetch($id = 0, $ref = '', $track_id = '') { $this->getInstanceDao(); return $this->dao->fetch($id, $ref, $track_id); } /** * Print statut * * @param int $mode Display mode * @return string Label of status */ public function getLibStatut($mode = 0) { $this->getInstanceDao(); $this->dao->fk_statut = $this->fk_statut; return $this->dao->getLibStatut($mode); } /** * Get ticket info * * @param int $id Object id * @return void */ public function getInfo($id) { $this->getInstanceDao(); $this->dao->fetch($id, '', $track_id); $this->label = $this->dao->label; $this->description = $this->dao->description; } /** * Get action title * * @param string $action Type of action * @return string Title of action */ public function getTitle($action = '') { global $langs; if ($action == 'create') { return $langs->trans("CreateTicket"); } elseif ($action == 'edit') { return $langs->trans("EditTicket"); } elseif ($action == 'view') { return $langs->trans("TicketCard"); } elseif ($action == 'add_message') { return $langs->trans("AddMessage"); } else { return $langs->trans("TicketsManagement"); } } /** * View html list of logs * * @param boolean $show_user Show user who make action * @return void */ public function viewTicketLogs($show_user = true) { global $conf, $langs; // Load logs in cache $ret = $this->dao->loadCacheLogsTicket(); if (is_array($this->dao->cache_logs_ticket) && count($this->dao->cache_logs_ticket) > 0) { print ''; print ''; print ''; if ($show_user) { print ''; } foreach ($this->dao->cache_logs_ticket as $id => $arraylogs) { print ''; print ''; if ($show_user) { print ''; } print ''; print ''; print ''; print ''; } print '
'; print $langs->trans('DateCreation'); print ''; print $langs->trans('User'); print '
'; print dol_print_date($arraylogs['datec'], 'dayhour'); print ''; if ($arraylogs['fk_user_create'] > 0) { $userstat = new User($this->db); $res = $userstat->fetch($arraylogs['fk_user_create']); if ($res) { print $userstat->getNomUrl(1); } } print '
'; print dol_nl2br($arraylogs['message']); print '
'; } else { print '
' . $langs->trans('NoLogForThisTicket') . '
'; } } /** * Show ticket original message * * @param User $user User wich display * @param string $action Action mode * @param Ticket $object Object ticket * @return void */ public function viewTicketOriginalMessage($user, $action, $object) { global $langs; print ''."\n"; if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') { // MESSAGE print '
'; print ''; print ''; print ''; } // Initial message print '
'; print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; print ''; print ''; print ''; print '
'; print $langs->trans("InitialMessage"); print ''; if ($user->rights->ticket->manage) { print '' . img_edit($langs->trans('Modify')) . ''; } print '
'; if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') { // MESSAGE $msg = GETPOST('message_initial', 'alpha') ? GETPOST('message_initial', 'alpha') : $object->message; include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; $uselocalbrowser = true; $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser); $doleditor->Create(); } else { // Deal with format differences (text / HTML) if (dol_textishtml($object->message)) { print $object->message; } else { print dol_nl2br($object->message); } //print '
' . $object->message . '
'; } if ($user->rights->ticket->manage && $action == 'edit_message_init') { print '
'; print ' '; print ' '; print '
'; } print '
'; } /** * View html list of message for ticket * * @param boolean $show_private Show private messages * @param boolean $show_user Show user who make action * @return void */ public function viewTicketMessages($show_private, $show_user = true) { global $conf, $langs, $user; // Load logs in cache $ret = $this->dao->loadCacheMsgsTicket(); $action = GETPOST('action'); $this->viewTicketOriginalMessage($user, $action); if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) { print load_fiche_titre($langs->trans('TicketMailExchanges')); print ''; print ''; print ''; if ($show_user) { print ''; } foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) { if (!$arraymsgs['private'] || ($arraymsgs['private'] == "1" && $show_private) ) { //print ''; print ''; print ''; if ($show_user) { print ''; } print ''; print ''; print ''; print ''; } } print '
'; print $langs->trans('DateCreation'); print ''; print $langs->trans('User'); print '
'; print dol_print_date($arraymsgs['datec'], 'dayhour'); print ''; if ($arraymsgs['fk_user_action'] > 0) { $userstat = new User($this->db); $res = $userstat->fetch($arraymsgs['fk_user_action']); if ($res) { print $userstat->getNomUrl(0); } } else { print $langs->trans('Customer'); } print '
'; print $arraymsgs['message']; print '
'; } else { print '
' . $langs->trans('NoMsgForThisTicket') . '
'; } } /** * View list of message for ticket with timeline display * * @param boolean $show_private Show private messages * @param boolean $show_user Show user who make action * @param Ticket $object Object ticket * @return void */ public function viewTicketTimelineMessages($show_private, $show_user, Ticket $object) { global $conf, $langs, $user; // Load logs in cache $ret = $object->loadCacheMsgsTicket(); $action = GETPOST('action'); if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) { print '
'; foreach ($object->cache_msgs_ticket as $id => $arraymsgs) { if (!$arraymsgs['private'] || ($arraymsgs['private'] == "1" && $show_private) ) { print '
'; print '
'; print ''; print '
'; print '
'; print $arraymsgs['message']; print ''; print dol_print_date($arraymsgs['datec'], 'dayhour'); if ($show_user) { if ($arraymsgs['fk_user_action'] > 0) { $userstat = new User($this->db); $res = $userstat->fetch($arraymsgs['fk_user_action']); if ($res) { print '
'; print $userstat->getNomUrl(1); } } else { print '
'; print $langs->trans('Customer'); } } print '
'; print '
'; print '
'; } } print '
'; } else { print '
' . $langs->trans('NoMsgForThisTicket') . '
'; } } /** * Print html navbar with link to set ticket status * * @param Ticket $object Ticket sup * @return void */ public function viewStatusActions(Ticket $object) { global $langs; print '
'; print '
'; print '
'; print '
'; print '' . $langs->trans('TicketChangeStatus') . ''; print '
'; // Exclude status which requires specific method $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED); // Exclude actual status $exclude_status = array_merge($exclude_status, array(intval($object->fk_statut))); // Sort results to be similar to status object list //sort($exclude_status); foreach ($object->statuts_short as $status => $status_label) { if (!in_array($status, $exclude_status)) { print '
'; if ($status == 1) { $urlforbutton = $_SERVER['PHP_SELF'] . '?track_id=' . $object->track_id . '&action=mark_ticket_read'; // To set as read, we use a dedicated action } else { $urlforbutton = $_SERVER['PHP_SELF'] . '?track_id=' . $object->track_id . '&action=set_status&new_status=' . $status; } print ''; print img_picto($langs->trans($object->statuts_short[$status]), 'statut' . $status . '.png@ticket') . ' ' . $langs->trans($object->statuts_short[$status]); print ''; print '
'; } } print '

'; } /** * Hook to add email element template * * @param array $parameters Parameters * @param Ticket $object Object for action * @param string $action Action string * @param HookManager $hookmanager Hookmanager object * @return int */ public function emailElementlist($parameters, &$object, &$action, $hookmanager) { global $langs; $error = 0; if (in_array('admin', explode(':', $parameters['context']))) { $this->results = array('ticket_send' => $langs->trans('MailToSendTicketMessage')); } if (! $error) { return 0; // or return 1 to replace standard code } else { $this->errors[] = 'Error message'; return -1; } } }