loginredirection.lib.php 2.1 KB

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