login_redirection.class.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class LoginRedirection
  5. * When a user login, the function LoginRedirection::redirect is called.
  6. * When this function is called all user info has already
  7. * been registered in $_user session variable.
  8. * */
  9. class LoginRedirection
  10. {
  11. //checks user status and redirect him through custom page if setting is enabled
  12. public static function redirect()
  13. {
  14. global $param;
  15. $param = isset($param) ? $param : '';
  16. $redirect_url = '';
  17. if (api_is_student() && !api_get_setting('student_page_after_login') == '') {
  18. $redirect_url = html_entity_decode(api_get_setting('student_page_after_login'));
  19. if ($redirect_url[0] == "/") {
  20. $redirect_url = substr(api_get_path(WEB_PATH), 0, -1).$redirect_url;
  21. }
  22. }
  23. if (api_is_teacher() && !api_get_setting('teacher_page_after_login') == '') {
  24. $redirect_url = html_entity_decode(api_get_setting('teacher_page_after_login'));
  25. if ($redirect_url[0] == "/") {
  26. $redirect_url = substr(api_get_path(WEB_PATH), 0, -1).$redirect_url;
  27. }
  28. }
  29. if (api_is_drh() && !api_get_setting('drh_page_after_login') == '') {
  30. $redirect_url = html_entity_decode(api_get_setting('drh_page_after_login'));
  31. if ($redirect_url[0] == "/") {
  32. $redirect_url = substr(api_get_path(WEB_PATH), 0, -1).$redirect_url;
  33. }
  34. }
  35. if (api_is_session_admin() && !api_get_setting('sessionadmin_page_after_login') == '') {
  36. $redirect_url = html_entity_decode(api_get_setting('sessionadmin_page_after_login'));
  37. if ($redirect_url[0] == "/") {
  38. $redirect_url = substr(api_get_path(WEB_PATH), 0, -1).$redirect_url;
  39. }
  40. }
  41. if (!empty($redirect_url)) {
  42. header('Location: '.$redirect_url.$param);
  43. exit();
  44. }
  45. // Custom pages
  46. if (CustomPages::enabled()) {
  47. CustomPages::display(CustomPages::INDEX_LOGGED);
  48. }
  49. header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param);
  50. exit();
  51. }
  52. }