ticket_details.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.plugin.ticket
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. api_block_anonymous_users();
  9. $user_id = api_get_user_id();
  10. $isAdmin = api_is_platform_admin();
  11. $interbreadcrumb[] = [
  12. 'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
  13. 'name' => get_lang('MyTickets'),
  14. ];
  15. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('TicketDetail')];
  16. $disableReponseButtons = '';
  17. $htmlHeadXtra[] = '<script>
  18. $(function() {
  19. $("#dialog-form").dialog({
  20. autoOpen: false,
  21. height: 450,
  22. width: 600,
  23. modal: true,
  24. buttons: {
  25. '.get_lang('Accept').': function(){
  26. $("#frmResponsable").submit()
  27. },
  28. '.ucfirst(get_lang('Close')).': function() {
  29. $(this).dialog("close");
  30. }
  31. }
  32. });
  33. $("a#assign").click(function () {
  34. $( "#dialog-form" ).dialog( "open" );
  35. });
  36. $(".responseyes").click(function () {
  37. if(!confirm("'.get_lang('AreYouSure').' : '.strtoupper(get_lang('Yes')).'. '.get_lang('IfYouAreSureTheTicketWillBeClosed').'")){
  38. return false;
  39. }
  40. });
  41. $(".responseno").click(function () {
  42. if(!confirm("'.get_lang('AreYouSure').' : '.strtoupper(get_lang('No')).'")){
  43. return false;
  44. }
  45. });
  46. '.$disableReponseButtons.'
  47. });
  48. var counter_image = 1;
  49. function remove_image_form(element_id) {
  50. $("#" + element_id).remove();
  51. counter_image = counter_image - 1;
  52. $("#link-more-attach").css("display", "block");
  53. }
  54. function add_image_form() {
  55. // Multiple filepaths for image form
  56. var filepaths = $("#filepaths");
  57. var new_elem, input_file, link_remove, img_remove, new_filepath_id;
  58. if ($("#filepath_"+counter_image)) {
  59. counter_image = counter_image + 1;
  60. } else {
  61. counter_image = counter_image;
  62. }
  63. new_elem = "filepath_"+counter_image;
  64. $("<div/>", {
  65. id: new_elem,
  66. class: "controls"
  67. }).appendTo(filepaths);
  68. input_file = $("<input/>", {
  69. type: "file",
  70. name: "attach_" + counter_image,
  71. size: 20
  72. });
  73. link_remove = $("<a/>", {
  74. onclick: "remove_image_form(\'" + new_elem + "\')",
  75. style: "cursor: pointer"
  76. });
  77. img_remove = $("<img/>", {
  78. src: "'.Display::returnIconPath('delete.png').'"
  79. });
  80. new_filepath_id = $("#filepath_" + counter_image);
  81. new_filepath_id.append(input_file, link_remove.append(img_remove));
  82. if (counter_image === 6) {
  83. var link_attach = $("#link-more-attach");
  84. if (link_attach) {
  85. $(link_attach).css("display", "none");
  86. }
  87. }
  88. }
  89. </script>';
  90. $htmlHeadXtra[] = '<style>
  91. .attachment-link {
  92. margin: 12px;
  93. }
  94. #link-more-attach {
  95. color: white;
  96. cursor: pointer;
  97. width: 120px;
  98. }
  99. </style>';
  100. $ticket_id = (int) $_REQUEST['ticket_id'];
  101. $ticket = TicketManager::get_ticket_detail_by_id($ticket_id);
  102. if (!isset($ticket['ticket']) ||
  103. // make sure it's either a user assigned to this ticket, or the reporter, or and admin
  104. !($ticket['ticket']['assigned_last_user'] == $user_id ||
  105. $ticket['ticket']['sys_insert_user_id'] == $user_id ||
  106. $isAdmin)
  107. ) {
  108. api_not_allowed(true);
  109. }
  110. if (!isset($_REQUEST['ticket_id'])) {
  111. header('Location: '.api_get_path(WEB_CODE_PATH).'ticket/tickets.php');
  112. exit;
  113. }
  114. /*if (isset($_POST['response'])) {
  115. if ($user_id == $ticket['ticket']['assigned_last_user'] || api_is_platform_admin()) {
  116. $response = $_POST['response'] === '1' ? true : false;
  117. $newStatus = TicketManager::STATUS_PENDING;
  118. if ($response) {
  119. $newStatus = TicketManager::STATUS_CLOSE;
  120. }
  121. TicketManager::update_ticket_status(
  122. TicketManager::getStatusIdFromCode($newStatus),
  123. $ticket_id,
  124. $user_id
  125. );
  126. Display::addFlash(Display::return_message(get_lang('Updated')));
  127. header("Location:".api_get_self()."?ticket_id=".$ticket_id);
  128. exit;
  129. }
  130. }*/
  131. $title = 'Ticket #'.$ticket['ticket']['code'];
  132. if (isset($_REQUEST['close'])) {
  133. TicketManager::close_ticket($ticket_id, $user_id);
  134. $ticket['ticket']['status_id'] = TicketManager::STATUS_CLOSE;
  135. $ticket['ticket']['status'] = get_lang('Closed');
  136. }
  137. $projectId = $ticket['ticket']['project_id'];
  138. $messages = $ticket['messages'];
  139. $counter = 1;
  140. $messageToShow = '';
  141. $formToShow = '';
  142. foreach ($messages as $message) {
  143. $date = Display::url(
  144. date_to_str_ago($message['sys_insert_datetime']),
  145. '#',
  146. ['title' => api_get_local_time($message['sys_insert_datetime']), 'class' => 'boot-tooltip']
  147. );
  148. $receivedMessage = '';
  149. if (!empty($message['subject'])) {
  150. $receivedMessage = '<b>'.get_lang('Subject').': </b> '.Security::remove_XSS($message['subject']).'<br />';
  151. }
  152. if (!empty($message['message'])) {
  153. $receivedMessage = '<b>'.get_lang('Message').':</b><br />'.Security::remove_XSS($message['message']).'<br />';
  154. }
  155. $attachmentLinks = '';
  156. if (isset($message['attachments'])) {
  157. $attributeClass = [
  158. 'class' => 'attachment-link',
  159. ];
  160. foreach ($message['attachments'] as $attach) {
  161. $attachmentLinks .= Display::tag('div', $attach['attachment_link'], $attributeClass);
  162. }
  163. }
  164. $entireMessage = $receivedMessage.$attachmentLinks;
  165. $counterLink = Display::url('#'.$counter, api_get_self().'?ticket_id='.$ticket_id.'#note-'.$counter);
  166. $messageToShow .= '<a id="note-'.$counter.'"> </a><h4>'.sprintf(
  167. get_lang('UpdatedByX'),
  168. $message['user_info']['complete_name_with_message_link']
  169. );
  170. $messageToShow .= ' '.$date.' <span class="pull-right">'.$counterLink.'</span></h4>';
  171. $messageToShow .= '<hr />';
  172. if (!empty($entireMessage)) {
  173. $messageToShow .= Display::div(
  174. $entireMessage,
  175. ['class' => 'well']
  176. );
  177. }
  178. $counter++;
  179. }
  180. $subject = get_lang('ReplyShort').': '.Security::remove_XSS($ticket['ticket']['subject']);
  181. if ($ticket['ticket']['status_id'] != TicketManager::STATUS_FORWARDED &&
  182. $ticket['ticket']['status_id'] != TicketManager::STATUS_CLOSE
  183. ) {
  184. if ($ticket['ticket']['assigned_last_user'] == $user_id ||
  185. $ticket['ticket']['sys_insert_user_id'] == $user_id ||
  186. $isAdmin
  187. ) {
  188. $form = getForm($ticket['ticket']);
  189. $formToShow = $form->returnForm();
  190. if ($form->validate()) {
  191. $ticket_id = (int) $_POST['ticket_id'];
  192. $messageToSend = '';
  193. $message = isset($_POST['confirmation']) ? true : false;
  194. $file_attachments = $_FILES;
  195. if ($isAdmin) {
  196. $oldUserId = $ticket['ticket']['assigned_last_user'];
  197. if (isset($_POST['assigned_last_user']) && !empty($_POST['assigned_last_user']) &&
  198. $_POST['assigned_last_user'] != $oldUserId
  199. ) {
  200. TicketManager::assignTicketToUser(
  201. $ticket_id,
  202. $_POST['assigned_last_user']
  203. );
  204. $oldUserName = '-';
  205. if (!empty($oldUserId)) {
  206. $oldUserInfo = api_get_user_info($oldUserId);
  207. $oldUserName = $oldUserInfo['complete_name_with_message_link'];
  208. }
  209. $userCompleteName = '-';
  210. if (!empty($_POST['assigned_last_user'])) {
  211. $userInfo = api_get_user_info(
  212. $_POST['assigned_last_user']
  213. );
  214. $userCompleteName = $userInfo['complete_name_with_message_link'];
  215. }
  216. $messageToSend .= sprintf(
  217. get_lang('AssignedChangeFromXToY'),
  218. $oldUserName,
  219. $userCompleteName
  220. ).'<br />';
  221. }
  222. TicketManager::updateTicket(
  223. [
  224. 'priority_id' => (int) $_POST['priority_id'],
  225. 'status_id' => (int) $_POST['status_id'],
  226. ],
  227. $ticket_id,
  228. api_get_user_id()
  229. );
  230. if ($_POST['priority_id'] != $ticket['ticket']['priority_id']) {
  231. $newPriority = TicketManager::getPriority(
  232. $_POST['priority_id']
  233. );
  234. $newPriorityTitle = '-';
  235. if ($newPriority) {
  236. $newPriorityTitle = $newPriority->getName();
  237. }
  238. $oldPriority = TicketManager::getPriority(
  239. $ticket['ticket']['priority_id']
  240. );
  241. $oldPriorityTitle = '-';
  242. if ($oldPriority) {
  243. $oldPriorityTitle = $oldPriority->getName();
  244. }
  245. $messageToSend .= sprintf(
  246. get_lang('PriorityChangeFromXToY'),
  247. $oldPriorityTitle,
  248. $newPriorityTitle
  249. ).'<br />';
  250. }
  251. if ($_POST['status_id'] != $ticket['ticket']['status_id']) {
  252. $newStatus = TicketManager::getStatus(
  253. $_POST['status_id']
  254. );
  255. $newTitle = '-';
  256. if ($newStatus) {
  257. $newTitle = $newStatus->getName();
  258. }
  259. $oldStatus = TicketManager::getStatus(
  260. $ticket['ticket']['status_id']
  261. );
  262. $oldStatusTitle = '-';
  263. if ($oldStatus) {
  264. $oldStatusTitle = $oldStatus->getName();
  265. }
  266. $messageToSend .= sprintf(
  267. get_lang('StatusChangeFromXToY'),
  268. $oldStatusTitle,
  269. $newTitle
  270. ).'<br />';
  271. }
  272. }
  273. $messageToSend .= $_POST['content'];
  274. TicketManager::insertMessage(
  275. $ticket_id,
  276. $_POST['subject'],
  277. $messageToSend,
  278. $file_attachments,
  279. $user_id,
  280. 'NOL',
  281. $message
  282. );
  283. TicketManager::sendNotification(
  284. $ticket_id,
  285. get_lang('TicketUpdated'),
  286. $messageToSend
  287. );
  288. Display::addFlash(Display::return_message(get_lang('Saved')));
  289. header("Location:".api_get_self()."?ticket_id=".$ticket_id);
  290. exit;
  291. }
  292. }
  293. }
  294. Display::display_header();
  295. echo '<div class="actions">';
  296. echo Display::url(
  297. Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
  298. api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId
  299. );
  300. echo '</div>';
  301. $bold = '';
  302. if ($ticket['ticket']['status_id'] == TicketManager::STATUS_CLOSE) {
  303. $bold = 'style = "font-weight: bold;"';
  304. }
  305. $senderData = get_lang('AddedBy').' '.$ticket['usuario']['complete_name_with_message_link'];
  306. echo '<table width="100%" >
  307. <tr>
  308. <td colspan="3">
  309. <h1>'.$title.'</h1>
  310. <h2>'.Security::remove_XSS($ticket['ticket']['subject']).'</h2>
  311. <p>
  312. '.$senderData.' '.
  313. get_lang('Created').' '.
  314. Display::url(
  315. date_to_str_ago($ticket['ticket']['start_date_from_db']),
  316. '#',
  317. ['title' => $ticket['ticket']['start_date'], 'class' => 'boot-tooltip']
  318. ).'. '.
  319. get_lang('TicketUpdated').' '.
  320. Display::url(
  321. date_to_str_ago($ticket['ticket']['sys_lastedit_datetime_from_db']),
  322. '#',
  323. ['title' => $ticket['ticket']['sys_lastedit_datetime'], 'class' => 'boot-tooltip']
  324. ).'
  325. </p>
  326. </td>
  327. </tr>
  328. <tr>
  329. <td><p><b>'.get_lang('Category').': </b>'.$ticket['ticket']['name'].'</p></td>
  330. </tr>
  331. <tr>
  332. <td><p '.$bold.'><b>'.get_lang('Status').':</b> '.$ticket['ticket']['status'].'</p></td>
  333. </tr>
  334. <tr>
  335. <td><p><b>'.get_lang('Priority').': </b>'.$ticket['ticket']['priority'].'<p></td>
  336. </tr>';
  337. if (!empty($ticket['ticket']['assigned_last_user'])) {
  338. $assignedUser = api_get_user_info($ticket['ticket']['assigned_last_user']);
  339. echo '<tr>
  340. <td><p><b>'.get_lang('AssignedTo').': </b>'.$assignedUser['complete_name_with_message_link'].'<p></td>
  341. </tr>';
  342. } else {
  343. echo '<tr>
  344. <td><p><b>'.get_lang('AssignedTo').': </b>-<p></td>
  345. </tr>';
  346. }
  347. if ($ticket['ticket']['course_url'] != null) {
  348. if (!empty($ticket['ticket']['session_id'])) {
  349. $sessionInfo = api_get_session_info($ticket['ticket']['session_id']);
  350. echo '<tr>
  351. <td><b>'.get_lang('Session').':</b> '.$sessionInfo['name'].' </td>
  352. <td></td>
  353. <td colspan="2"></td>
  354. </tr>';
  355. }
  356. echo '<tr>
  357. <td><b>'.get_lang('Course').':</b> '.$ticket['ticket']['course_url'].' </td>
  358. <td></td>
  359. <td colspan="2"></td>
  360. </tr>';
  361. }
  362. echo '<tr>
  363. <td>
  364. <hr />
  365. <b>'.get_lang('Description').':</b> <br />
  366. '.Security::remove_XSS($ticket['ticket']['message']).'
  367. <hr />
  368. </td>
  369. </tr>
  370. ';
  371. echo '</table>';
  372. echo $messageToShow;
  373. echo $formToShow;
  374. Display::display_footer();
  375. /**
  376. * @param array $ticket
  377. *
  378. * @return FormValidator
  379. */
  380. function getForm($ticket)
  381. {
  382. $isAdmin = api_is_platform_admin();
  383. global $subject;
  384. $form = new FormValidator(
  385. 'send_ticket',
  386. 'POST',
  387. api_get_self().'?ticket_id='.$ticket['id'],
  388. '',
  389. [
  390. 'enctype' => 'multipart/form-data',
  391. 'class' => 'form-horizontal',
  392. ]
  393. );
  394. if ($isAdmin) {
  395. $statusList = TicketManager::getStatusList();
  396. $form->addElement(
  397. 'select',
  398. 'status_id',
  399. get_lang('Status'),
  400. $statusList
  401. );
  402. $priorityList = TicketManager::getPriorityList();
  403. $form->addElement(
  404. 'select',
  405. 'priority_id',
  406. get_lang('Priority'),
  407. $priorityList,
  408. [
  409. 'id' => 'priority_id',
  410. 'for' => 'priority_id',
  411. ]
  412. );
  413. $form->addSelectAjax(
  414. 'assigned_last_user',
  415. get_lang('Assign'),
  416. null,
  417. ['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like']
  418. );
  419. $form->setDefaults(
  420. [
  421. 'priority_id' => $ticket['priority_id'],
  422. 'status_id' => $ticket['status_id'],
  423. 'assigned_last_user' => $ticket['assigned_last_user'],
  424. ]
  425. );
  426. }
  427. $form->addElement(
  428. 'text',
  429. 'subject',
  430. get_lang('Subject'),
  431. [
  432. 'for' => 'subject',
  433. 'value' => $subject,
  434. 'style' => 'width: 540px;',
  435. ]
  436. );
  437. $form->addElement('hidden', 'ticket_id', $ticket['id']);
  438. $form->addHtmlEditor(
  439. 'content',
  440. get_lang('Message'),
  441. false,
  442. false,
  443. [
  444. 'ToolbarSet' => 'Profile',
  445. 'Width' => '550',
  446. 'Height' => '250',
  447. ]
  448. );
  449. if ($isAdmin) {
  450. $form->addElement(
  451. 'checkbox',
  452. 'confirmation',
  453. null,
  454. get_lang('RequestConfirmation')
  455. );
  456. }
  457. $form->addElement('file', 'attach_1', get_lang('FilesAttachment'));
  458. $form->addLabel(
  459. '',
  460. '<span id="filepaths"><div id="filepath_1"></div></span>'
  461. );
  462. $form->addLabel(
  463. '',
  464. '<span id="link-more-attach">
  465. <span class="btn btn-success" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</span>
  466. </span>
  467. ('.sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))).')'
  468. );
  469. $form->addElement('html', '<br/>');
  470. $form->addButtonSend(get_lang('Send'));
  471. return $form;
  472. }