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