|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
use ChamiloSession as Session; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Send a redirect to the user agent and exist. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Laurent Opprecht <[email protected]> for the Univesity of Geneva |
|
10
|
|
|
*/ |
|
11
|
|
|
class Redirect |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Returns the result of api_get_path() (a web path to the root of Chamilo). |
|
15
|
|
|
* |
|
16
|
|
|
* @return string |
|
17
|
|
|
*/ |
|
18
|
|
|
public static function www() |
|
19
|
|
|
{ |
|
20
|
|
|
return api_get_path(WEB_PATH); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Checks whether the given URL contains "http". If not, prepend the web |
|
25
|
|
|
* root of Chamilo and send the browser there (HTTP redirect). |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $url |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function go($url = '') |
|
30
|
|
|
{ |
|
31
|
|
|
if (empty($url)) { |
|
32
|
|
|
self::session_request_uri(); |
|
33
|
|
|
$www = self::www(); |
|
34
|
|
|
self::navigate($www); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$is_full_uri = (0 === strpos($url, 'http')); |
|
38
|
|
|
if ($is_full_uri) { |
|
39
|
|
|
self::navigate($url); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$url = self::www().$url; |
|
43
|
|
|
self::navigate($url); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Redirect to the current session's "request uri" if it is defined, or |
|
48
|
|
|
* check sso_referer, user's role and page_after_login settings to send |
|
49
|
|
|
* the user to some predefined URL. |
|
50
|
|
|
* |
|
51
|
|
|
* @param bool Whether the user just logged in (in this case, use page_after_login rules) |
|
52
|
|
|
* @param int The user_id, if defined. Otherwise just send to where the page_after_login setting says |
|
53
|
|
|
*/ |
|
54
|
|
|
public static function session_request_uri($logging_in = false, $userInfo = null) |
|
55
|
|
|
{ |
|
56
|
|
|
$no_redirection = isset($_SESSION['noredirection']) ? $_SESSION['noredirection'] : false; |
|
57
|
|
|
|
|
58
|
|
|
if ($no_redirection) { |
|
59
|
|
|
unset($_SESSION['noredirection']); |
|
60
|
|
|
|
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$url = isset($_SESSION['request_uri']) ? Security::remove_XSS($_SESSION['request_uri']) : ''; |
|
65
|
|
|
unset($_SESSION['request_uri']); |
|
66
|
|
|
|
|
67
|
|
|
$afterLogin = Session::read('redirect_after_not_allow_page'); |
|
68
|
|
|
|
|
69
|
|
|
if (!empty($afterLogin) && isset($_GET['redirect_after_not_allow_page'])) { |
|
70
|
|
|
Session::erase('redirect_after_not_allow_page'); |
|
71
|
|
|
self::navigate($afterLogin); |
|
72
|
|
|
} |
|
73
|
|
|
if (!empty($url)) { |
|
74
|
|
|
self::navigate($url); |
|
75
|
|
|
} elseif ($logging_in || |
|
76
|
|
|
(isset($_REQUEST['sso_referer']) && !empty($_REQUEST['sso_referer'])) |
|
77
|
|
|
) { |
|
78
|
|
|
if (isset($userInfo) && !empty($userInfo)) { |
|
79
|
|
|
$userId = $userInfo['user_id']; |
|
80
|
|
|
$allow = ('true' === api_get_setting('workflows.plugin_redirection_enabled')); |
|
81
|
|
|
if ($allow) { |
|
82
|
|
|
RedirectionPlugin::redirectUser($userId); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// Make sure we use the appropriate role redirection in case one has been defined |
|
86
|
|
|
$user_status = $userInfo['status']; |
|
87
|
|
|
switch ($user_status) { |
|
88
|
|
|
case COURSEMANAGER: |
|
89
|
|
|
$redir = api_get_setting('teacher_page_after_login'); |
|
90
|
|
|
if (!empty($redir)) { |
|
91
|
|
|
self::navigate(api_get_path(WEB_PATH).$redir); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
break; |
|
94
|
|
|
case STUDENT: |
|
95
|
|
|
$redir = api_get_setting('student_page_after_login'); |
|
96
|
|
|
if (!empty($redir)) { |
|
97
|
|
|
self::navigate(api_get_path(WEB_PATH).$redir); |
|
98
|
|
|
} |
|
99
|
|
|
break; |
|
100
|
|
|
case DRH: |
|
101
|
|
|
$redir = api_get_setting('drh_page_after_login'); |
|
102
|
|
|
if (!empty($redir)) { |
|
103
|
|
|
self::navigate(api_get_path(WEB_PATH).$redir); |
|
104
|
|
|
} |
|
105
|
|
|
break; |
|
106
|
|
|
case SESSIONADMIN: |
|
107
|
|
|
$redir = api_get_setting('sessionadmin_page_after_login'); |
|
108
|
|
|
if (!empty($redir)) { |
|
109
|
|
|
self::navigate(api_get_path(WEB_PATH).$redir); |
|
110
|
|
|
} |
|
111
|
|
|
break; |
|
112
|
|
|
default: |
|
113
|
|
|
break; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
$redirect = api_get_setting('redirect_admin_to_courses_list'); |
|
117
|
|
|
if ('true' !== $redirect) { |
|
118
|
|
|
// If the user is a platform admin, redirect to the main admin page |
|
119
|
|
|
if (api_is_multiple_url_enabled()) { |
|
|
|
|
|
|
120
|
|
|
// if multiple URLs are enabled, make sure he's admin of the |
|
121
|
|
|
// current URL before redirecting |
|
122
|
|
|
$url = api_get_current_access_url_id(); |
|
123
|
|
|
if (api_is_platform_admin_by_id($userId, $url)) { |
|
|
|
|
|
|
124
|
|
|
self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); |
|
125
|
|
|
} |
|
126
|
|
|
} else { |
|
127
|
|
|
// if no multiple URL, then it's enough to be platform admin |
|
128
|
|
|
if (api_is_platform_admin_by_id($userId)) { |
|
129
|
|
|
self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
$page_after_login = api_get_setting('page_after_login'); |
|
134
|
|
|
if (!empty($page_after_login)) { |
|
135
|
|
|
self::navigate(api_get_path(WEB_PATH).$page_after_login); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Sends the user to the web root of Chamilo (e.g. http://my.chamiloportal.com/ ). |
|
142
|
|
|
*/ |
|
143
|
|
|
public static function home() |
|
144
|
|
|
{ |
|
145
|
|
|
$www = self::www(); |
|
146
|
|
|
self::navigate($www); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Sends the user to the user_portal.php page. |
|
151
|
|
|
*/ |
|
152
|
|
|
public static function user_home() |
|
153
|
|
|
{ |
|
154
|
|
|
$www = self::www(); |
|
155
|
|
|
self::navigate("$www/user_portal.php"); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Redirects the user to a given URL through the header('location: ...') function. |
|
160
|
|
|
* |
|
161
|
|
|
* @param string $url |
|
162
|
|
|
*/ |
|
163
|
|
|
protected static function navigate($url) |
|
164
|
|
|
{ |
|
165
|
|
|
session_write_close(); //should not be needed |
|
166
|
|
|
header("Location: $url"); |
|
167
|
|
|
exit; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|