|
|
|
|
@ -1,18 +1,27 @@ |
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
/** |
|
|
|
|
* Send a redirect to the user agent and exist |
|
|
|
|
* |
|
|
|
|
* @license see /license.txt |
|
|
|
|
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
|
|
|
|
*/ |
|
|
|
|
class Redirect { |
|
|
|
|
|
|
|
|
|
static function www() { |
|
|
|
|
class Redirect |
|
|
|
|
{ |
|
|
|
|
/** |
|
|
|
|
* Returns the result of api_get_path() (a web path to the root of Chamilo) |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public static function www() |
|
|
|
|
{ |
|
|
|
|
return Uri::www(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static function go($url = '') { |
|
|
|
|
/** |
|
|
|
|
* Checks whether the given URL contains "http". If not, prepend the web |
|
|
|
|
* root of Chamilo and send the browser there (HTTP redirect) |
|
|
|
|
* @param string $url |
|
|
|
|
*/ |
|
|
|
|
public static function go($url = '') |
|
|
|
|
{ |
|
|
|
|
if (empty($url)) { |
|
|
|
|
Redirect::session_request_uri(); |
|
|
|
|
$www = self::www(); |
|
|
|
|
@ -29,10 +38,14 @@ class Redirect { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Redirect to the session "request uri" if it exists. |
|
|
|
|
* Redirect to the current session's "request uri" if it is defined, or |
|
|
|
|
* check sso_referer, user's role and page_after_login settings to send |
|
|
|
|
* the user to some predefined URL |
|
|
|
|
* @param bool Whether the user just logged in (in this case, use page_after_login rules) |
|
|
|
|
* @param int The user_id, if defined. Otherwise just send to where the page_after_login setting says |
|
|
|
|
*/ |
|
|
|
|
static function session_request_uri($logging_in = false, $user_id = null) { |
|
|
|
|
public static function session_request_uri($logging_in = false, $user_id = null) |
|
|
|
|
{ |
|
|
|
|
$no_redirection = isset($_SESSION['noredirection']) ? $_SESSION['noredirection'] : false; |
|
|
|
|
|
|
|
|
|
if ($no_redirection) { |
|
|
|
|
@ -78,6 +91,20 @@ class Redirect { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// If the user is a platform admin, redirect to the main admin page |
|
|
|
|
if (api_is_multiple_url_enabled()) { |
|
|
|
|
// if multiple URLs are enabled, make sure he's admin of the |
|
|
|
|
// current URL before redirecting |
|
|
|
|
$url = api_get_current_access_url_id(); |
|
|
|
|
if (api_is_platform_admin_by_id($user_id, $url)) { |
|
|
|
|
self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// if no multiple URL, then it's enough to be platform admin |
|
|
|
|
if (api_is_platform_admin_by_id($user_id)) { |
|
|
|
|
self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$page_after_login = api_get_setting('page_after_login'); |
|
|
|
|
if (!empty($page_after_login)) { |
|
|
|
|
self::navigate(api_get_path(WEB_PATH) . $page_after_login); |
|
|
|
|
@ -85,16 +112,28 @@ class Redirect { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static function home() { |
|
|
|
|
/** |
|
|
|
|
* Sends the user to the web root of Chamilo (e.g. http://my.chamiloportal.com/ ) |
|
|
|
|
*/ |
|
|
|
|
public static function home() |
|
|
|
|
{ |
|
|
|
|
$www = self::www(); |
|
|
|
|
self::navigate($www); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static function user_home() { |
|
|
|
|
/** |
|
|
|
|
* Sends the user to the user_portal.php page |
|
|
|
|
*/ |
|
|
|
|
public static function user_home() |
|
|
|
|
{ |
|
|
|
|
$www = self::www(); |
|
|
|
|
self::navigate("$www/user_portal.php"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Redirects the user to a given URL through the header('location: ...') function |
|
|
|
|
* @param $url |
|
|
|
|
*/ |
|
|
|
|
protected static function navigate($url) |
|
|
|
|
{ |
|
|
|
|
$url = Security::remove_XSS($url); |
|
|
|
|
|