change_user_session.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file = 'admin';
  4. $cidReset = true;
  5. require_once '../inc/global.inc.php';
  6. $user_id = intval($_REQUEST['user_id']);
  7. $session_id = intval($_REQUEST['id_session']);
  8. if (empty($user_id) && empty($session_id)) {
  9. api_not_allowed(true);
  10. }
  11. SessionManager::protect_session_edit($session_id);
  12. if (api_is_platform_admin()) {
  13. $sessions = SessionManager::get_sessions_admin(array('order' => 'name'));
  14. } else {
  15. $sessions = SessionManager::get_sessions_by_general_coach(api_get_session_id());
  16. }
  17. $message = null;
  18. $session_to_select = array();
  19. foreach ($sessions as $session) {
  20. if ($session_id != $session['id']) {
  21. $session_to_select[$session['id']] = $session['name'];
  22. }
  23. }
  24. $session_name = api_get_session_name($session_id);
  25. $user_info = api_get_user_info($user_id);
  26. //Check if user was already moved
  27. $user_status = SessionManager::get_user_status_in_session($session_id, $user_id);
  28. if (isset($user_status['moved_to']) && $user_status['moved_to'] != 0 || $user_status['moved_status'] == SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION) {
  29. api_not_allowed(true);
  30. }
  31. $form = new FormValidator('change_user_session', 'post', api_get_self());
  32. $form->addElement('hidden', 'user_id', $user_id);
  33. $form->addElement('hidden', 'id_session', $session_id);
  34. $form->addElement('header', get_lang('ChangeUserSession'));
  35. $form->addElement('label', get_lang('User'), '<b>'.$user_info['complete_name'].'</b>');
  36. $form->addElement('label', get_lang('CurrentSession'), $session_name);
  37. $form->addElement('select', 'reason_id', get_lang('Action'), SessionManager::get_session_change_user_reasons(), array('id' => 'reason_id'));
  38. $form->addElement('select', 'new_session_id', get_lang('SessionDestination'), $session_to_select, array('id' => 'new_session_id'));
  39. $form->addElement('button', 'submit', get_lang('Change'));
  40. $content = $form->return_form();
  41. if ($form->validate()) {
  42. $values = $form->getSubmitValues();
  43. $result = SessionManager::change_user_session($values['user_id'], $values['id_session'], $values['new_session_id'], $values['reason_id']);
  44. if ($result) {
  45. $message = Display::return_message(get_lang('UserSessionWasChanged'));
  46. }
  47. header('Location: resume_session.php?id_session='.$values['id_session']);
  48. exit;
  49. }
  50. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  51. $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  52. $interbreadcrumb[] = array('url' => 'resume_session.php?id_session='.$session_id,'name' => get_lang('SessionOverview'));
  53. $interbreadcrumb[] = array('url' => '#','name' => get_lang('ChangeUserSession'));
  54. $htmlHeadXtra[] = '<script>
  55. $(document).ready(function() {
  56. $("#reason_id").change(function() {
  57. value = $(this).val();
  58. if (value == "'.SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION.'") {
  59. $("#new_session_id").parent().parent().hide();
  60. } else {
  61. $("#new_session_id").parent().parent().show();
  62. }
  63. });
  64. });
  65. </script>';
  66. $tpl = $app['template'];
  67. $tpl->assign('message', $message);
  68. $tpl->assign('content', $content);
  69. $tpl->display_one_col_template();