ticket_details.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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[] = array(
  12. 'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
  13. 'name' => get_lang('MyTickets')
  14. );
  15. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('TicketDetail'));
  16. $disableReponseButtons = '';
  17. $htmlHeadXtra[] = '<script>
  18. $(document).ready(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. $("input#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 = $_GET['ticket_id'];
  101. $ticket = TicketManager::get_ticket_detail_by_id($ticket_id);
  102. if (!isset($ticket['ticket'])) {
  103. api_not_allowed(true);
  104. }
  105. if (!isset($_GET['ticket_id'])) {
  106. header('Location: '.api_get_path(WEB_CODE_PATH).'ticket/tickets.php');
  107. exit;
  108. }
  109. /*if (isset($_POST['response'])) {
  110. if ($user_id == $ticket['ticket']['assigned_last_user'] || api_is_platform_admin()) {
  111. $response = $_POST['response'] === '1' ? true : false;
  112. $newStatus = TicketManager::STATUS_PENDING;
  113. if ($response) {
  114. $newStatus = TicketManager::STATUS_CLOSE;
  115. }
  116. TicketManager::update_ticket_status(
  117. TicketManager::getStatusIdFromCode($newStatus),
  118. $ticket_id,
  119. $user_id
  120. );
  121. Display::addFlash(Display::return_message(get_lang('Updated')));
  122. header("Location:".api_get_self()."?ticket_id=".$ticket_id);
  123. exit;
  124. }
  125. }*/
  126. $title = 'Ticket #'.$ticket['ticket']['code'];
  127. if (isset($_REQUEST['close'])) {
  128. TicketManager::close_ticket($_REQUEST['ticket_id'], $user_id);
  129. $ticket['ticket']['status_id'] = TicketManager::STATUS_CLOSE;
  130. $ticket['ticket']['status'] = get_lang('Closed');
  131. }
  132. $projectId = $ticket['ticket']['project_id'];
  133. $messages = $ticket['messages'];
  134. $counter = 1;
  135. $messageToShow = '';
  136. $formToShow = '';
  137. foreach ($messages as $message) {
  138. $date = Display::url(
  139. date_to_str_ago($message['sys_insert_datetime']),
  140. '#',
  141. ['title' => api_get_local_time($message['sys_insert_datetime']), 'class' => 'boot-tooltip']
  142. );
  143. $receivedMessage = '';
  144. if (!empty($message['subject'])) {
  145. $receivedMessage = '<b>'.get_lang('Subject').': </b> '.$message['subject'].'<br/>';
  146. }
  147. if (!empty($message['message'])) {
  148. $receivedMessage = '<b>'.get_lang('Message').':</b><br/>'.$message['message'].'<br/>';
  149. }
  150. $attachmentLinks = '';
  151. if (isset($message['attachments'])) {
  152. $attributeClass = array(
  153. 'class' => 'attachment-link'
  154. );
  155. foreach ($message['attachments'] as $attach) {
  156. $attachmentLinks .= Display::tag('div', $attach['attachment_link'], $attributeClass);
  157. }
  158. }
  159. $entireMessage = $receivedMessage.$attachmentLinks;
  160. $counterLink = Display::url('#'.$counter, api_get_self().'?ticket_id='.$ticket_id.'#note-'.$counter);
  161. $messageToShow .= '<a id="note-'.$counter.'"> </a><h4>'.sprintf(
  162. get_lang('UpdatedByX'),
  163. $message['user_info']['complete_name_with_message_link']
  164. );
  165. $messageToShow .= ' '.$date.' <span class="pull-right">'.$counterLink.'</span></h4>';
  166. $messageToShow .= '<hr />';
  167. if (!empty($entireMessage)) {
  168. $messageToShow .= Display::div(
  169. $entireMessage,
  170. ['class' => 'well']
  171. );
  172. }
  173. $counter++;
  174. }
  175. $subject = get_lang('ReplyShort').': '.$ticket['ticket']['subject'];
  176. if ($ticket['ticket']['status_id'] != TicketManager::STATUS_FORWARDED &&
  177. $ticket['ticket']['status_id'] != TicketManager::STATUS_CLOSE
  178. ) {
  179. if ($ticket['ticket']['assigned_last_user'] == $user_id ||
  180. $ticket['ticket']['sys_insert_user_id'] == $user_id ||
  181. $isAdmin
  182. ) {
  183. $form = getForm($ticket['ticket']);
  184. $formToShow = $form->returnForm();
  185. if ($form->validate()) {
  186. $ticket_id = $_POST['ticket_id'];
  187. $content = $_POST['content'];
  188. $messageToSend = '';
  189. $subject = $_POST['subject'];
  190. $message = isset($_POST['confirmation']) ? true : false;
  191. $file_attachments = $_FILES;
  192. if ($isAdmin) {
  193. $oldUserId = $ticket['ticket']['assigned_last_user'];
  194. if (isset($_POST['assigned_last_user']) && !empty($_POST['assigned_last_user']) &&
  195. $_POST['assigned_last_user'] != $oldUserId
  196. ) {
  197. TicketManager::assignTicketToUser(
  198. $ticket_id,
  199. $_POST['assigned_last_user']
  200. );
  201. $oldUserName = '-';
  202. if (!empty($oldUserId)) {
  203. $oldUserInfo = api_get_user_info($oldUserId);
  204. $oldUserName = $oldUserInfo['complete_name_with_message_link'];
  205. }
  206. $userCompleteName = '-';
  207. if (!empty($_POST['assigned_last_user'])) {
  208. $userInfo = api_get_user_info(
  209. $_POST['assigned_last_user']
  210. );
  211. $userCompleteName = $userInfo['complete_name_with_message_link'];
  212. }
  213. $messageToSend .= sprintf(
  214. get_lang('AssignedChangeFromXToY'),
  215. $oldUserName,
  216. $userCompleteName
  217. ).'<br />';
  218. }
  219. TicketManager::updateTicket(
  220. [
  221. 'priority_id' => $_POST['priority_id'],
  222. 'status_id' => $_POST['status_id']
  223. ],
  224. $ticket_id,
  225. api_get_user_id()
  226. );
  227. if ($_POST['priority_id'] != $ticket['ticket']['priority_id']) {
  228. $newPriority = TicketManager::getPriority(
  229. $_POST['priority_id']
  230. );
  231. $newPriorityTitle = '-';
  232. if ($newPriority) {
  233. $newPriorityTitle = $newPriority->getName();
  234. }
  235. $oldPriority = TicketManager::getPriority(
  236. $ticket['ticket']['priority_id']
  237. );
  238. $oldPriorityTitle = '-';
  239. if ($oldPriority) {
  240. $oldPriorityTitle = $oldPriority->getName();
  241. }
  242. $messageToSend .= sprintf(
  243. get_lang('PriorityChangeFromXToY'),
  244. $oldPriorityTitle,
  245. $newPriorityTitle
  246. ).'<br />';
  247. }
  248. if ($_POST['status_id'] != $ticket['ticket']['status_id']) {
  249. $newStatus = TicketManager::getStatus(
  250. $_POST['status_id']
  251. );
  252. $newTitle = '-';
  253. if ($newStatus) {
  254. $newTitle = $newStatus->getName();
  255. }
  256. $oldStatus = TicketManager::getStatus(
  257. $ticket['ticket']['status_id']
  258. );
  259. $oldStatusTitle = '-';
  260. if ($oldStatus) {
  261. $oldStatusTitle = $oldStatus->getName();
  262. }
  263. $messageToSend .= sprintf(
  264. get_lang('StatusChangeFromXToY'),
  265. $oldStatusTitle,
  266. $newTitle
  267. ).'<br />';
  268. }
  269. }
  270. $messageToSend .= $content;
  271. TicketManager::insertMessage(
  272. $ticket_id,
  273. $subject,
  274. $messageToSend,
  275. $file_attachments,
  276. $user_id,
  277. 'NOL',
  278. $message
  279. );
  280. TicketManager::sendNotification(
  281. $ticket_id,
  282. get_lang('TicketUpdated'),
  283. $messageToSend
  284. );
  285. Display::addFlash(Display::return_message(get_lang('Saved')));
  286. header("Location:".api_get_self()."?ticket_id=".$ticket_id);
  287. exit;
  288. }
  289. }
  290. }
  291. Display::display_header();
  292. echo '<div class="actions">';
  293. echo Display::url(
  294. Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
  295. api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId
  296. );
  297. echo '</div>';
  298. $bold = '';
  299. if ($ticket['ticket']['status_id'] == TicketManager::STATUS_CLOSE) {
  300. $bold = 'style = "font-weight: bold;"';
  301. }
  302. if ($isAdmin) {
  303. $senderData = get_lang('AddedBy').' '.$ticket['ticket']['user_url'].' ('.$ticket['usuario']['complete_name_with_message_link'].').';
  304. } else {
  305. $senderData = get_lang('AddedBy').' '.$ticket['usuario']['complete_name_with_message_link'].' ('.$ticket['usuario']['username'].').';
  306. }
  307. echo '<table width="100%" >
  308. <tr>
  309. <td colspan="3">
  310. <h1>'.$title.'</h1>
  311. <h2>'.$ticket['ticket']['subject'].'</h2>
  312. <p>
  313. '.$senderData.' '.
  314. get_lang('Created').' '.
  315. Display::url(
  316. date_to_str_ago($ticket['ticket']['start_date_from_db']),
  317. '#',
  318. ['title' => $ticket['ticket']['start_date'], 'class' => 'boot-tooltip']
  319. ).'. '.
  320. get_lang('TicketUpdated').' '.
  321. Display::url(
  322. date_to_str_ago($ticket['ticket']['sys_lastedit_datetime_from_db']),
  323. '#',
  324. ['title' => $ticket['ticket']['sys_lastedit_datetime'], 'class' => 'boot-tooltip']
  325. ).'
  326. </p>
  327. </td>
  328. </tr>
  329. <tr>
  330. <td><p><b>' . get_lang('Category').': </b>'.$ticket['ticket']['name'].'</p></td>
  331. </tr>
  332. <tr>
  333. <td><p ' . $bold.'><b>'.get_lang('Status').':</b> '.$ticket['ticket']['status'].'</p></td>
  334. </tr>
  335. <tr>
  336. <td><p><b>' . get_lang('Priority').': </b>'.$ticket['ticket']['priority'].'<p></td>
  337. </tr>';
  338. if (!empty($ticket['ticket']['assigned_last_user'])) {
  339. $assignedUser = api_get_user_info($ticket['ticket']['assigned_last_user']);
  340. echo '<tr>
  341. <td><p><b>' . get_lang('AssignedTo').': </b>'.$assignedUser['complete_name_with_message_link'].'<p></td>
  342. </tr>';
  343. } else {
  344. echo '<tr>
  345. <td><p><b>' . get_lang('AssignedTo').': </b>-<p></td>
  346. </tr>';
  347. }
  348. if ($ticket['ticket']['course_url'] != null) {
  349. if (!empty($ticket['ticket']['session_id'])) {
  350. $sessionInfo = api_get_session_info($ticket['ticket']['session_id']);
  351. echo '<tr>
  352. <td><b>' . get_lang('Session').':</b> '.$sessionInfo['name'].' </td>
  353. <td></td>
  354. <td colspan="2"></td>
  355. </tr>';
  356. }
  357. echo '<tr>
  358. <td><b>' . get_lang('Course').':</b> '.$ticket['ticket']['course_url'].' </td>
  359. <td></td>
  360. <td colspan="2"></td>
  361. </tr>';
  362. }
  363. echo '<tr>
  364. <td>
  365. <hr />
  366. <b>' . get_lang('Description').':</b> <br />
  367. '.$ticket['ticket']['message'].'
  368. <hr />
  369. </td>
  370. </tr>
  371. ';
  372. echo '</table>';
  373. echo $messageToShow;
  374. echo $formToShow;
  375. Display::display_footer();
  376. /**
  377. * @param array $ticket
  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. array(
  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. array(
  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. array(
  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. array(
  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. }