api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
'name' => get_lang('MyTickets')
);
$interbreadcrumb[] = array('url' => '#', 'name' => get_lang('TicketDetail'));
$disableReponseButtons = '';
$htmlHeadXtra[] = '';
$htmlHeadXtra[] = '';
$ticket_id = $_GET['ticket_id'];
$ticket = TicketManager::get_ticket_detail_by_id($ticket_id);
if (!isset($ticket['ticket'])) {
api_not_allowed();
}
if (!isset($_GET['ticket_id'])) {
header('Location: '.api_get_path(WEB_CODE_PATH).'ticket/tickets.php');
exit;
}
if (isset($_POST['response'])) {
if ($user_id == $ticket['ticket']['assigned_last_user'] || api_is_platform_admin()) {
$response = $_POST['response'] === '1' ? true : false;
$newStatus = TicketManager::STATUS_PENDING;
if ($response) {
$newStatus = TicketManager::STATUS_CLOSE;
}
TicketManager::update_ticket_status(
TicketManager::getStatusIdFromCode($newStatus),
$ticket_id,
$user_id
);
Display::addFlash(Display::return_message(get_lang('Updated')));
header("Location:".api_get_self()."?ticket_id=".$ticket_id);
exit;
}
}
$title = 'Ticket #'.$ticket['ticket']['code'];
if (!isset($_POST['compose'])) {
if (isset($_REQUEST['close'])) {
TicketManager::close_ticket($_REQUEST['ticket_id'], $user_id);
$ticket['ticket']['status_id'] = TicketManager::STATUS_CLOSE;
$ticket['ticket']['status'] = get_lang('Closed');
}
Display::display_header();
$projectId = $ticket['ticket']['project_id'];
echo '
';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId
);
echo '
';
$bold = '';
if ($ticket['ticket']['status_id'] == TicketManager::STATUS_CLOSE) {
$bold = 'style = "font-weight: bold;"';
echo "";
}
if ($isAdmin) {
$senderData = get_lang('AddedBy').' '.$ticket['ticket']['user_url'].' ('.$ticket['usuario']['username'].').';
} else {
$senderData = get_lang('AddedBy').' '.$ticket['usuario']['complete_name'].' ('.$ticket['usuario']['username'].').';
}
echo '
'.$title.'
'.$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('TicketUpdated').' '.
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']['name'].' |
'.get_lang('Status').': '.$ticket['ticket']['status'].' |
' . get_lang('Priority').': '.$ticket['ticket']['priority'].' |
';
if (!empty($ticket['ticket']['assigned_last_user'])) {
$assignedUser = api_get_user_info($ticket['ticket']['assigned_last_user']);
echo '
' . get_lang('AssignedTo').': '.$assignedUser['complete_name'].' |
';
} else {
echo '
' . get_lang('AssignedTo').': - |
';
}
if ($ticket['ticket']['course_url'] != null) {
if (!empty($ticket['ticket']['session_id'])) {
$sessionInfo = api_get_session_info($ticket['ticket']['session_id']);
echo '
' . get_lang('Session').': '.$sessionInfo['name'].' |
|
|
';
}
echo '
' . get_lang('Course').': '.$ticket['ticket']['course_url'].' |
|
|
';
}
echo '
' . get_lang('Description').':
'.$ticket['ticket']['message'].'
|
';
echo '
';
$messages = $ticket['messages'];
$counter = 1;
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').': '.$message['subject'].'
';
}
if (!empty($message['message'])) {
$receivedMessage = ''.get_lang('Message').':
'.$message['message'].'
';
}
$attachmentLinks = '';
if (isset($message['attachments'])) {
$attributeClass = array(
'class' => 'attachment-link'
);
foreach ($message['attachments'] as $attach) {
$attachmentLinks .= Display::tag('div', $attach['attachment_link'], $attributeClass);
}
}
$entireMessage = $receivedMessage.$attachmentLinks;
$counterLink = Display::url('#'.$counter, api_get_self().'?ticket_id='.$ticket_id.'#note-'.$counter);
echo ' '.sprintf(get_lang('UpdatedByX'), $message['user_created']).' '.$date.
' '.$counterLink.'
';
echo '
';
if (!empty($entireMessage)) {
echo Display::div(
$entireMessage,
['class' => 'well']
);
}
$counter++;
}
$subject = get_lang('ReplyShort').': '.$ticket['ticket']['subject'];
if ($ticket['ticket']['status_id'] != TicketManager::STATUS_FORWARDED &&
$ticket['ticket']['status_id'] != TicketManager::STATUS_CLOSE
) {
if (!$isAdmin && $ticket['ticket']['status_id'] != TicketManager::STATUS_UNCONFIRMED) {
show_form_send_message($ticket['ticket']);
} else {
if (
$ticket['ticket']['assigned_last_user'] == $user_id ||
$ticket['ticket']['sys_insert_user_id'] == $user_id ||
$isAdmin
) {
show_form_send_message($ticket['ticket']);
}
}
}
Display::display_footer();
} else {
$ticket_id = $_POST['ticket_id'];
$content = $_POST['content'];
$messageToSend = '';
$subject = $_POST['subject'];
$message = isset($_POST['confirmation']) ? true : false;
$file_attachments = $_FILES;
$user_id = api_get_user_id();
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'];
}
$userCompleteName = '-';
if (!empty($_POST['assigned_last_user'])) {
$userInfo = api_get_user_info($_POST['assigned_last_user']);
$userCompleteName = $userInfo['complete_name'];
}
$messageToSend .= sprintf(
get_lang('AssignedChangeFromXToY'),
$oldUserName,
$userCompleteName
).'
';
}
TicketManager::updateTicket(
[
'priority_id' => $_POST['priority_id'],
'status_id' => $_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->getName();
}
$oldPriority = TicketManager::getPriority($ticket['ticket']['priority_id']);
$oldPriorityTitle = '-';
if ($oldPriority) {
$oldPriorityTitle = $oldPriority->getName();
}
$messageToSend .= sprintf(
get_lang('PriorityChangeFromXToY'),
$oldPriorityTitle,
$newPriorityTitle
).'
';
}
if ($_POST['status_id'] != $ticket['ticket']['status_id']) {
$newStatus = TicketManager::getStatus($_POST['status_id']);
$newTitle = '-';
if ($newStatus) {
$newTitle = $newStatus->getName();
}
$oldStatus = TicketManager::getStatus($ticket['ticket']['status_id']);
$oldStatusTitle = '-';
if ($oldStatus) {
$oldStatusTitle = $oldStatus->getName();
}
$messageToSend .= sprintf(
get_lang('StatusChangeFromXToY'),
$oldStatusTitle,
$newTitle
).'
';
}
}
$messageToSend .= $content;
TicketManager::insertMessage(
$ticket_id,
$subject,
$messageToSend,
$file_attachments,
$user_id,
'NOL',
$message
);
TicketManager::sendNotification(
$ticket_id,
get_lang('TicketUpdated'),
$messageToSend
);
Display::addFlash(Display::return_message(get_lang('Saved')));
header("Location:".api_get_self()."?ticket_id=".$ticket_id);
exit;
}
/**
* @param array $ticket
*/
function show_form_send_message($ticket)
{
global $isAdmin;
global $subject;
$form = new FormValidator(
'send_ticket',
'POST',
api_get_self().'?ticket_id='.$ticket['id'],
'',
array(
'enctype' => 'multipart/form-data',
'class' => 'form-horizontal'
)
);
if ($isAdmin) {
$statusList = TicketManager::getStatusList();
$form->addElement(
'select',
'status_id',
get_lang('Status'),
$statusList
);
$priorityList = TicketManager::getPriorityList();
$form->addElement(
'select',
'priority_id',
get_lang('Priority'),
$priorityList,
array(
'id' => 'priority_id',
'for' => 'priority_id'
)
);
$form->addSelectAjax(
'assigned_last_user',
get_lang('Assign'),
null,
['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'),
array(
'for' => 'subject',
'value' => $subject,
'style' => 'width: 540px;'
)
);
$form->addElement('hidden', 'ticket_id', $ticket['id']);
$form->addHtmlEditor(
'content',
get_lang('Message'),
false,
false,
array(
'ToolbarSet' => 'Profile',
'Width' => '550',
'Height' => '250'
)
);
if ($isAdmin) {
$form->addElement(
'checkbox',
'confirmation',
null,
get_lang('RequestConfirmation')
);
}
$form->addElement('file', 'attach_1', get_lang('FilesAttachment'));
$form->addLabel(
'',
''
);
$form->addLabel(
'',
'
' . get_lang('AddOneMoreFile').'
('.sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))).')
');
$form->addElement('html', '
');
$form->addElement(
'button',
'compose',
get_lang('SendMessage'),
null,
null,
null,
'btn btn-primary'
);
$form->display();
}