categories_add_user.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. *
  5. * @package chamilo.plugin.ticket
  6. */
  7. $cidReset = true;
  8. require_once '../config.php';
  9. $plugin = TicketPlugin::create();
  10. api_protect_admin_script(true);
  11. $categoryId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  12. if (empty($categoryId)) {
  13. api_not_allowed(true);
  14. }
  15. $form = new FormValidator('edit', 'post', api_get_self().'?id='.$categoryId);
  16. $users = UserManager::get_user_list([], ['firstname']);
  17. $users = array_column($users, 'complete_name', 'user_id');
  18. $form->addElement(
  19. 'advmultiselect',
  20. 'users',
  21. get_lang('Users'),
  22. $users,
  23. 'style="width: 280px;"'
  24. );
  25. $usersAdded = TicketManager::getUsersInCategory($categoryId);
  26. if (!empty($usersAdded)) {
  27. $usersAdded = array_column($usersAdded, 'user_id');
  28. }
  29. $form->setDefaults(['users' => $usersAdded]);
  30. // submit button
  31. $form->addButtonSave(get_lang('Save'));
  32. if ($form->validate()) {
  33. $values = $form->exportValues();
  34. TicketManager::deleteAllUserInCategory($categoryId);
  35. TicketManager::addUsersToCategory($categoryId, $values['users']);
  36. Display::addFlash(Display::return_message(get_lang('Updated')));
  37. header("Location: ".api_get_self()."?id=".$categoryId);
  38. exit;
  39. }
  40. $interbreadcrumb[] = array('url' => 'myticket.php', 'name' => $plugin->get_lang('MyTickets'));
  41. $interbreadcrumb[] = array('url' => 'categories.php', 'name' => get_lang('Categories'));
  42. Display::display_header();
  43. $form->display();