status.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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('Status');
  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', 'getStatusCount'],
  19. ['TicketManager', 'getStatusAdminList'],
  20. 1
  21. );
  22. if ($table->per_page == 0) {
  23. $table->per_page = 20;
  24. }
  25. $formToString = '';
  26. $id = isset($_GET['id']) ? (int) $_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('My tickets'),
  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(['status' => $id]);
  39. if (empty($tickets)) {
  40. TicketManager::deleteStatus($id);
  41. Display::addFlash(Display::return_message(get_lang('Deleted')));
  42. } else {
  43. Display::addFlash(Display::return_message(get_lang('This item is related to other tickets.'), '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/status.php',
  52. 'name' => get_lang('Status'),
  53. ];
  54. $url = api_get_self().'?action=add';
  55. $form = TicketManager::getStatusForm($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::addStatus($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/status.php',
  73. 'name' => get_lang('Status'),
  74. ];
  75. $url = api_get_self().'?action=edit&id='.$id;
  76. $form = TicketManager::getStatusForm($url);
  77. $item = TicketManager::getStatus($id);
  78. $form->setDefaults([
  79. 'name' => $item->getName(),
  80. 'description' => $item->getDescription(),
  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::updateStatus($id, $params);
  90. Display::addFlash(Display::return_message(get_lang('Update successful')));
  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. *
  103. * @param int The user id
  104. * @param string URL params to add to table links
  105. * @param array Row of elements to alter
  106. *
  107. * @return string Some HTML-code with modify-buttons
  108. */
  109. function modify_filter($id, $params, $row)
  110. {
  111. $id = $row['id'];
  112. $code = $row['code'];
  113. $result = Display::url(
  114. Display::return_icon('edit.png', get_lang('Edit')),
  115. api_get_self()."?action=edit&id={$id}"
  116. );
  117. if (!in_array($code, TicketManager::getDefaultStatusList())) {
  118. $result .= Display::url(
  119. Display::return_icon('delete.png', get_lang('Delete')),
  120. api_get_self()."?action=delete&id={$id}"
  121. );
  122. }
  123. return $result;
  124. }
  125. $table->set_header(0, '', false);
  126. $table->set_header(1, get_lang('Title'), false);
  127. $table->set_header(2, get_lang('Description'), true, ["style" => "width:200px"]);
  128. $table->set_header(3, get_lang('Detail'), true);
  129. $table->set_column_filter('3', 'modify_filter');
  130. Display::display_header($toolName);
  131. $items = [
  132. 'icon' => 'new_folder.png',
  133. 'url' => 'status.php?action=add',
  134. 'content' => get_lang('Add status'),
  135. ];
  136. echo '<div class="actions">';
  137. echo Display::url(
  138. Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
  139. api_get_path(WEB_CODE_PATH).'ticket/tickets.php'
  140. );
  141. $sections = TicketManager::getSettingsMenuItems('status');
  142. array_unshift($sections, $items);
  143. foreach ($sections as $item) {
  144. echo Display::url(
  145. Display::return_icon($item['icon'], $item['content'], [], ICON_SIZE_MEDIUM),
  146. $item['url']
  147. );
  148. }
  149. echo '</div>';
  150. echo $formToString;
  151. echo $table->return_table();
  152. Display::display_footer();