tickets.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This script is the Tickets plugin main entry point.
  6. *
  7. * @package chamilo.plugin.ticket
  8. */
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. $tool_name = get_lang('Ticket');
  12. $webLibPath = api_get_path(WEB_LIBRARY_PATH);
  13. $htmlHeadXtra[] = '<script>
  14. function load_history_ticket(div_course, ticket_id) {
  15. $.ajax({
  16. contentType: "application/x-www-form-urlencoded",
  17. beforeSend: function(object) {
  18. $("div#"+div_course).html("<img src=\''.$webLibPath.'javascript/indicator.gif\' />"); },
  19. type: "POST",
  20. url: "ticket_assign_log.php",
  21. data: "ticket_id="+ticket_id,
  22. success: function(data) {
  23. $("div#div_"+ticket_id).html(data);
  24. $("div#div_"+ticket_id).attr("class","blackboard_show");
  25. $("div#div_"+ticket_id).attr("style","");
  26. }
  27. });
  28. }
  29. function clear_course_list(div_course) {
  30. $("div#"+div_course).html("&nbsp;");
  31. $("div#"+div_course).hide("");
  32. }
  33. $(function() {
  34. $("#advanced_search_form").css("display","none");
  35. });
  36. function display_advanced_search_form () {
  37. if ($("#advanced_search_form").css("display") == "none") {
  38. $("#advanced_search_form").css("display","block");
  39. $("#img_plus_and_minus").html(\'&nbsp;'.Display::returnFontAwesomeIcon('arrow-down').' '.get_lang('Advanced search').'\');
  40. } else {
  41. $("#advanced_search_form").css("display","none");
  42. $("#img_plus_and_minus").html(\'&nbsp;'.Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('Advanced search').'\');
  43. }
  44. }
  45. </script>';
  46. $this_section = 'tickets';
  47. Session::erase('this_section');
  48. $action = isset($_GET['action']) ? $_GET['action'] : '';
  49. $projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : 0;
  50. $table = new SortableTable(
  51. 'Tickets',
  52. ['TicketManager', 'getTotalTicketsCurrentUser'],
  53. ['TicketManager', 'getTicketsByCurrentUser'],
  54. 2,
  55. 20,
  56. 'DESC'
  57. );
  58. $table->set_additional_parameters(['project_id' => $projectId]);
  59. if ($table->per_page == 0) {
  60. $table->per_page = 20;
  61. }
  62. switch ($action) {
  63. case 'alert':
  64. if (!$isAdmin && isset($_GET['ticket_id'])) {
  65. TicketManager::send_alert($_GET['ticket_id'], $user_id);
  66. }
  67. break;
  68. case 'export':
  69. $data = [
  70. [
  71. '#',
  72. get_lang('Date'),
  73. get_lang('Last update'),
  74. get_lang('Category'),
  75. get_lang('User'),
  76. get_lang('Course Program</a>. If your course has no code, whatever the reason, invent one. For instance <i>INNOVATION</i> if the course is about Innovation Management'),
  77. get_lang('Assigned to'),
  78. get_lang('Status'),
  79. get_lang('Description'),
  80. ],
  81. ];
  82. $datos = $table->get_clean_html();
  83. foreach ($datos as $ticket) {
  84. $ticket[0] = substr(strip_tags($ticket[0]), 0, 12);
  85. $ticket_rem = [
  86. utf8_decode(strip_tags($ticket[0])),
  87. utf8_decode(api_html_entity_decode($ticket[1])),
  88. utf8_decode(strip_tags($ticket[2])),
  89. utf8_decode(strip_tags($ticket[3])),
  90. utf8_decode(strip_tags($ticket[4])),
  91. utf8_decode(strip_tags($ticket[5])),
  92. utf8_decode(strip_tags($ticket[6])),
  93. utf8_decode(strip_tags($ticket[7])),
  94. ];
  95. $data[] = $ticket_rem;
  96. }
  97. Export::arrayToXls($data, get_lang('Tickets'));
  98. exit;
  99. break;
  100. case 'close_tickets':
  101. TicketManager::close_old_tickets();
  102. break;
  103. default:
  104. break;
  105. }
  106. if (empty($projectId)) {
  107. $projects = TicketManager::getProjectsSimple();
  108. if (!empty($projects) && isset($projects[0])) {
  109. $project = $projects[0];
  110. header('Location: '.api_get_self().'?project_id='.$project['id']);
  111. exit;
  112. }
  113. }
  114. $currentUrl = api_get_self().'?project_id='.$projectId;
  115. $user_id = api_get_user_id();
  116. $isAllow = TicketManager::userIsAllowInProject(api_get_user_info(), $projectId);
  117. $isAdmin = api_is_platform_admin();
  118. $actionRight = '';
  119. Display::display_header(get_lang('My tickets'));
  120. if (!empty($projectId)) {
  121. $getParameters = [];
  122. if ($isAdmin) {
  123. $getParameters = [
  124. 'keyword',
  125. 'keyword_status',
  126. 'keyword_category',
  127. 'keyword_assigned_to',
  128. 'keyword_start_date',
  129. 'keyword_unread',
  130. 'Tickets_per_page',
  131. 'Tickets_column',
  132. ];
  133. }
  134. $get_parameter = '';
  135. foreach ($getParameters as $getParameter) {
  136. if (isset($_GET[$getParameter])) {
  137. $get_parameter .= "&$getParameter=".Security::remove_XSS($_GET[$getParameter]);
  138. }
  139. }
  140. $getParameters = [
  141. 'Tickets_per_page',
  142. 'Tickets_column',
  143. ];
  144. $get_parameter2 = '';
  145. foreach ($getParameters as $getParameter) {
  146. if (isset($_GET[$getParameter])) {
  147. $get_parameter2 .= "&$getParameter=".Security::remove_XSS($_GET[$getParameter]);
  148. }
  149. }
  150. if (isset($_GET['submit_advanced'])) {
  151. $get_parameter .= "&submit_advanced=";
  152. }
  153. if (isset($_GET['submit_simple'])) {
  154. $get_parameter .= "&submit_simple=";
  155. }
  156. // Select categories
  157. $selectTypes = [];
  158. $types = TicketManager::get_all_tickets_categories($projectId);
  159. foreach ($types as $type) {
  160. $selectTypes[$type['category_id']] = $type['name'];
  161. }
  162. $admins = UserManager::getUserListLike(
  163. ['status' => '1'],
  164. ['username'],
  165. true
  166. );
  167. $selectAdmins = [
  168. 0 => get_lang('Unassigned'),
  169. ];
  170. foreach ($admins as $admin) {
  171. $selectAdmins[$admin['user_id']] = $admin['complete_name_with_username'];
  172. }
  173. $status = TicketManager::get_all_tickets_status();
  174. $selectStatus = [];
  175. foreach ($status as $stat) {
  176. $selectStatus[$stat['id']] = $stat['name'];
  177. }
  178. $selectPriority = TicketManager::getPriorityList();
  179. $selectUnread = [
  180. '' => get_lang('All'),
  181. 'yes' => get_lang('Unread'),
  182. 'no' => get_lang('Read'),
  183. ];
  184. // Create a search-box
  185. $form = new FormValidator(
  186. 'search_simple',
  187. 'get',
  188. $currentUrl,
  189. null,
  190. null,
  191. 'inline'
  192. );
  193. $form->addText('keyword', get_lang('Keyword'), false);
  194. $form->addButtonSearch(get_lang('Search'), 'submit_simple');
  195. $form->addHidden('project_id', $projectId);
  196. $advancedSearch = Display::url(
  197. '<span id="img_plus_and_minus">&nbsp;'.
  198. Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('Advanced search'),
  199. 'javascript://',
  200. [
  201. 'class' => 'btn btn-default advanced-parameters',
  202. 'onclick' => 'display_advanced_search_form();',
  203. ]
  204. );
  205. // Add link
  206. if (api_get_setting('ticket_allow_student_add') == 'true' || api_is_platform_admin()) {
  207. $actionRight = Display::url(
  208. Display::return_icon(
  209. 'add.png',
  210. get_lang('Add'),
  211. null,
  212. ICON_SIZE_MEDIUM
  213. ),
  214. api_get_path(WEB_CODE_PATH).'ticket/new_ticket.php?project_id='.$projectId.'&'.api_get_cidReq(),
  215. ['title' => get_lang('Add')]
  216. );
  217. }
  218. if (api_is_platform_admin()) {
  219. $actionRight .= Display::url(
  220. Display::return_icon(
  221. 'export_excel.png',
  222. get_lang('Export'),
  223. null,
  224. ICON_SIZE_MEDIUM
  225. ),
  226. api_get_self().'?action=export'.$get_parameter.$get_parameter2.'&project_id='.$projectId,
  227. ['title' => get_lang('Export')]
  228. );
  229. $actionRight .= Display::url(
  230. Display::return_icon(
  231. 'settings.png',
  232. get_lang('Settings'),
  233. null,
  234. ICON_SIZE_MEDIUM
  235. ),
  236. api_get_path(WEB_CODE_PATH).'ticket/settings.php',
  237. ['title' => get_lang('Settings')]
  238. );
  239. }
  240. echo Display::toolbarAction(
  241. 'toolbar-tickets',
  242. [
  243. $form->returnForm(),
  244. $advancedSearch,
  245. $actionRight,
  246. ]
  247. );
  248. $ticketLabel = get_lang('All tickets');
  249. $url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId;
  250. if (!isset($_GET['keyword_assigned_to'])) {
  251. $ticketLabel = get_lang('My tickets');
  252. $url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId.'&keyword_assigned_to='.api_get_user_id();
  253. }
  254. $options = '';
  255. $iconProject = Display::return_icon(
  256. 'project.png',
  257. get_lang('Projects'),
  258. null,
  259. ICON_SIZE_MEDIUM
  260. );
  261. if ($isAdmin) {
  262. $options .= Display::url(
  263. $iconProject,
  264. api_get_path(WEB_CODE_PATH).'ticket/projects.php'
  265. );
  266. }
  267. $iconTicket = Display::return_icon(
  268. 'tickets.png',
  269. $ticketLabel,
  270. null,
  271. ICON_SIZE_MEDIUM
  272. );
  273. $options .= Display::url(
  274. $iconTicket,
  275. $url
  276. );
  277. if ($isAllow) {
  278. echo Display::toolbarAction(
  279. 'toolbar-options',
  280. [
  281. $options,
  282. ]
  283. );
  284. }
  285. $advancedSearchForm = new FormValidator(
  286. 'advanced_search',
  287. 'get',
  288. $currentUrl,
  289. null,
  290. ['style' => 'display:"none"', 'id' => 'advanced_search_form']
  291. );
  292. $advancedSearchForm->addHidden('project_id', $projectId);
  293. $advancedSearchForm->addHeader(get_lang('Advanced search'));
  294. $advancedSearchForm->addSelect(
  295. 'keyword_category',
  296. get_lang('Category'),
  297. $selectTypes,
  298. ['placeholder' => get_lang('Select')]
  299. );
  300. $advancedSearchForm->addDateTimePicker('keyword_start_date_start', get_lang('Created'));
  301. $advancedSearchForm->addDateTimePicker('keyword_start_date_end', get_lang('Until'));
  302. $advancedSearchForm->addSelect(
  303. 'keyword_assigned_to',
  304. get_lang('Assigned to'),
  305. $selectAdmins,
  306. ['placeholder' => get_lang('All')]
  307. );
  308. $advancedSearchForm->addSelect(
  309. 'keyword_status',
  310. get_lang('Status'),
  311. $selectStatus,
  312. ['placeholder' => get_lang('Select')]
  313. );
  314. $advancedSearchForm->addSelect(
  315. 'keyword_priority',
  316. get_lang('Priority'),
  317. $selectPriority,
  318. ['placeholder' => get_lang('All')]
  319. );
  320. $advancedSearchForm->addText('keyword_course', get_lang('Course'), false);
  321. $advancedSearchForm->addButtonSearch(get_lang('Advanced search'), 'submit_advanced');
  322. $advancedSearchForm->display();
  323. } else {
  324. if (api_get_setting('ticket_allow_student_add') === 'true') {
  325. echo '<div class="actions">';
  326. echo '<a href="'.api_get_path(WEB_CODE_PATH).'ticket/new_ticket.php?project_id='.$projectId.'">'.
  327. Display::return_icon('add.png', get_lang('Add'), '', '32').
  328. '</a>';
  329. echo '</div>';
  330. }
  331. }
  332. if ($isAdmin) {
  333. $table->set_header(0, '#', true);
  334. $table->set_header(1, get_lang('Status'), true);
  335. $table->set_header(2, get_lang('Date'), true);
  336. $table->set_header(3, get_lang('Last update'), true);
  337. $table->set_header(4, get_lang('Category'), true);
  338. $table->set_header(5, get_lang('Created by'), true);
  339. $table->set_header(6, get_lang('Assigned to'), true);
  340. $table->set_header(7, get_lang('Message'), true);
  341. } else {
  342. if ($isAllow == false) {
  343. echo Display::page_subheader(get_lang('My tickets'));
  344. echo Display::return_message(get_lang('Welcome to YOUR tickets section. Here, you\'ll be able to track the state of all the tickets you created in the main tickets section.'));
  345. }
  346. $table->set_header(0, '#', true);
  347. $table->set_header(1, get_lang('Status'), false);
  348. $table->set_header(2, get_lang('Date'), true);
  349. $table->set_header(3, get_lang('Last update'), true);
  350. $table->set_header(4, get_lang('Category'));
  351. }
  352. $table->display();
  353. Display::display_footer();