2019-09-11 23:30:09 +02:00
< ? php
/* Copyright ( C ) - 2013 - 2016 Jean - François FERRY < hello @ librethic . io >
*
* 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 , see < http :// www . gnu . org / licenses />.
*/
/**
2019-09-30 17:08:57 +02:00
* \file htdocs / ticket / messaging . php
2019-09-11 23:30:09 +02:00
* \ingroup ticket
* \brief Page with events on ticket
*/
require '../main.inc.php' ;
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/ticket/class/actions_ticket.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formticket.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php' ;
require_once DOL_DOCUMENT_ROOT . " /core/lib/company.lib.php " ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2019-09-11 23:30:09 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'companies' , 'other' , 'ticket' ));
// Get parameters
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
$track_id = GETPOST ( 'track_id' , 'alpha' , 3 );
$socid = GETPOST ( 'socid' , 'int' );
$action = GETPOST ( 'action' , 'aZ09' );
2019-11-13 19:35:39 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-12-03 10:13:13 +01:00
$sortfield = GETPOST ( " sortfield " , " aZ09comma " );
$sortorder = GETPOST ( " sortorder " , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2019-09-11 23:30:09 +02:00
$page = is_numeric ( $page ) ? $page : 0 ;
$page = $page == - 1 ? 0 : $page ;
2021-02-26 13:27:00 +01:00
if ( ! $sortfield ) {
$sortfield = " a.datep,a.id " ;
}
if ( ! $sortorder ) {
$sortorder = " desc " ;
}
2019-11-13 19:35:39 +01:00
$offset = $limit * $page ;
2019-09-11 23:30:09 +02:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-26 13:27:00 +01:00
if ( GETPOST ( 'actioncode' , 'array' )) {
2019-11-13 19:35:39 +01:00
$actioncode = GETPOST ( 'actioncode' , 'array' , 3 );
2021-02-26 13:27:00 +01:00
if ( ! count ( $actioncode )) {
$actioncode = '0' ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$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 ));
2019-09-11 23:30:09 +02:00
}
2019-11-13 19:35:39 +01:00
$search_agenda_label = GETPOST ( 'search_agenda_label' );
2019-09-11 23:30:09 +02:00
$object = new Ticket ( $db );
$object -> fetch ( $id , $ref , $track_id );
$extrafields = new ExtraFields ( $db );
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2019-09-11 23:30:09 +02:00
if ( ! $action ) {
$action = 'view' ;
}
2021-05-18 01:58:54 +02:00
$permissiontoadd = $user -> rights -> ticket -> write ;
2019-09-11 23:30:09 +02:00
// Security check
$id = GETPOST ( " id " , 'int' );
2021-05-18 01:58:54 +02:00
if ( $user -> socid > 0 ) $socid = $user -> socid ;
$result = restrictedArea ( $user , 'ticket' , $object -> id , '' );
2019-09-11 23:30:09 +02:00
// restrict access for externals users
2021-02-26 13:27:00 +01:00
if ( $user -> socid > 0 && ( $object -> fk_soc != $user -> socid )) {
2019-09-11 23:30:09 +02:00
accessforbidden ();
}
// or for unauthorized internals users
2021-05-11 08:15:44 +02:00
if ( ! $user -> socid && ( ! empty ( $conf -> global -> TICKET_LIMIT_VIEW_ASSIGNED_ONLY ) && $object -> fk_user_assign != $user -> id ) && ! $user -> rights -> ticket -> manage ) {
2019-09-11 23:30:09 +02:00
accessforbidden ();
}
/*
* Actions
*/
2019-11-13 19:35:39 +01:00
$parameters = array ( 'id' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 13:27:00 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2019-09-11 23:30:09 +02:00
2021-02-26 13:27:00 +01:00
if ( empty ( $reshook )) {
2019-09-16 13:56:07 +02:00
// Set view style
$_SESSION [ 'ticket-view-type' ] = " messaging " ;
}
2019-09-11 23:30:09 +02:00
// Purge search criteria
2021-02-26 13:27:00 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All test are required to be compatible with all browsers
2019-11-13 19:35:39 +01:00
$actioncode = '' ;
$search_agenda_label = '' ;
2019-09-11 23:30:09 +02:00
}
/*
* View
*/
$form = new Form ( $db );
$userstat = new User ( $db );
$formticket = new FormTicket ( $db );
2019-11-13 19:35:39 +01:00
$title = $langs -> trans ( " Ticket " ) . ' - ' . $object -> ref . ' ' . $object -> name ;
2021-02-26 13:27:00 +01:00
if ( ! empty ( $conf -> global -> MAIN_HTML_TITLE ) && preg_match ( '/ticketnameonly/' , $conf -> global -> MAIN_HTML_TITLE ) && $object -> name ) {
$title = $object -> ref . ' ' . $object -> name . ' - ' . $langs -> trans ( " Info " );
}
2019-09-11 23:30:09 +02:00
$help_url = 'FR:DocumentationModuleTicket' ;
llxHeader ( '' , $title , $help_url );
if ( $socid > 0 ) {
2020-10-31 14:32:18 +01:00
$object -> fetch_thirdparty ();
$head = societe_prepare_head ( $object -> thirdparty );
2019-09-11 23:30:09 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_head ( $head , 'ticket' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
2019-09-11 23:30:09 +02:00
2020-10-31 14:32:18 +01:00
dol_banner_tab ( $object -> thirdparty , 'socid' , '' , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
2019-09-11 23:30:09 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2019-09-11 23:30:09 +02:00
}
2021-05-11 08:15:44 +02:00
if ( ! $user -> socid && ! empty ( $conf -> global -> TICKET_LIMIT_VIEW_ASSIGNED_ONLY )) {
2020-10-31 14:32:18 +01:00
$object -> next_prev_filter = " te.fk_user_assign = ' " . $user -> id . " ' " ;
2019-09-11 23:30:09 +02:00
} elseif ( $user -> socid > 0 ) {
2020-10-31 14:32:18 +01:00
$object -> next_prev_filter = " te.fk_soc = ' " . $user -> socid . " ' " ;
2019-09-11 23:30:09 +02:00
}
$head = ticket_prepare_head ( $object );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'tabTicketLogs' , $langs -> trans ( " Ticket " ), 0 , 'ticket' );
2019-09-11 23:30:09 +02:00
2019-11-13 19:35:39 +01:00
$morehtmlref = '<div class="refidno">' ;
$morehtmlref .= $object -> subject ;
2019-09-11 23:30:09 +02:00
// Author
if ( $object -> fk_user_create > 0 ) {
2019-11-13 19:35:39 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( " CreatedBy " ) . ' : ' ;
2019-09-11 23:30:09 +02:00
$langs -> load ( " users " );
$fuser = new User ( $db );
$fuser -> fetch ( $object -> fk_user_create );
2022-01-02 18:57:16 +01:00
$morehtmlref .= $fuser -> getNomUrl ( - 1 );
2019-09-11 23:30:09 +02:00
}
if ( ! empty ( $object -> origin_email )) {
2020-04-10 10:59:32 +02:00
$morehtmlref .= '<br>' . $langs -> trans ( " CreatedBy " ) . ' : ' ;
$morehtmlref .= $object -> origin_email . ' <small>(' . $langs -> trans ( " TicketEmailOriginIssuer " ) . ')</small>' ;
2019-09-11 23:30:09 +02:00
}
// Thirdparty
2021-02-26 13:27:00 +01:00
if ( ! empty ( $conf -> societe -> enabled )) {
2020-04-10 10:59:32 +02:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' );
2019-10-31 20:46:31 +01:00
/* if ( $action != 'editcustomer' && $object -> fk_statut < 8 && ! $user -> socid && $user -> rights -> ticket -> write ) {
2021-09-27 12:24:01 +02:00
$morehtmlref .= '<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&token=' . newToken () . '&track_id=' . $object -> track_id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'Edit' ), 1 ) . '</a>' ;
2019-09-11 23:30:09 +02:00
} */
2020-04-10 10:59:32 +02:00
$morehtmlref .= ' : ' ;
2019-09-11 23:30:09 +02:00
if ( $action == 'editcustomer' ) {
2020-04-10 10:59:32 +02:00
$morehtmlref .= $form -> form_thirdparty ( $url_page_current . '?track_id=' . $object -> track_id , $object -> socid , 'editcustomer' , '' , 1 , 0 , 0 , array (), 1 );
2019-09-11 23:30:09 +02:00
} else {
2020-04-10 10:59:32 +02:00
$morehtmlref .= $form -> form_thirdparty ( $url_page_current . '?track_id=' . $object -> track_id , $object -> socid , 'none' , '' , 1 , 0 , 0 , array (), 1 );
2019-09-11 23:30:09 +02:00
}
}
// Project
2021-02-26 13:27:00 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2019-09-11 23:30:09 +02:00
$langs -> load ( " projects " );
2020-04-10 10:59:32 +02:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' );
2021-02-26 13:27:00 +01:00
if ( $user -> rights -> ticket -> write ) {
2019-10-26 20:58:29 +02:00
if ( $action != 'classify' ) {
2021-09-18 22:09:55 +02:00
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
2020-04-10 10:59:32 +02:00
$morehtmlref .= ' : ' ;
2019-10-26 20:58:29 +02:00
}
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
2020-04-10 10:59:32 +02:00
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , 0 , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
2019-10-26 20:58:29 +02:00
} else {
2020-04-10 10:59:32 +02:00
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
2019-10-26 20:58:29 +02:00
}
2019-09-11 23:30:09 +02:00
} else {
2020-04-10 10:59:32 +02:00
if ( ! empty ( $object -> fk_project )) {
2022-01-15 23:04:56 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2019-09-11 23:30:09 +02:00
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
2020-04-10 10:59:32 +02:00
$morehtmlref .= $proj -> getNomUrl ( 1 );
2019-09-11 23:30:09 +02:00
} else {
2020-04-10 10:59:32 +02:00
$morehtmlref .= '' ;
2019-09-11 23:30:09 +02:00
}
}
}
2020-04-10 10:59:32 +02:00
$morehtmlref .= '</div>' ;
2019-09-11 23:30:09 +02:00
2021-09-18 19:34:46 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/ticket/list.php"><strong>' . $langs -> trans ( " BackToList " ) . '</strong></a> ' ;
2019-09-11 23:30:09 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , ( $user -> socid ? 0 : 1 ), 'ref' , 'ref' , $morehtmlref , '' , 0 , '' , '' , 1 );
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2019-09-11 23:30:09 +02:00
print '<br>' ;
2021-02-26 13:27:00 +01:00
if ( ! empty ( $object -> id )) {
2019-11-13 19:35:39 +01:00
$param = '&id=' . $object -> id ;
2021-02-26 13:27:00 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . $contextpage ;
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . $limit ;
}
2019-09-11 23:30:09 +02:00
2020-10-31 14:32:18 +01:00
$morehtmlright = '' ;
2019-09-12 21:17:48 +02:00
2020-10-31 14:32:18 +01:00
$messagingUrl = DOL_URL_ROOT . '/ticket/messaging.php?track_id=' . $object -> track_id ;
$morehtmlright .= dolGetButtonTitle ( $langs -> trans ( 'ShowAsConversation' ), '' , 'fa fa-comments imgforviewmode' , $messagingUrl , '' , 1 , array ( 'morecss' => 'btnTitleSelected' ));
2019-11-13 19:35:39 +01:00
$messagingUrl = DOL_URL_ROOT . '/ticket/agenda.php?track_id=' . $object -> track_id ;
2019-09-30 17:08:57 +02:00
$morehtmlright .= dolGetButtonTitle ( $langs -> trans ( 'MessageListViewType' ), '' , 'fa fa-list-alt imgforviewmode' , $messagingUrl , '' , 1 );
2019-09-12 21:17:48 +02:00
2020-08-02 00:52:01 +02:00
2019-09-16 13:56:07 +02:00
// Show link to add a message (if read and not closed)
$btnstatus = $object -> fk_statut < Ticket :: STATUS_CLOSED && $action != " presend " && $action != " presend_addmessage " ;
2019-11-13 19:35:39 +01:00
$url = 'card.php?track_id=' . $object -> track_id . '&action=presend_addmessage&mode=init' ;
2019-09-30 17:08:57 +02:00
$morehtmlright .= dolGetButtonTitle ( $langs -> trans ( 'TicketAddMessage' ), '' , 'fa fa-comment-dots' , $url , 'add-new-ticket-title-button' , $btnstatus );
2019-09-12 21:17:48 +02:00
2019-09-16 13:56:07 +02:00
// Show link to add event (if read and not closed)
$btnstatus = $object -> fk_statut < Ticket :: STATUS_CLOSED && $action != " presend " && $action != " presend_addmessage " ;
2021-09-18 19:34:46 +02:00
$url = DOL_URL_ROOT . '/comm/action/card.php?action=create&datep=' . date ( 'YmdHi' ) . '&origin=ticket&originid=' . $object -> id . '&projectid=' . $object -> fk_project . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?track_id=' . $object -> track_id );
2019-09-30 17:08:57 +02:00
$morehtmlright .= dolGetButtonTitle ( $langs -> trans ( 'AddAction' ), '' , 'fa fa-plus-circle' , $url , 'add-new-ticket-even-button' , $btnstatus );
2019-09-12 21:17:48 +02:00
print_barre_liste ( $langs -> trans ( " ActionsOnTicket " ), 0 , $_SERVER [ " PHP_SELF " ], '' , $sortfield , $sortorder , '' , 0 , - 1 , '' , 0 , $morehtmlright , '' , 0 , 1 , 1 );
2019-09-11 23:30:09 +02:00
// List of all actions
2019-11-13 19:35:39 +01:00
$filters = array ();
$filters [ 'search_agenda_label' ] = $search_agenda_label ;
2020-10-31 14:32:18 +01:00
show_ticket_messaging ( $conf , $langs , $db , $object , null , 0 , $actioncode , '' , $filters , $sortfield , $sortorder );
2019-09-11 23:30:09 +02:00
}
// End of page
llxFooter ();
$db -> close ();