Refactor whoisonlinesession, check the current session see BT#14262

pull/2539/head
jmontoyaa 8 years ago
parent cf3373de42
commit 507e2369b0
  1. 59
      whoisonlinesession.php

@ -18,6 +18,10 @@ if (empty($userId)) {
$sessionId = api_get_session_id();
$courseId = api_get_course_int_id();
if (empty($sessionId)) {
api_not_allowed(true);
}
$allow = api_is_platform_admin(true) ||
api_is_coach($sessionId, $courseId, false) ||
SessionManager::get_user_status_in_course_session(api_get_user_id(), $courseId, $sessionId) == 2;
@ -26,19 +30,13 @@ if (!$allow) {
api_not_allowed(true);
}
/**
* Header
* include the HTTP, HTML headers plus the top banner.
*/
Display::display_header(get_lang('UserOnlineListSession'));
$sessionInfo = api_get_session_info($sessionId);
Display::display_header(get_lang('UsersOnLineList'));
echo Display::page_header($sessionInfo['name']);
?>
<br />
<table class="data_table">
<tr class="tableName">
<td colspan="4">
<strong><?php echo get_lang('UserOnlineListSession'); ?></strong>
</td>
</tr>
<tr>
<th>
<?php echo get_lang('Name'); ?>
@ -46,9 +44,6 @@ Display::display_header(get_lang('UserOnlineListSession'));
<th>
<?php echo get_lang('InCourse'); ?>
</th>
<th>
<?php echo get_lang('Email'); ?>
</th>
<th>
<?php echo get_lang('Chat'); ?>
</th>
@ -72,14 +67,12 @@ if (api_is_multiple_url_enabled()) {
$online_time = time() - $time_limit * 60;
$current_date = api_get_utc_datetime($online_time);
$students_online = [];
$studentsOnline = [];
$sql = "SELECT DISTINCT last_access.login_user_id,
last_access.login_date,
last_access.c_id,
last_access.session_id,
".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." as name,
user.email
last_access.session_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
@ -92,31 +85,31 @@ $sql = "SELECT DISTINCT last_access.login_user_id,
$result = Database::query($sql);
while ($user_list = Database::fetch_array($result)) {
$students_online[$user_list['login_user_id']] = $user_list;
$studentsOnline[$user_list['login_user_id']] = $user_list;
}
if (count($students_online) > 0) {
foreach ($students_online as $student_online) {
if (count($studentsOnline) > 0) {
foreach ($studentsOnline as $student_online) {
$userInfo = api_get_user_info($student_online['login_user_id']);
if (empty($userInfo)) {
continue;
}
echo "<tr>
<td>
";
echo $student_online['name'];
echo $userInfo['complete_name_with_message_link'];
echo " </td>
<td>
";
$courseInfo = api_get_course_info_by_id($student_online['c_id']);
echo $courseInfo['title'];
echo " </td>
<td>
";
if (!empty($student_online['email'])) {
echo $student_online['email'];
} else {
echo get_lang('NoEmail');
}
echo " </td>
<td>
";
echo Display::url(
$courseInfo['title'],
$courseInfo['course_public_url'].'?id_session='.$student_online['session_id'],
['target' => '_blank']
);
echo " </td>";
echo "<td>";
echo '<a
target="_blank"
href="main/chat/chat.php?cidReq='.$courseInfo['code'].'&id_session='.$student_online['session_id'].'"> -> </a>';

Loading…
Cancel
Save