login_redirection.class.php 2.2 KB

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