priorities.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. api_protect_admin_script(true);
  12. $toolName = get_lang('Priorities');
  13. $webLibPath = api_get_path(WEB_LIBRARY_PATH);
  14. $this_section = 'tickets';
  15. Session::erase('this_section');
  16. $table = new SortableTable(
  17. 'TicketProject',
  18. ['TicketManager', 'getPriorityCount'],
  19. ['TicketManager', 'getPriorityAdminList'],
  20. 1
  21. );
  22. if ($table->per_page == 0) {
  23. $table->per_page = 20;
  24. }
  25. $formToString = '';
  26. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  27. $action = isset($_GET['action']) ? $_GET['action'] : '';
  28. $interbreadcrumb[] = [
  29. 'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
  30. 'name' => get_lang('MyTickets'),
  31. ];
  32. $interbreadcrumb[] = [
  33. 'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
  34. 'name' => get_lang('Settings'),
  35. ];
  36. switch ($action) {
  37. case 'delete':
  38. $tickets = TicketManager::getTicketsFromCriteria(['priority' => $id]);
  39. if (empty($tickets)) {
  40. TicketManager::deletePriority($id);
  41. Display::addFlash(Display::return_message(get_lang('Deleted')));
  42. } else {
  43. Display::addFlash(Display::return_message(get_lang('ThisItemIsRelatedToOtherTickets'), 'warning'));
  44. }
  45. header("Location: ".api_get_self());
  46. exit;
  47. break;
  48. case 'add':
  49. $toolName = get_lang('Add');
  50. $interbreadcrumb[] = [
  51. 'url' => api_get_path(WEB_CODE_PATH).'ticket/priorities.php',
  52. 'name' => get_lang('Priorities'),
  53. ];
  54. $url = api_get_self().'?action=add';
  55. $form = TicketManager::getPriorityForm($url);
  56. $formToString = $form->returnForm();
  57. if ($form->validate()) {
  58. $values = $form->getSubmitValues();
  59. $params = [
  60. 'name' => $values['name'],
  61. 'description' => $values['description'],
  62. ];
  63. TicketManager::addPriority($params);
  64. Display::addFlash(Display::return_message(get_lang('Added')));
  65. header("Location: ".api_get_self());
  66. exit;
  67. }
  68. break;
  69. case 'edit':
  70. $toolName = get_lang('Edit');
  71. $interbreadcrumb[] = [
  72. 'url' => api_get_path(WEB_CODE_PATH).'ticket/priorities.php',
  73. 'name' => get_lang('Priorities'),
  74. ];
  75. $url = api_get_self().'?action=edit&id='.$id;
  76. $form = TicketManager::getPriorityForm($url);
  77. $item = TicketManager::getPriority($_GET['id']);
  78. $form->setDefaults(
  79. [
  80. 'name' => $item->getName(),
  81. 'description' => $item->getDescription(),
  82. ]
  83. );
  84. $formToString = $form->returnForm();
  85. if ($form->validate()) {
  86. $values = $form->getSubmitValues();
  87. $params = [
  88. 'name' => $values['name'],
  89. 'description' => $values['description'],
  90. ];
  91. $cat = TicketManager::updatePriority($_GET['id'], $params);
  92. Display::addFlash(Display::return_message(get_lang('Updated')));
  93. header("Location: ".api_get_self());
  94. exit;
  95. }
  96. break;
  97. default:
  98. break;
  99. }
  100. $user_id = api_get_user_id();
  101. $isAdmin = api_is_platform_admin();
  102. /**
  103. * Build the modify-column of the table.
  104. *
  105. * @param int The user id
  106. * @param string URL params to add to table links
  107. * @param array Row of elements to alter
  108. *
  109. * @return string Some HTML-code with modify-buttons
  110. */
  111. function modify_filter($id, $params, $row)
  112. {
  113. $result = Display::url(
  114. Display::return_icon('edit.png', get_lang('Edit')),
  115. api_get_self()."?action=edit&id={$row['id']}"
  116. );
  117. $code = $row['code'];
  118. if (!in_array($code, TicketManager::getDefaultPriorityList())) {
  119. $result .= Display::url(
  120. Display::return_icon('delete.png', get_lang('Delete')),
  121. api_get_self()."?action=delete&id={$row['id']}"
  122. );
  123. }
  124. return $result;
  125. }
  126. $table->set_header(0, '', false);
  127. $table->set_header(1, get_lang('Title'), false);
  128. $table->set_header(2, get_lang('Description'), true, ["style" => "width:200px"]);
  129. $table->set_header(3, get_lang('Actions'), true);
  130. $table->set_column_filter('3', 'modify_filter');
  131. Display::display_header($toolName);
  132. $items = [
  133. 'icon' => 'new_folder.png',
  134. 'url' => 'priorities.php?action=add',
  135. 'content' => get_lang('AddPriority'),
  136. ];
  137. echo '<div class="actions">';
  138. echo Display::url(
  139. Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
  140. api_get_path(WEB_CODE_PATH).'ticket/tickets.php'
  141. );
  142. $sections = TicketManager::getSettingsMenuItems('priority');
  143. array_unshift($sections, $items);
  144. foreach ($sections as $item) {
  145. echo Display::url(
  146. Display::return_icon($item['icon'], $item['content'], [], ICON_SIZE_MEDIUM),
  147. $item['url']
  148. );
  149. }
  150. echo '</div>';
  151. echo $formToString;
  152. echo $table->return_table();
  153. Display::display_footer();