-
Notifications
You must be signed in to change notification settings - Fork 1
/
whoisonlinesession.php
executable file
·145 lines (132 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
<?php
/* For licensing terms, see /license.txt */
/**
* Shows who is online in a specific session
* @package chamilo.main
*/
include_once './main/inc/global.inc.php';
api_block_anonymous_users();
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
/**
* Header
* include the HTTP, HTML headers plus the top banner
*/
Display::display_header(get_lang('UserOnlineListSession'));
?>
<br /><br />
<table class="data_table" width="60%">
<tr class="tableName">
<td colspan="4">
<strong><?php echo get_lang('UserOnlineListSession'); ?></strong>
</td>
</tr>
<tr>
<th>
<?php echo get_lang('Name'); ?>
</th>
<th>
<?php echo get_lang('InCourse'); ?>
</th>
<th>
<?php echo get_lang('Email'); ?>
</th>
<th>
<?php echo get_lang('Chat'); ?>
</th>
</tr>
<?php
$session_is_coach = array();
if (isset($_user['user_id']) && $_user['user_id'] != '') {
$_user['user_id'] = intval($_user['user_id']);
$sql = "SELECT DISTINCT session.id,
name,
access_start_date,
access_end_date
FROM $tbl_session as session
INNER JOIN $tbl_session_course_user as srcru
ON srcru.user_id = ".$_user['user_id']." AND srcru.status=2
AND session.id = srcru.session_id
ORDER BY access_start_date, access_end_date, name";
$result = Database::query($sql);
while ($session = Database:: fetch_array($result)) {
$session_is_coach[$session['id']] = $session;
}
$sql = "SELECT DISTINCT session.id,
name,
access_start_date,
access_end_date
FROM $tbl_session as session
WHERE session.id_coach = ".$_user['user_id']."
ORDER BY access_start_date, access_end_date, name";
$result = Database::query($sql);
while ($session = Database:: fetch_array($result)) {
$session_is_coach[$session['id']] = $session;
}
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);
$students_online = array();
foreach ($session_is_coach as $session) {
$sql = "SELECT DISTINCT last_access.access_user_id,
last_access.access_date,
last_access.c_id,
last_access.access_session_id,
".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." as name,
user.email
FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS)." AS last_access
INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
ON user.user_id = last_access.access_user_id
WHERE access_session_id='".$session['id']."'
AND access_date >= '$current_date'
GROUP BY access_user_id";
$result = Database::query($sql);
while($user_list = Database::fetch_array($result)) {
$students_online[$user_list['access_user_id']] = $user_list;
}
}
if (count($students_online) > 0) {
foreach ($students_online as $student_online) {
echo "<tr>
<td>
";
echo $student_online['name'];
echo " </td>
<td align='center'>
";
$courseInfo = api_get_course_info_by_id($student_online['c_id']);
echo $courseInfo['title'];
echo " </td>
<td align='center'>
";
if (!empty($student_online['email'])) {
echo $student_online['email'];
} else {
echo get_lang('NoEmail');
}
echo " </td>
<td align='center'>
";
echo '<a href="main/chat/chat.php?cidReq='.$courseInfo['code'].'&id_session='.$student_online['access_session_id'].'"> -> </a>';
echo " </td>
</tr>
";
}
} else {
echo ' <tr>
<td colspan="4">
'.get_lang('NoOnlineStudents').'
</td>
</tr>
';
}
}
?>
</table>
<?php
Display::display_footer();