1<?php 2/* Copyright (C) - 2013-2016 Jean-François FERRY <hello@librethic.io> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18/** 19 * \file htdocs/ticket/agenda.php 20 * \ingroup ticket 21 * \brief Page with events on ticket 22 */ 23 24require '../main.inc.php'; 25require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php'; 26require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php'; 27require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php'; 28require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php"; 29require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; 31require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; 32 33// Load translation files required by the page 34$langs->loadLangs(array('companies', 'other', 'ticket')); 35 36// Get parameters 37$id = GETPOST('id', 'int'); 38$ref = GETPOST('ref', 'alpha'); 39$track_id = GETPOST('track_id', 'alpha', 3); 40$socid = GETPOST('socid', 'int'); 41$action = GETPOST('action', 'aZ09'); 42 43$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; 44$sortfield = GETPOST('sortfield', 'aZ09comma'); 45$sortorder = GETPOST('sortorder', 'aZ09comma'); 46$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 47$page = is_numeric($page) ? $page : 0; 48$page = $page == -1 ? 0 : $page; 49if (!$sortfield) { 50 $sortfield = "a.datep,a.id"; 51} 52if (!$sortorder) { 53 $sortorder = "DESC"; 54} 55$offset = $limit * $page; 56$pageprev = $page - 1; 57$pagenext = $page + 1; 58 59if (GETPOST('actioncode', 'array')) { 60 $actioncode = GETPOST('actioncode', 'array', 3); 61 if (!count($actioncode)) { 62 $actioncode = '0'; 63 } 64} else { 65 $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); 66} 67$search_agenda_label = GETPOST('search_agenda_label'); 68 69$object = new Ticket($db); 70$object->fetch($id, $ref, $track_id); 71 72$extrafields = new ExtraFields($db); 73 74$extrafields->fetch_name_optionals_label($object->table_element); 75 76if (!$action) { 77 $action = 'view'; 78} 79 80 81// Security check 82$id = GETPOST("id", 'int'); 83$socid = 0; 84if ($user->socid > 0) $socid = $user->socid; 85$result = restrictedArea($user, 'ticket', $id, ''); 86 87// restrict access for externals users 88if ($user->socid > 0 && ($object->fk_soc != $user->socid)) { 89 accessforbidden(); 90} 91// or for unauthorized internals users 92if (!$user->socid && ($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) { 93 accessforbidden(); 94} 95 96 97 98/* 99 * Actions 100 */ 101 102$parameters = array('id'=>$socid); 103$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks 104if ($reshook < 0) { 105 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 106} 107 108if (empty($reshook)) { 109 // Set view style 110 $_SESSION['ticket-view-type'] = "list"; 111} 112 113// Purge search criteria 114if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers 115 $actioncode = ''; 116 $search_agenda_label = ''; 117} 118 119 120 121/* 122 * View 123 */ 124 125$form = new Form($db); 126$userstat = new User($db); 127$formticket = new FormTicket($db); 128 129$title = $langs->trans("Ticket").' - '.$object->ref.' '.$object->name; 130if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/ticketnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) { 131 $title = $object->ref.' '.$object->name.' - '.$langs->trans("Info"); 132} 133$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda'; 134 135llxHeader('', $title, $help_url); 136 137if ($socid > 0) { 138 $object->fetch_thirdparty(); 139 $head = societe_prepare_head($object->thirdparty); 140 141 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company'); 142 143 dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom'); 144 145 print dol_get_fiche_end(); 146} 147 148if (!$user->socid && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) { 149 $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'"; 150} elseif ($user->socid > 0) { 151 $object->next_prev_filter = "te.fk_soc = '".$user->socid."'"; 152} 153$head = ticket_prepare_head($object); 154 155print dol_get_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticket'); 156 157$morehtmlref = '<div class="refidno">'; 158$morehtmlref .= $object->subject; 159// Author 160if ($object->fk_user_create > 0) { 161 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : '; 162 163 $langs->load("users"); 164 $fuser = new User($db); 165 $fuser->fetch($object->fk_user_create); 166 $morehtmlref .= $fuser->getNomUrl(0); 167} 168if (!empty($object->origin_email)) { 169 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : '; 170 $morehtmlref .= $object->origin_email.' <small>('.$langs->trans("TicketEmailOriginIssuer").')</small>'; 171} 172 173// Thirdparty 174if (!empty($conf->societe->enabled)) { 175 $morehtmlref .= '<br>'.$langs->trans('ThirdParty'); 176 /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) { 177 $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>'; 178 }*/ 179 $morehtmlref .= ' : '; 180 if ($action == 'editcustomer') { 181 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1); 182 } else { 183 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1); 184 } 185} 186 187// Project 188if (!empty($conf->projet->enabled)) { 189 $langs->load("projects"); 190 $morehtmlref .= '<br>'.$langs->trans('Project'); 191 if ($user->rights->ticket->write) { 192 if ($action != 'classify') { 193 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>'; 194 $morehtmlref .= ' : '; 195 } 196 if ($action == 'classify') { 197 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 198 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 199 $morehtmlref .= '<input type="hidden" name="action" value="classin">'; 200 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; 201 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1); 202 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; 203 $morehtmlref .= '</form>'; 204 } else { 205 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 206 } 207 } else { 208 if (!empty($object->fk_project)) { 209 $proj = new Project($db); 210 $proj->fetch($object->fk_project); 211 $morehtmlref .= $proj->getNomUrl(1); 212 } else { 213 $morehtmlref .= ''; 214 } 215 } 216} 217 218$morehtmlref .= '</div>'; 219 220$linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> '; 221 222dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); 223 224print dol_get_fiche_end(); 225 226print '<br>'; 227 228 229if (!empty($object->id)) { 230 $param = '&id='.$object->id; 231 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { 232 $param .= '&contextpage='.$contextpage; 233 } 234 if ($limit > 0 && $limit != $conf->liste_limit) { 235 $param .= '&limit='.$limit; 236 } 237 238 $morehtmlright = ''; 239 240 $messagingUrl = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id; 241 $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1); 242 $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id; 243 $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-list-alt imgforviewmode', $messagingUrl, '', 1, array('morecss'=>'btnTitleSelected')); 244 245 // Show link to add a message (if read and not closed) 246 $btnstatus = $object->fk_statut < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage"; 247 $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init'; 248 $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus); 249 250 // Show link to add event (if read and not closed) 251 $btnstatus = $object->fk_statut < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage"; 252 $url = dol_buildpath('/comm/action/card.php', 1).'?action=create&datep='.date('YmdHi').'&origin=ticket&originid='.$object->id.'&projectid='.$object->fk_project.'&backtopage='.urlencode($_SERVER["PHP_SELF"]); 253 $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', $btnstatus); 254 255 print_barre_liste($langs->trans("ActionsOnTicket"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1); 256 257 // List of all actions 258 $filters = array(); 259 $filters['search_agenda_label'] = $search_agenda_label; 260 show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder); 261} 262 263// End of page 264llxFooter(); 265$db->close(); 266