categories_add_user.php 2.2 KB

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