status.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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('Status');
  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', 'getStatusCount'),
  17. array('TicketManager', 'getStatusAdminList'),
  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(['status' => $id]);
  37. if (empty($tickets)) {
  38. TicketManager::deleteStatus($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/status.php',
  50. 'name' => get_lang('Status')
  51. );
  52. $url = api_get_self().'?action=add';
  53. $form = TicketManager::getStatusForm($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::addStatus($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/status.php',
  71. 'name' => get_lang('Status')
  72. );
  73. $url = api_get_self().'?action=edit&id='.$id;
  74. $form = TicketManager::getStatusForm($url);
  75. $item = TicketManager::getStatus($_GET['id']);
  76. $form->setDefaults([
  77. 'name' => $item->getName(),
  78. 'description' => $item->getDescription()
  79. ]);
  80. $formToString = $form->returnForm();
  81. if ($form->validate()) {
  82. $values = $form->getSubmitValues();
  83. $params = [
  84. 'name' => $values['name'],
  85. 'description' => $values['description']
  86. ];
  87. $cat = TicketManager::updateStatus($_GET['id'], $params);
  88. Display::addFlash(Display::return_message(get_lang('Updated')));
  89. header("Location: ".api_get_self());
  90. exit;
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96. $user_id = api_get_user_id();
  97. $isAdmin = api_is_platform_admin();
  98. /**
  99. * Build the modify-column of the table
  100. * @param int The user id
  101. * @param string URL params to add to table links
  102. * @param array Row of elements to alter
  103. * @return string Some HTML-code with modify-buttons
  104. */
  105. function modify_filter($id, $params, $row)
  106. {
  107. $id = $row['id'];
  108. $code = $row['code'];
  109. $result = Display::url(
  110. Display::return_icon('edit.png', get_lang('Edit')),
  111. api_get_self()."?action=edit&id={$id}"
  112. );
  113. if (!in_array($code, TicketManager::getDefaultStatusList())) {
  114. $result .= Display::url(
  115. Display::return_icon('delete.png', get_lang('Delete')),
  116. api_get_self()."?action=delete&id={$id}"
  117. );
  118. }
  119. return $result;
  120. }
  121. $table->set_header(0, '', false);
  122. $table->set_header(1, get_lang('Title'), false);
  123. $table->set_header(2, get_lang('Description'), true, array("style" => "width:200px"));
  124. $table->set_header(3, get_lang('Actions'), true);
  125. $table->set_column_filter('3', 'modify_filter');
  126. Display::display_header($toolName);
  127. $items = [
  128. [
  129. 'url' => 'status.php?action=add',
  130. 'content' => Display::return_icon('new_folder.png', null, null, ICON_SIZE_MEDIUM)
  131. ]
  132. ];
  133. echo Display::actions($items);
  134. echo $formToString;
  135. echo $table->return_table();
  136. Display::display_footer();