Skip to content

Commit d400657

Browse files
committed
Fix who is online access not it will check chamilo settings
api_get_setting('showonline', 'world') api_get_setting('showonline', 'users') api_get_setting('showonline', 'course')
1 parent 95433c0 commit d400657

File tree

3 files changed

+56
-45
lines changed

3 files changed

+56
-45
lines changed

main/inc/ajax/online.ajax.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
echo returnNotificationMenu();
1313
break;
1414
case 'load_online_user':
15+
$access = accessToWhoIsOnline();
16+
17+
if (!$access) {
18+
exit;
19+
}
1520
$images_to_show = MAX_ONLINE_USERS;
1621
$page = intval($_REQUEST['online_page_nr']);
1722
$max_page = ceil(who_is_online_count() / $images_to_show);
1823
$page_rows = ($page - 1) * MAX_ONLINE_USERS;
19-
2024
if (!empty($max_page) && $page <= $max_page) {
2125
if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
2226
$user_list = who_is_online_in_this_course(

main/inc/lib/banner.lib.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,25 @@ function return_logo($theme = '')
200200
);
201201
}
202202

203+
/**
204+
* Check if user have access to "who is online" page
205+
* @return bool
206+
*/
207+
function accessToWhoIsOnline()
208+
{
209+
$user_id = api_get_user_id();
210+
$course_id = api_get_course_int_id();
211+
$access = false;
212+
if ((api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
213+
(api_get_setting('showonline', 'users') == 'true' && $user_id) ||
214+
(api_get_setting('showonline', 'course') == 'true' && $user_id && $course_id)
215+
) {
216+
$access = true;
217+
}
218+
219+
return $access;
220+
}
221+
203222
/**
204223
* Return HTML string of a list as <li> items.
205224
*
@@ -208,19 +227,11 @@ function return_logo($theme = '')
208227
function returnNotificationMenu()
209228
{
210229
$courseInfo = api_get_course_info();
211-
$course_id = 0;
212-
if (!empty($courseInfo)) {
213-
$course_id = $courseInfo['code'];
214-
}
215-
216230
$user_id = api_get_user_id();
217231
$sessionId = api_get_session_id();
218232
$html = '';
219233

220-
if ((api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
221-
(api_get_setting('showonline', 'users') == 'true' && $user_id) ||
222-
(api_get_setting('showonline', 'course') == 'true' && $user_id && $course_id)
223-
) {
234+
if (accessToWhoIsOnline()) {
224235
$number = getOnlineUsersCount();
225236
$number_online_in_course = getOnlineUsersInCourseCount($user_id, $courseInfo);
226237

whoisonline.php

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
$cidReset = true;
99
}
1010

11-
// including necessary files
1211
require_once './main/inc/global.inc.php';
1312

1413
if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
@@ -20,48 +19,45 @@
2019
$whoisonline_list = '';
2120
$social_search = '';
2221
$userId = api_get_user_id();
22+
$access = accessToWhoIsOnline();
2323

24-
// This if statement prevents users accessing the who's online feature when it has been disabled.
25-
if ((api_get_setting('showonline', 'world') == 'true' && !$userId) ||
26-
((api_get_setting('showonline', 'users') == 'true' ||
27-
api_get_setting('showonline', 'course') == 'true') && $userId)
28-
) {
29-
if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
30-
$user_list = who_is_online_in_this_course(
31-
0,
32-
MAX_ONLINE_USERS,
33-
api_get_user_id(),
34-
api_get_setting('time_limit_whosonline'),
35-
$_GET['cidReq']
36-
);
37-
} else {
38-
$user_list = who_is_online(0, MAX_ONLINE_USERS);
39-
}
24+
if (!$access) {
25+
api_not_allowed(true);
26+
}
4027

41-
if ($user_list) {
42-
if (!isset($_GET['id'])) {
43-
if (api_get_setting('allow_social_tool') == 'true') {
44-
if (!api_is_anonymous()) {
45-
$query = isset($_GET['q']) ? $_GET['q'] : null;
46-
$social_search = UserManager::get_search_form($query);
47-
}
28+
if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
29+
$user_list = who_is_online_in_this_course(
30+
0,
31+
MAX_ONLINE_USERS,
32+
api_get_user_id(),
33+
api_get_setting('time_limit_whosonline'),
34+
$_GET['cidReq']
35+
);
36+
} else {
37+
$user_list = who_is_online(0, MAX_ONLINE_USERS);
38+
}
39+
40+
if ($user_list) {
41+
if (!isset($_GET['id'])) {
42+
if (api_get_setting('allow_social_tool') == 'true') {
43+
if (!api_is_anonymous()) {
44+
$query = isset($_GET['q']) ? $_GET['q'] : null;
45+
$social_search = UserManager::get_search_form($query);
4846
}
49-
$social_right_content .= SocialManager::display_user_list($user_list);
5047
}
48+
$social_right_content .= SocialManager::display_user_list($user_list);
5149
}
50+
}
5251

53-
$whoisonline_list .= SocialManager::display_user_list($user_list);
52+
$whoisonline_list .= SocialManager::display_user_list($user_list);
5453

55-
if (isset($_GET['id'])) {
56-
if (api_get_setting('allow_social_tool') == 'true' && api_user_is_login()) {
57-
header("Location: ".api_get_path(WEB_CODE_PATH)."social/profile.php?u=".intval($_GET['id']));
58-
exit;
59-
} else {
60-
$social_right_content .= SocialManager::display_individual_user($_GET['id']);
61-
}
54+
if (isset($_GET['id'])) {
55+
if (api_get_setting('allow_social_tool') == 'true' && api_user_is_login()) {
56+
header("Location: ".api_get_path(WEB_CODE_PATH)."social/profile.php?u=".intval($_GET['id']));
57+
exit;
58+
} else {
59+
$social_right_content .= SocialManager::display_individual_user($_GET['id']);
6260
}
63-
} else {
64-
api_not_allowed(true);
6561
}
6662

6763
$tpl = new Template(get_lang('UsersOnLineList'));

0 commit comments

Comments
 (0)