change_user_session.php 3.1 KB

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