categories.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. $cidReset = true;
  8. // needed in order to load the plugin lang variables
  9. $course_plugin = 'ticket';
  10. require_once '../config.php';
  11. $plugin = TicketPlugin::create();
  12. api_protect_admin_script(true);
  13. $tool_name = $plugin->get_lang('LastEdit');
  14. $libPath = api_get_path(LIBRARY_PATH);
  15. $webLibPath = api_get_path(WEB_LIBRARY_PATH);
  16. $this_section = 'tickets';
  17. unset($_SESSION['this_section']);
  18. $table = new SortableTable(
  19. 'TicketCategories',
  20. array('TicketManager', 'getCategoriesCount'),
  21. array('TicketManager', 'getCategories'),
  22. 1
  23. );
  24. if ($table->per_page == 0) {
  25. $table->per_page = 20;
  26. }
  27. $formToString = '';
  28. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  29. if (isset($_GET['action'])) {
  30. global $table;
  31. $action = $_GET['action'];
  32. switch ($action) {
  33. case 'delete':
  34. TicketManager::deleteCategory($id);
  35. Display::addFlash(Display::return_message(get_lang('Deleted')));
  36. header("Location: ".api_get_self());
  37. break;
  38. case 'add':
  39. $url = api_get_self().'?action=add';
  40. $form = TicketManager::getCategoryForm($url);
  41. $formToString = $form->returnForm();
  42. if ($form->validate()) {
  43. $values =$form->getSubmitValues();
  44. $params = [
  45. 'name' => $values['name'],
  46. 'description' => $values['description'],
  47. 'total_tickets' => 0,
  48. 'sys_insert_user_id' => api_get_user_id(),
  49. 'sys_insert_datetime' => api_get_utc_datetime()
  50. ];
  51. TicketManager::addCategory($params);
  52. Display::addFlash(Display::return_message(get_lang('Added')));
  53. header("Location: ".api_get_self());
  54. exit;
  55. }
  56. break;
  57. case 'edit':
  58. $url = api_get_self().'?action=edit&id='.$id;
  59. $form = TicketManager::getCategoryForm($url);
  60. $cat = TicketManager::getCategory($_GET['id']);
  61. $form->setDefaults($cat);
  62. $formToString = $form->returnForm();
  63. if ($form->validate()) {
  64. $values =$form->getSubmitValues();
  65. $params = [
  66. 'name' => $values['name'],
  67. 'description' => $values['description'],
  68. 'sys_lastedit_datetime' => api_get_utc_datetime(),
  69. 'sys_lastedit_user_id' => api_get_user_id()
  70. ];
  71. $cat = TicketManager::updateCategory($_GET['id'], $params);
  72. Display::addFlash(Display::return_message(get_lang('Updated')));
  73. header("Location: ".api_get_self());
  74. exit;
  75. }
  76. break;
  77. default:
  78. break;
  79. }
  80. }
  81. $user_id = api_get_user_id();
  82. $isAdmin = api_is_platform_admin();
  83. /**
  84. * Build the modify-column of the table
  85. * @param int The user id
  86. * @param string URL params to add to table links
  87. * @param array Row of elements to alter
  88. * @return string Some HTML-code with modify-buttons
  89. */
  90. function modify_filter($id, $params, $row)
  91. {
  92. $result = Display::url(
  93. Display::return_icon('edit.png', get_lang('Edit')),
  94. "categories.php?action=edit&id={$row['id']}"
  95. );
  96. $result .= Display::url(
  97. Display::return_icon('user.png', get_lang('AssignUser')),
  98. "categories_add_user.php?id={$row['id']}"
  99. );
  100. $result .= Display::url(
  101. Display::return_icon('delete.png', get_lang('Delete')),
  102. "categories.php?action=delete&id={$row['id']}"
  103. );
  104. return $result;
  105. }
  106. $table->set_header(0, '', false);
  107. $table->set_header(1, $plugin->get_lang('Title'), false);
  108. $table->set_header(2, get_lang('Description'), true, array("style" => "width:200px"));
  109. $table->set_header(3, $plugin->get_lang('TotalTickets'), false);
  110. $table->set_header(4, get_lang('Actions'), true);
  111. $table->set_column_filter(4, 'modify_filter');
  112. $interbreadcrumb[] = array('url' => 'myticket.php', 'name' => $plugin->get_lang('MyTickets'));
  113. Display::display_header($plugin->get_lang('Categories'));
  114. $items = [
  115. [
  116. 'url' => 'categories.php?action=add',
  117. 'content' => Display::return_icon('new_folder.png', null, null, ICON_SIZE_MEDIUM),
  118. ]
  119. ];
  120. echo Display::actions($items);
  121. echo $formToString;
  122. echo $table->return_table();
  123. Display::display_footer();