forked from chamilo/chamilo-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhoisonlinesession.php
executable file
·150 lines (125 loc) · 3.95 KB
/
whoisonlinesession.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/* For licensing terms, see /license.txt */
/**
* Shows who is online in a specific session.
*
* @package chamilo.main
*/
require_once './main/inc/global.inc.php';
api_block_anonymous_users();
$userId = api_get_user_id();
if (empty($userId)) {
api_not_allowed(true);
}
$sessionId = api_get_session_id();
if (empty($sessionId)) {
api_not_allowed(true);
}
$allow = api_is_platform_admin(true) ||
api_is_coach($sessionId, null, false) ||
SessionManager::isUserSubscribedAsStudent($sessionId, api_get_user_id());
if (!$allow) {
api_not_allowed(true);
}
$maxNumberItems = 20;
$sessionInfo = api_get_session_info($sessionId);
Display::display_header(get_lang('Online users list'));
echo Display::page_header($sessionInfo['name']);
function getUsers(
$from,
$numberItems,
$column,
$direction,
$getCount = false
) {
$sessionId = api_get_session_id();
$from = (int) $from;
$numberItems = (int) $numberItems;
$urlCondition = '';
$urlJoin = '';
if (api_is_multiple_url_enabled()) {
$accessUrlUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$urlId = api_get_current_access_url_id();
$urlJoin = " INNER JOIN $accessUrlUser a ON (a.user_id = user.id) ";
$urlCondition = " AND a.access_url_id = $urlId ";
}
if (empty($time_limit)) {
$time_limit = api_get_setting('time_limit_whosonline');
} else {
$time_limit = 60;
}
$online_time = time() - $time_limit * 60;
$current_date = api_get_utc_datetime($online_time);
if ($getCount) {
$sql = "SELECT
count(DISTINCT last_access.login_user_id) count
FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE)." AS last_access
INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
ON user.id = last_access.login_user_id
$urlJoin
WHERE
session_id ='".$sessionId."' AND
login_date >= '$current_date'
$urlCondition";
$result = Database::query($sql);
$result = Database::fetch_array($result);
return $result['count'];
}
$sql = "SELECT DISTINCT
last_access.login_user_id,
last_access.c_id
FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE)." AS last_access
INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
ON user.id = last_access.login_user_id
$urlJoin
WHERE
session_id ='".$sessionId."' AND
login_date >= '$current_date'
$urlCondition
GROUP BY login_user_id
LIMIT $from, $numberItems";
$studentsOnline = [];
$result = Database::query($sql);
while ($user_list = Database::fetch_array($result)) {
$studentsOnline[$user_list['login_user_id']] = $user_list;
}
return $studentsOnline;
}
function getCountUsers()
{
return getUsers(0, 0, 0, 0, true);
}
$table = new SortableTable(
'users',
'getCountUsers',
'getUsers',
'1',
$maxNumberItems
);
$table->set_header(0, get_lang('Name'), false);
$table->set_header(1, get_lang('In course'), false);
$table->set_column_filter(0, 'user_filter');
$table->set_column_filter(1, 'course_filter');
$table->display();
function user_filter($userId, $urlParams, $row)
{
$userInfo = api_get_user_info($userId);
return $userInfo['complete_name_with_message_link'];
}
function course_filter($courseId, $urlParams, $row)
{
$sessionId = api_get_session_id();
$courseInfo = api_get_course_info_by_id($courseId);
return Display::url(
$courseInfo['title'],
$courseInfo['course_public_url'].'?id_session='.$sessionId,
['target' => '_blank']
).
' '.
Display::url(
get_lang('Chat'),
'main/chat/chat.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId,
['target' => '_blank', 'class' => 'btn btn-primary']
);
}
Display::display_footer();