tickets.php 11 KB

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