status.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. * @package chamilo.plugin.ticket
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_protect_admin_script(true);
  11. $toolName = get_lang('Status');
  12. $libPath = api_get_path(LIBRARY_PATH);
  13. $webLibPath = api_get_path(WEB_LIBRARY_PATH);
  14. $this_section = 'tickets';
  15. Session::erase('this_section');
  16. $table = new SortableTable(
  17. 'TicketProject',
  18. array('TicketManager', 'getStatusCount'),
  19. array('TicketManager', 'getStatusAdminList'),
  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[] = array(
  29. 'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
  30. 'name' => get_lang('MyTickets')
  31. );
  32. $interbreadcrumb[] = array(
  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('ThisItemIsRelatedToOtherTickets'), 'warning'));
  44. }
  45. header("Location: ".api_get_self());
  46. exit;
  47. break;
  48. case 'add':
  49. $toolName = get_lang('Add');
  50. $interbreadcrumb[] = array(
  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[] = array(
  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($_GET['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($_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. $id = $row['id'];
  110. $code = $row['code'];
  111. $result = Display::url(
  112. Display::return_icon('edit.png', get_lang('Edit')),
  113. api_get_self()."?action=edit&id={$id}"
  114. );
  115. if (!in_array($code, TicketManager::getDefaultStatusList())) {
  116. $result .= Display::url(
  117. Display::return_icon('delete.png', get_lang('Delete')),
  118. api_get_self()."?action=delete&id={$id}"
  119. );
  120. }
  121. return $result;
  122. }
  123. $table->set_header(0, '', false);
  124. $table->set_header(1, get_lang('Title'), false);
  125. $table->set_header(2, get_lang('Description'), true, array("style" => "width:200px"));
  126. $table->set_header(3, get_lang('Actions'), true);
  127. $table->set_column_filter('3', 'modify_filter');
  128. Display::display_header($toolName);
  129. $items = [
  130. [
  131. 'url' => 'status.php?action=add',
  132. 'content' => Display::return_icon('new_folder.png', null, null, ICON_SIZE_MEDIUM)
  133. ]
  134. ];
  135. echo Display::actions($items);
  136. echo $formToString;
  137. echo $table->return_table();
  138. Display::display_footer();