priorities.php 4.7 KB

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