categories_add_user.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. *
  5. * @package chamilo.plugin.ticket
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. api_protect_admin_script(true);
  9. $categoryId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  10. $projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : '';
  11. $categoryInfo = TicketManager::getCategory($categoryId);
  12. if (empty($categoryInfo)) {
  13. api_not_allowed(true);
  14. }
  15. $project = TicketManager::getProject($projectId);
  16. if (empty($project)) {
  17. api_not_allowed(true);
  18. }
  19. $form = new FormValidator('edit', 'post', api_get_self().'?id='.$categoryId.'&project_id='.$projectId);
  20. $form->addHeader($categoryInfo['name']);
  21. $users = UserManager::get_user_list([], ['firstname']);
  22. $users = array_column($users, 'complete_name', 'user_id');
  23. $form->addElement(
  24. 'advmultiselect',
  25. 'users',
  26. get_lang('Users'),
  27. $users,
  28. 'style="width: 280px;"'
  29. );
  30. $usersAdded = TicketManager::getUsersInCategory($categoryId);
  31. if (!empty($usersAdded)) {
  32. $usersAdded = array_column($usersAdded, 'user_id');
  33. }
  34. $form->setDefaults(['users' => $usersAdded]);
  35. // submit button
  36. $form->addButtonSave(get_lang('Save'));
  37. if ($form->validate()) {
  38. $values = $form->exportValues();
  39. TicketManager::deleteAllUserInCategory($categoryId);
  40. TicketManager::addUsersToCategory($categoryId, $values['users']);
  41. Display::addFlash(Display::return_message(get_lang('Updated')));
  42. header("Location: ".api_get_self()."?id=".$categoryId.'&project_id='.$projectId);
  43. exit;
  44. }
  45. $interbreadcrumb[] = array(
  46. 'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId,
  47. 'name' => get_lang('MyTickets')
  48. );
  49. $interbreadcrumb[] = array(
  50. 'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
  51. 'name' => get_lang('Settings')
  52. );
  53. $interbreadcrumb[] = array(
  54. 'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
  55. 'name' => get_lang('Projects')
  56. );
  57. $interbreadcrumb[] = array(
  58. 'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
  59. 'name' => $project->getName()
  60. );
  61. $interbreadcrumb[] = array(
  62. 'url' => api_get_path(WEB_CODE_PATH).'ticket/categories.php?project_id='.$projectId,
  63. 'name' => get_lang('Categories')
  64. );
  65. Display::display_header(get_lang('Users'));
  66. $form->display();