api_get_path(WEB_CODE_PATH).'ticket/tickets.php', 'name' => get_lang('My tickets'), ]; $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Ticket details')]; $disableReponseButtons = ''; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; if (!isset($_REQUEST['ticket_id'])) { header('Location: '.api_get_path(WEB_CODE_PATH).'ticket/tickets.php'); exit; } $userInfo = api_get_user_info(); $ticket_id = (int) $_REQUEST['ticket_id']; $ticket = TicketManager::get_ticket_detail_by_id($ticket_id); if (empty($ticket)) { api_not_allowed(true); } $projectId = (int) $ticket['ticket']['project_id']; $userIsAllowInProject = true; //TicketManager::userIsAllowInProject($projectId); $allowEdition = $ticket['ticket']['assigned_last_user'] == $user_id || $ticket['ticket']['sys_insert_user_id'] == $user_id || $isAdmin; if (false === $userIsAllowInProject) { // make sure it's either a user assigned to this ticket, or the reporter, or and admin if (false === $allowEdition) { api_not_allowed(true); } } if (isset($_GET['action'])) { $action = $_GET['action']; switch ($action) { case 'subscribe': TicketManager::subscribeUserToTicket($ticket_id, $user_id); Display::addFlash(Display::return_message(get_lang('Subscribed successfully'))); header('Location: '.api_get_self().'?ticket_id='.$ticket_id); exit; case 'unsubscribe': TicketManager::unsubscribeUserFromTicket($ticket_id, $user_id); Display::addFlash(Display::return_message(get_lang('Unsubscribed successfully'))); header('Location: '.api_get_self().'?ticket_id='.$ticket_id); exit; } } $title = 'Ticket #'.$ticket['ticket']['code']; if ($allowEdition && isset($_REQUEST['close'])) { TicketManager::close_ticket($ticket_id, $user_id); $ticket['ticket']['status_id'] = TicketManager::STATUS_CLOSE; $ticket['ticket']['status'] = get_lang('Closed'); } $messages = $ticket['messages']; $counter = 1; $messageToShow = ''; $formToShow = ''; foreach ($messages as $message) { $date = Display::url( date_to_str_ago($message['sys_insert_datetime']), '#', ['title' => api_get_local_time($message['sys_insert_datetime']), 'class' => 'boot-tooltip'] ); $receivedMessage = ''; if (!empty($message['subject'])) { $receivedMessage = ''.get_lang('Subject').': '.Security::remove_XSS($message['subject']).'
'; } if (!empty($message['message'])) { $receivedMessage = ''.get_lang('Message').':
'.Security::remove_XSS($message['message']).'
'; } $attachmentLinks = ''; if (isset($message['attachments'])) { $attributeClass = [ 'class' => 'attachment-link', ]; foreach ($message['attachments'] as $attach) { $attachmentLinks .= Display::tag('div', $attach, $attributeClass); } } $entireMessage = $receivedMessage.$attachmentLinks; $counterLink = Display::url('#'.$counter, api_get_self().'?ticket_id='.$ticket_id.'#note-'.$counter); $messageToShow .= '

' .sprintf( get_lang('Updated by %s'), $message['user_info']['complete_name_with_message_link'] ); $messageToShow .= ' '.$date.' '.$counterLink.'

'; $messageToShow .= '
'; if (!empty($entireMessage)) { $messageToShow .= Display::div( $entireMessage, ['class' => 'well'] ); } $counter++; } $subject = get_lang('Re:').': '.Security::remove_XSS($ticket['ticket']['subject']); if ($allowEdition && TicketManager::STATUS_FORWARDED != $ticket['ticket']['status_id'] && TicketManager::STATUS_CLOSE != $ticket['ticket']['status_id'] ) { $form = getForm($ticket['ticket']); $formToShow = $form->returnForm(); if ($form->validate()) { $ticket_id = (int) $_POST['ticket_id']; $messageToSend = ''; $message = isset($_POST['confirmation']) ? true : false; $file_attachments = $_FILES; if ($isAdmin) { $oldUserId = $ticket['ticket']['assigned_last_user']; if (isset($_POST['assigned_last_user']) && !empty($_POST['assigned_last_user']) && $_POST['assigned_last_user'] != $oldUserId ) { TicketManager::assignTicketToUser( $ticket_id, $_POST['assigned_last_user'] ); $oldUserName = '-'; if (!empty($oldUserId)) { $oldUserInfo = api_get_user_info($oldUserId); $oldUserName = $oldUserInfo['complete_name_with_message_link']; } $userCompleteName = '-'; if (!empty($_POST['assigned_last_user'])) { $userInfo = api_get_user_info( $_POST['assigned_last_user'] ); $userCompleteName = $userInfo['complete_name_with_message_link']; } $messageToSend .= sprintf( get_lang('Assignee changed from %s to %s'), $oldUserName, $userCompleteName ).'
'; } TicketManager::updateTicket( [ 'priority_id' => (int) $_POST['priority_id'], 'status_id' => (int) $_POST['status_id'], ], $ticket_id, api_get_user_id() ); if ($_POST['priority_id'] != $ticket['ticket']['priority_id']) { $newPriority = TicketManager::getPriority( $_POST['priority_id'] ); $newPriorityTitle = '-'; if ($newPriority) { $newPriorityTitle = $newPriority->getTitle(); } $oldPriority = TicketManager::getPriority( $ticket['ticket']['priority_id'] ); $oldPriorityTitle = '-'; if ($oldPriority) { $oldPriorityTitle = $oldPriority->getTitle(); } $messageToSend .= sprintf( get_lang('Priority changed from %s to %s'), $oldPriorityTitle, $newPriorityTitle ).'
'; } if ($_POST['status_id'] != $ticket['ticket']['status_id']) { $newStatus = TicketManager::getStatus( $_POST['status_id'] ); $newTitle = '-'; if ($newStatus) { $newTitle = $newStatus->getTitle(); } $oldStatus = TicketManager::getStatus( $ticket['ticket']['status_id'] ); $oldStatusTitle = '-'; if ($oldStatus) { $oldStatusTitle = $oldStatus->getTitle(); } $messageToSend .= sprintf( get_lang('Status changed from %s to %s'), $oldStatusTitle, $newTitle ).'
'; } } $messageToSend .= $_POST['content']; TicketManager::insertMessage( $ticket_id, $_POST['subject'], $messageToSend, $file_attachments, $user_id, 'NOL', $message ); TicketManager::sendNotification( $ticket_id, get_lang('TicketUpdate successful'), $messageToSend ); Display::addFlash(Display::return_message(get_lang('Saved.'))); header('Location:'.api_get_self().'?ticket_id='.$ticket_id); exit; } } $isSubscribed = TicketManager::isUserSubscribedToTicket($ticket_id, $user_id); $subscribeAction = ''; if ($isSubscribed) { $subscribeAction = Display::url( Display::getMdiIcon( 'email-alert', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Unsubscribe') ), api_get_self().'?ticket_id='.$ticket_id.'&action=unsubscribe', ['title' => get_lang('Unsubscribe')] ); } else { $subscribeAction = Display::url( Display::getMdiIcon( 'email-outline', 'ch-tool-icon-disabled', null, ICON_SIZE_MEDIUM, get_lang('Subscribe') ), api_get_self().'?ticket_id='.$ticket_id.'&action=subscribe', ['title' => get_lang('Subscribe')] ); } $actions = [ Display::url( Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Tickets')), api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId ), $subscribeAction, ]; Display::display_header(); echo Display::toolbarAction('ticket', $actions); $bold = ''; if (TicketManager::STATUS_CLOSE == $ticket['ticket']['status_id']) { $bold = 'style = "font-weight: bold;"'; } $senderData = get_lang('added by').' '.$ticket['user']['complete_name_with_message_link']; echo '
'; echo ''; if (!empty($ticket['ticket']['assigned_last_user'])) { $assignedUser = api_get_user_info($ticket['ticket']['assigned_last_user']); echo ''; } else { echo ''; } if (null != $ticket['ticket']['course_url']) { if (!empty($ticket['ticket']['session_id'])) { $sessionInfo = api_get_session_info($ticket['ticket']['session_id']); echo ''; } echo ''; if ('true' === api_get_setting('lp.ticket_lp_quiz_info_add')) { if (!empty($ticket['ticket']['exercise_url'])) { echo ''; } if (!empty($ticket['ticket']['lp_id'])) { echo ''; } } } echo ' '; echo '

'.$title.'

'.Security::remove_XSS($ticket['ticket']['subject']).'

'.$senderData.' '. get_lang('Created').' '. Display::url( date_to_str_ago($ticket['ticket']['start_date_from_db']), '#', ['title' => $ticket['ticket']['start_date'], 'class' => 'boot-tooltip'] ).'. '. get_lang('TicketUpdate successful').' '. Display::url( date_to_str_ago($ticket['ticket']['sys_lastedit_datetime_from_db']), '#', ['title' => $ticket['ticket']['sys_lastedit_datetime'], 'class' => 'boot-tooltip'] ).'

'.get_lang('Category').': '.$ticket['ticket']['title'].'

'.get_lang('Status').': '.$ticket['ticket']['status'].'

'.get_lang('Priority').': '.$ticket['ticket']['priority'].'

'.get_lang('Assigned to').': '.$assignedUser['complete_name_with_message_link'].'

'.get_lang('Assigned to').': -

'.get_lang('Session').': '.$sessionInfo['name'].'
'.get_lang('Course').': '.$ticket['ticket']['course_url'].'
'.get_lang('Exercise').': '.$ticket['ticket']['exercise_url'].'
'.get_lang('LearningPath').': '.$ticket['ticket']['lp_url'].'
'.get_lang('Description').':
'.Security::remove_XSS($ticket['ticket']['message']).'
'; echo $messageToShow; echo '
'; echo $formToShow; Display::display_footer(); /** * @param array $ticket * * @return FormValidator */ function getForm($ticket) { $isAdmin = api_is_platform_admin(); global $subject; $form = new FormValidator( 'send_ticket', 'POST', api_get_self().'?ticket_id='.$ticket['id'], '', [ 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal', ] ); if ($isAdmin) { $statusList = TicketManager::getStatusList(); $form->addSelect( 'status_id', get_lang('Status'), $statusList ); $priorityList = TicketManager::getPriorityList(); $form->addSelect( 'priority_id', get_lang('Priority'), $priorityList, [ 'id' => 'priority_id', 'for' => 'priority_id', ] ); $form->addSelectAjax( 'assigned_last_user', get_lang('Assign'), [], ['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like'] ); $form->setDefaults( [ 'priority_id' => $ticket['priority_id'], 'status_id' => $ticket['status_id'], 'assigned_last_user' => $ticket['assigned_last_user'], ] ); } $form->addElement( 'text', 'subject', get_lang('Subject'), [ 'for' => 'subject', 'value' => $subject, 'style' => 'width: 540px;', ] ); $form->addElement('hidden', 'ticket_id', $ticket['id']); $form->addHtmlEditor( 'content', get_lang('Message'), false, false, [ 'ToolbarSet' => 'Profile', 'Width' => '550', 'Height' => '250', ] ); if ($isAdmin) { $form->addElement( 'checkbox', 'confirmation', null, get_lang('Request confirmation') ); } $form->addElement('file', 'attach_1', get_lang('Files attachments')); $form->addLabel( '', '
' ); $form->addLabel( '', '' .get_lang('Add one more file') .'(' .sprintf( get_lang('Maximun file size: %s'), format_file_size((int) api_get_setting('message_max_upload_filesize')) ).')' ); $form->addElement('html', '
'); $form->addButtonSend(get_lang('Send message')); return $form; }