chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | /* For licensing terms, see /license.txt */ |
||
| 4 | |||
| 5 | use ChamiloSession as Session; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Code library for showing Who is online. |
||
| 9 | * |
||
| 10 | * @author Istvan Mandak, principal author |
||
| 11 | * @author Denes Nagy, principal author |
||
| 12 | * @author Bart Mollet |
||
| 13 | * @author Roan Embrechts, cleaning and bugfixing |
||
| 14 | * Insert a login reference for the current user into the track_e_online stats |
||
| 15 | * table. This table keeps trace of the last login. Nothing else matters (we |
||
| 16 | * don't keep traces of anything older). |
||
| 17 | * |
||
| 18 | * @param int user id |
||
| 19 | */ |
||
| 20 | function LoginCheck($uid) |
||
| 21 | { |
||
| 22 | $uid = (int) $uid; |
||
| 23 | if (!empty($uid)) { |
||
| 24 | $online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
||
| 25 | $_course = api_get_course_info(); |
||
| 26 | $user_ip = ''; |
||
| 27 | if (!empty($_SERVER['REMOTE_ADDR'])) { |
||
| 28 | $user_ip = Database::escape_string(api_get_real_ip()); |
||
| 29 | } |
||
| 30 | |||
| 31 | $login_date = api_get_utc_datetime(); |
||
| 32 | $access_url_id = 1; |
||
| 33 | if (api_get_multiple_access_url() && api_get_current_access_url_id() != -1) { |
||
| 34 | $access_url_id = api_get_current_access_url_id(); |
||
| 35 | } |
||
| 36 | $session_id = api_get_session_id(); |
||
| 37 | $cid = 0; |
||
| 38 | if (is_array($_course) && count($_course) > 0 && !empty($_course['real_id'])) { |
||
| 39 | $cid = intval($_course['real_id']); |
||
| 40 | } |
||
| 41 | $query = "SELECT login_id FROM $online_table WHERE login_user_id = $uid"; |
||
| 42 | $resLogin = Database::query($query); |
||
| 43 | if (Database::num_rows($resLogin) > 0) { |
||
| 44 | $query = "UPDATE $online_table SET |
||
| 45 | login_date = '$login_date', |
||
| 46 | user_ip = '$user_ip', |
||
| 47 | c_id = $cid, |
||
| 48 | session_id = $session_id, |
||
| 49 | access_url_id = $access_url_id |
||
| 50 | WHERE login_user_id = $uid"; |
||
| 51 | Database::query($query); |
||
| 52 | } else { |
||
| 53 | $query = "INSERT $online_table ( |
||
| 54 | login_user_id, |
||
| 55 | login_date, |
||
| 56 | user_ip, |
||
| 57 | c_id, |
||
| 58 | session_id, |
||
| 59 | access_url_id |
||
| 60 | ) values ( |
||
| 61 | $uid, |
||
| 62 | '$login_date', |
||
| 63 | '$user_ip', |
||
| 64 | $cid, |
||
| 65 | $session_id, |
||
| 66 | $access_url_id |
||
| 67 | )"; |
||
| 68 | Database::query($query); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param int $userId |
||
| 75 | */ |
||
| 76 | function preventMultipleLogin($userId) |
||
| 77 | { |
||
| 78 | $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
||
| 79 | $userId = (int) $userId; |
||
| 80 | if (api_get_setting('prevent_multiple_simultaneous_login') === 'true') { |
||
| 81 | if (!empty($userId) && !api_is_anonymous()) { |
||
| 82 | $isFirstLogin = Session::read('first_user_login'); |
||
| 83 | $currentIp = Session::read('current_ip'); |
||
| 84 | $differentIp = false; |
||
| 85 | if (!empty($currentIp) && api_get_real_ip() !== $currentIp) { |
||
| 86 | //$isFirstLogin = null; |
||
| 87 | $differentIp = true; |
||
| 88 | } |
||
| 89 | |||
| 90 | if (empty($isFirstLogin)) { |
||
| 91 | $sql = "SELECT login_id FROM $table |
||
| 92 | WHERE login_user_id = $userId |
||
| 93 | LIMIT 1"; |
||
| 94 | |||
| 95 | $result = Database::query($sql); |
||
| 96 | $loginData = []; |
||
| 97 | if (Database::num_rows($result)) { |
||
| 98 | $loginData = Database::fetch_array($result); |
||
| 99 | } |
||
| 100 | |||
| 101 | $userIsReallyOnline = user_is_online($userId); |
||
| 102 | |||
| 103 | // Trying double login. |
||
| 104 | if ((!empty($loginData) && $userIsReallyOnline) || $differentIp) { |
||
| 105 | session_regenerate_id(); |
||
| 106 | Session::destroy(); |
||
| 107 | header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=multiple_connection_not_allowed'); |
||
| 108 | exit; |
||
| 109 | } else { |
||
| 110 | // First time |
||
| 111 | Session::write('first_user_login', 1); |
||
| 112 | Session::write('current_ip', api_get_real_ip()); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * This function handles the logout and is called whenever there is a $_GET['logout']. |
||
| 121 | * |
||
| 122 | * @param int $user_id |
||
| 123 | * @param bool $logout_redirect |
||
| 124 | * |
||
| 125 | * @author Fernando P. García <[email protected]> |
||
| 126 | */ |
||
| 127 | function online_logout($user_id = null, $logout_redirect = false) |
||
| 128 | { |
||
| 129 | global $extAuthSource; |
||
| 130 | |||
| 131 | // Database table definition |
||
| 132 | $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
||
| 133 | |||
| 134 | if (empty($user_id)) { |
||
| 135 | $user_id = isset($_GET['uid']) ? intval($_GET['uid']) : 0; |
||
| 136 | } |
||
| 137 | |||
| 138 | // Changing global chat status to offline |
||
| 139 | if (api_is_global_chat_enabled()) { |
||
| 140 | $chat = new Chat(); |
||
| 141 | $chat->setUserStatus(0); |
||
| 142 | } |
||
| 143 | |||
| 144 | $chat = new Chat(); |
||
| 145 | $chat->close(); |
||
| 146 | |||
| 147 | // selecting the last login of the user |
||
| 148 | $sql = "SELECT login_id, login_date |
||
| 149 | FROM $tbl_track_login |
||
| 150 | WHERE login_user_id = $user_id |
||
| 151 | ORDER BY login_date DESC |
||
| 152 | LIMIT 0,1"; |
||
| 153 | $q_last_connection = Database::query($sql); |
||
| 154 | $i_id_last_connection = 0; |
||
| 155 | if (Database::num_rows($q_last_connection) > 0) { |
||
| 156 | $i_id_last_connection = Database::result($q_last_connection, 0, "login_id"); |
||
| 157 | } |
||
| 158 | |||
| 159 | if (!isset($_SESSION['login_as']) && !empty($i_id_last_connection)) { |
||
| 160 | $current_date = api_get_utc_datetime(); |
||
| 161 | $sql = "UPDATE $tbl_track_login SET logout_date='".$current_date."' |
||
| 162 | WHERE login_id='$i_id_last_connection'"; |
||
| 163 | Database::query($sql); |
||
| 164 | } |
||
| 165 | $logInfo = [ |
||
| 166 | 'tool' => 'logout', |
||
| 167 | 'tool_id' => 0, |
||
| 168 | 'tool_id_detail' => 0, |
||
| 169 | ]; |
||
| 170 | Event::registerLog($logInfo); |
||
|
0 ignored issues
–
show
|
|||
| 171 | |||
| 172 | UserManager::loginDelete($user_id); |
||
| 173 | |||
| 174 | //the following code enables the use of an external logout function. |
||
| 175 | //example: define a $extAuthSource['ldap']['logout']="file.php" in configuration.php |
||
| 176 | // then a function called ldap_logout() inside that file |
||
| 177 | // (using *authent_name*_logout as the function name) and the following code |
||
| 178 | // will find and execute it |
||
| 179 | $uinfo = api_get_user_info($user_id); |
||
| 180 | if (($uinfo['auth_source'] != PLATFORM_AUTH_SOURCE) && is_array($extAuthSource)) { |
||
| 181 | if (is_array($extAuthSource[$uinfo['auth_source']])) { |
||
| 182 | $subarray = $extAuthSource[$uinfo['auth_source']]; |
||
| 183 | if (!empty($subarray['logout']) && file_exists($subarray['logout'])) { |
||
| 184 | require_once $subarray['logout']; |
||
| 185 | $logout_function = $uinfo['auth_source'].'_logout'; |
||
| 186 | if (function_exists($logout_function)) { |
||
| 187 | $logout_function($uinfo); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | // After logout redirect to |
||
| 194 | $url = api_get_path(WEB_PATH).'index.php'; |
||
| 195 | |||
| 196 | if ($logout_redirect && api_get_plugin_setting('azure_active_directory', 'enable') === 'true') { |
||
| 197 | if (ChamiloSession::read('_user_auth_source') === 'azure_active_directory') { |
||
| 198 | $activeDirectoryPlugin = AzureActiveDirectory::create(); |
||
| 199 | $azureLogout = $activeDirectoryPlugin->getUrl(AzureActiveDirectory::URL_TYPE_LOGOUT); |
||
| 200 | if (!empty($azureLogout)) { |
||
| 201 | $url = $azureLogout; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | if ('true' === api_get_plugin_setting('oauth2', 'enable') |
||
| 207 | && 'oauth2' === ChamiloSession::read('_user_auth_source') |
||
| 208 | && ChamiloSession::has('oauth2AccessToken') |
||
| 209 | ) { |
||
| 210 | if (!isset($oAuth2Plugin)) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 211 | $oAuth2Plugin = OAuth2::create(); |
||
| 212 | } |
||
| 213 | $logoutUrl = $oAuth2Plugin->getLogoutUrl(); |
||
| 214 | if (!empty($logoutUrl)) { |
||
| 215 | $url = $logoutUrl; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | api_delete_firstpage_parameter(); |
||
| 220 | // If we were using "login_as", make sure this doesn't stick to the session |
||
| 221 | if (Session::read('login_as') !== null) { |
||
| 222 | Session::erase('login_as'); |
||
| 223 | } |
||
| 224 | Session::erase('last_id'); |
||
| 225 | CourseChatUtils::exitChat($user_id); |
||
| 226 | session_regenerate_id(); |
||
| 227 | Session::destroy(); |
||
| 228 | |||
| 229 | $pluginKeycloak = api_get_plugin_setting('keycloak', 'tool_enable') === 'true'; |
||
| 230 | if ($pluginKeycloak && $uinfo['auth_source'] === 'keycloak') { |
||
| 231 | $pluginUrl = api_get_path(WEB_PLUGIN_PATH).'keycloak/start.php?slo'; |
||
| 232 | header('Location: '.$pluginUrl); |
||
| 233 | exit; |
||
| 234 | } |
||
| 235 | |||
| 236 | if ($uinfo['auth_source'] === CAS_AUTH_SOURCE && api_is_cas_activated()) { |
||
| 237 | require_once __DIR__.'/../../auth/cas/cas_var.inc.php'; |
||
| 238 | if (phpCas::isInitialized()) { |
||
| 239 | phpCAS::logout(); |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | if ($logout_redirect) { |
||
| 244 | header("Location: $url"); |
||
| 245 | exit; |
||
| 246 | } |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @param int $user_id |
||
| 251 | * |
||
| 252 | * @return bool |
||
| 253 | */ |
||
| 254 | function user_is_online($user_id) |
||
| 255 | { |
||
| 256 | $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
||
| 257 | $table_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 258 | |||
| 259 | $access_url_id = api_get_current_access_url_id(); |
||
| 260 | $time_limit = api_get_setting('time_limit_whosonline'); |
||
| 261 | |||
| 262 | $online_time = time() - $time_limit * 60; |
||
| 263 | $limit_date = api_get_utc_datetime($online_time); |
||
| 264 | $user_id = (int) $user_id; |
||
| 265 | |||
| 266 | $query = " SELECT login_user_id, login_date |
||
| 267 | FROM $track_online_table track |
||
| 268 | INNER JOIN $table_user u |
||
| 269 | ON (u.id=track.login_user_id) |
||
| 270 | WHERE |
||
| 271 | track.access_url_id = $access_url_id AND |
||
| 272 | login_date >= '".$limit_date."' AND |
||
| 273 | u.id = $user_id |
||
| 274 | LIMIT 1 "; |
||
| 275 | |||
| 276 | $result = Database::query($query); |
||
| 277 | if (Database::num_rows($result)) { |
||
| 278 | return true; |
||
| 279 | } |
||
| 280 | |||
| 281 | return false; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Gives a list of people online now (and in the last $valid minutes). |
||
| 286 | * |
||
| 287 | * @param $from |
||
| 288 | * @param $number_of_items |
||
| 289 | * @param null $column |
||
|
0 ignored issues
–
show
|
|||
| 290 | * @param null $direction |
||
|
0 ignored issues
–
show
|
|||
| 291 | * @param null $time_limit |
||
|
0 ignored issues
–
show
|
|||
| 292 | * @param bool $friends |
||
| 293 | * |
||
| 294 | * @return array|bool For each line, a list of user IDs and login dates, or FALSE on error or empty results |
||
| 295 | */ |
||
| 296 | function who_is_online( |
||
| 297 | $from, |
||
| 298 | $number_of_items, |
||
| 299 | $column = null, |
||
| 300 | $direction = null, |
||
| 301 | $time_limit = null, |
||
| 302 | $friends = false |
||
| 303 | ) { |
||
| 304 | // Time limit in seconds? |
||
| 305 | if (empty($time_limit)) { |
||
| 306 | $time_limit = api_get_setting('time_limit_whosonline'); |
||
| 307 | } else { |
||
| 308 | $time_limit = intval($time_limit); |
||
| 309 | } |
||
| 310 | |||
| 311 | $from = intval($from); |
||
| 312 | $number_of_items = intval($number_of_items); |
||
| 313 | |||
| 314 | if (empty($column)) { |
||
| 315 | $column = 'picture_uri'; |
||
| 316 | if ($friends) { |
||
| 317 | $column = 'login_date'; |
||
| 318 | } |
||
| 319 | } |
||
| 320 | |||
| 321 | if (empty($direction)) { |
||
| 322 | $direction = 'DESC'; |
||
| 323 | } else { |
||
| 324 | if (!in_array(strtolower($direction), ['asc', 'desc'])) { |
||
| 325 | $direction = 'DESC'; |
||
| 326 | } |
||
| 327 | } |
||
| 328 | |||
| 329 | $online_time = time() - $time_limit * 60; |
||
| 330 | $current_date = api_get_utc_datetime($online_time); |
||
| 331 | $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
||
| 332 | $friend_user_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 333 | $table_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 334 | |||
| 335 | if ($friends) { |
||
| 336 | // who friends from social network is online |
||
| 337 | $query = "SELECT DISTINCT login_user_id, login_date |
||
| 338 | FROM $track_online_table INNER JOIN $friend_user_table |
||
| 339 | ON (friend_user_id = login_user_id) |
||
| 340 | WHERE |
||
| 341 | login_date >= '".$current_date."' AND |
||
| 342 | friend_user_id <> '".api_get_user_id()."' AND |
||
| 343 | relation_type='".USER_RELATION_TYPE_FRIEND."' AND |
||
| 344 | user_id = '".api_get_user_id()."' |
||
| 345 | ORDER BY `$column` $direction |
||
| 346 | LIMIT $from, $number_of_items"; |
||
| 347 | } else { |
||
| 348 | $query = "SELECT DISTINCT login_user_id, login_date |
||
| 349 | FROM ".$track_online_table." e |
||
| 350 | INNER JOIN ".$table_user." u ON (u.id = e.login_user_id) |
||
| 351 | WHERE u.status != ".ANONYMOUS." AND login_date >= '".$current_date."' |
||
| 352 | ORDER BY `$column` $direction |
||
| 353 | LIMIT $from, $number_of_items"; |
||
| 354 | } |
||
| 355 | |||
| 356 | if (api_get_multiple_access_url()) { |
||
| 357 | $access_url_id = api_get_current_access_url_id(); |
||
| 358 | if ($access_url_id != -1) { |
||
| 359 | if ($friends) { |
||
| 360 | // friends from social network is online |
||
| 361 | $query = "SELECT distinct login_user_id, login_date |
||
| 362 | FROM $track_online_table track INNER JOIN $friend_user_table |
||
| 363 | ON (friend_user_id = login_user_id) |
||
| 364 | WHERE track.access_url_id = $access_url_id AND |
||
| 365 | login_date >= '".$current_date."' AND |
||
| 366 | friend_user_id <> '".api_get_user_id()."' AND |
||
| 367 | relation_type='".USER_RELATION_TYPE_FRIEND."' |
||
| 368 | ORDER BY `$column` $direction |
||
| 369 | LIMIT $from, $number_of_items"; |
||
| 370 | } else { |
||
| 371 | // all users online |
||
| 372 | $query = "SELECT login_user_id, login_date |
||
| 373 | FROM ".$track_online_table." track |
||
| 374 | INNER JOIN ".$table_user." u |
||
| 375 | ON (u.id=track.login_user_id) |
||
| 376 | WHERE u.status != ".ANONYMOUS." AND track.access_url_id = $access_url_id AND |
||
| 377 | login_date >= '".$current_date."' |
||
| 378 | ORDER BY `$column` $direction |
||
| 379 | LIMIT $from, $number_of_items"; |
||
| 380 | } |
||
| 381 | } |
||
| 382 | } |
||
| 383 | |||
| 384 | //This query will show all registered users. Only for dev purposes. |
||
| 385 | /*$query = "SELECT DISTINCT u.id as login_user_id, login_date |
||
| 386 | FROM $track_online_table e, $table_user u |
||
| 387 | GROUP by u.id |
||
| 388 | ORDER BY $column $direction |
||
| 389 | LIMIT $from, $number_of_items";*/ |
||
| 390 | |||
| 391 | $result = Database::query($query); |
||
| 392 | if ($result) { |
||
|
0 ignored issues
–
show
|
|||
| 393 | $users_online = []; |
||
| 394 | while (list($login_user_id, $login_date) = Database::fetch_row($result)) { |
||
| 395 | $users_online[] = $login_user_id; |
||
| 396 | } |
||
| 397 | |||
| 398 | return $users_online; |
||
| 399 | } else { |
||
| 400 | return false; |
||
| 401 | } |
||
| 402 | } |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @param string $time_limit |
||
| 406 | */ |
||
| 407 | function who_is_online_count($time_limit = null, $friends = false) |
||
| 408 | { |
||
| 409 | if (empty($time_limit)) { |
||
| 410 | $time_limit = api_get_setting('time_limit_whosonline'); |
||
| 411 | } else { |
||
| 412 | $time_limit = intval($time_limit); |
||
| 413 | } |
||
| 414 | $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
||
| 415 | $friend_user_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 416 | $table_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 417 | $online_time = time() - $time_limit * 60; |
||
| 418 | $current_date = api_get_utc_datetime($online_time); |
||
| 419 | |||
| 420 | if ($friends) { |
||
| 421 | // who friends from social network is online |
||
| 422 | $query = "SELECT DISTINCT count(login_user_id) as count |
||
| 423 | FROM $track_online_table INNER JOIN $friend_user_table |
||
| 424 | ON (friend_user_id = login_user_id) |
||
| 425 | WHERE |
||
| 426 | login_date >= '$current_date' AND |
||
| 427 | friend_user_id <> '".api_get_user_id()."' AND |
||
| 428 | relation_type='".USER_RELATION_TYPE_FRIEND."' AND |
||
| 429 | user_id = '".api_get_user_id()."' "; |
||
| 430 | } else { |
||
| 431 | // All users online |
||
| 432 | $query = "SELECT count(login_id) as count |
||
| 433 | FROM $track_online_table track INNER JOIN $table_user u |
||
| 434 | ON (u.id=track.login_user_id) |
||
| 435 | WHERE u.status != ".ANONYMOUS." AND login_date >= '$current_date' "; |
||
| 436 | } |
||
| 437 | |||
| 438 | if (api_get_multiple_access_url()) { |
||
| 439 | $access_url_id = api_get_current_access_url_id(); |
||
| 440 | if ($access_url_id != -1) { |
||
| 441 | if ($friends) { |
||
| 442 | // friends from social network is online |
||
| 443 | $query = "SELECT DISTINCT count(login_user_id) as count |
||
| 444 | FROM $track_online_table track |
||
| 445 | INNER JOIN $friend_user_table ON (friend_user_id = login_user_id) |
||
| 446 | WHERE |
||
| 447 | track.access_url_id = $access_url_id AND |
||
| 448 | login_date >= '".$current_date."' AND |
||
| 449 | friend_user_id <> '".api_get_user_id()."' AND |
||
| 450 | relation_type='".USER_RELATION_TYPE_FRIEND."' "; |
||
| 451 | } else { |
||
| 452 | // all users online |
||
| 453 | $query = "SELECT count(login_id) as count FROM $track_online_table track |
||
| 454 | INNER JOIN $table_user u ON (u.id=track.login_user_id) |
||
| 455 | WHERE |
||
| 456 | u.status != ".ANONYMOUS." AND |
||
| 457 | track.access_url_id = $access_url_id AND |
||
| 458 | login_date >= '$current_date' "; |
||
| 459 | } |
||
| 460 | } |
||
| 461 | } |
||
| 462 | |||
| 463 | // Dev purposes show all users online |
||
| 464 | /*$table_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 465 | $query = "SELECT count(*) as count FROM ".$table_user;*/ |
||
| 466 | |||
| 467 | $result = Database::query($query); |
||
| 468 | if (Database::num_rows($result) > 0) { |
||
| 469 | $row = Database::fetch_array($result); |
||
| 470 | |||
| 471 | return $row['count']; |
||
| 472 | } else { |
||
| 473 | return false; |
||
| 474 | } |
||
| 475 | } |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Returns a list (array) of users who are online and in this course. |
||
| 479 | * |
||
| 480 | * @param int User ID |
||
| 481 | * @param int Number of minutes |
||
| 482 | * @param string Course code (could be empty, but then the function returns false) |
||
| 483 | * |
||
| 484 | * @return array Each line gives a user id and a login time |
||
| 485 | */ |
||
| 486 | function who_is_online_in_this_course($from, $number_of_items, $uid, $time_limit, $course_code) |
||
| 487 | { |
||
| 488 | if (empty($course_code)) { |
||
| 489 | return false; |
||
| 490 | } |
||
| 491 | |||
| 492 | $time_limit = (int) $time_limit; |
||
| 493 | if (empty($time_limit)) { |
||
| 494 | $time_limit = api_get_setting('time_limit_whosonline'); |
||
| 495 | } |
||
| 496 | |||
| 497 | $online_time = time() - $time_limit * 60; |
||
| 498 | $current_date = api_get_utc_datetime($online_time); |
||
| 499 | $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
||
| 500 | $tableUser = Database::get_main_table(TABLE_MAIN_USER); |
||
| 501 | $course_code = Database::escape_string($course_code); |
||
| 502 | $courseInfo = api_get_course_info($course_code); |
||
| 503 | $courseId = $courseInfo['real_id']; |
||
| 504 | |||
| 505 | $from = (int) $from; |
||
| 506 | $number_of_items = (int) $number_of_items; |
||
| 507 | |||
| 508 | $urlCondition = ''; |
||
| 509 | $urlJoin = ''; |
||
| 510 | if (api_is_multiple_url_enabled()) { |
||
| 511 | $accessUrlUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||
| 512 | $urlId = api_get_current_access_url_id(); |
||
| 513 | $urlJoin = " INNER JOIN $accessUrlUser a ON (a.user_id = u.id) "; |
||
| 514 | $urlCondition = " AND a.access_url_id = $urlId "; |
||
| 515 | } |
||
| 516 | |||
| 517 | $query = "SELECT o.login_user_id, o.login_date |
||
| 518 | FROM $track_online_table o |
||
| 519 | INNER JOIN $tableUser u |
||
| 520 | ON (o.login_user_id = u.id) |
||
| 521 | $urlJoin |
||
| 522 | WHERE |
||
| 523 | u.status <> '".ANONYMOUS."' AND |
||
| 524 | o.c_id = $courseId AND |
||
| 525 | o.login_date >= '$current_date' |
||
| 526 | $urlCondition |
||
| 527 | LIMIT $from, $number_of_items "; |
||
| 528 | |||
| 529 | $result = Database::query($query); |
||
| 530 | if ($result) { |
||
|
0 ignored issues
–
show
|
|||
| 531 | $users_online = []; |
||
| 532 | while (list($login_user_id, $login_date) = Database::fetch_row($result)) { |
||
| 533 | $users_online[] = $login_user_id; |
||
| 534 | } |
||
| 535 | |||
| 536 | return $users_online; |
||
| 537 | } else { |
||
| 538 | return false; |
||
| 539 | } |
||
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * @param int $uid |
||
| 544 | * @param string $time_limit |
||
| 545 | */ |
||
| 546 | function who_is_online_in_this_course_count( |
||
| 547 | $uid, |
||
| 548 | $time_limit, |
||
| 549 | $coursecode = null |
||
| 550 | ) { |
||
| 551 | if (empty($coursecode)) { |
||
| 552 | return false; |
||
| 553 | } |
||
| 554 | $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
||
| 555 | $tableUser = Database::get_main_table(TABLE_MAIN_USER); |
||
| 556 | $time_limit = Database::escape_string($time_limit); |
||
| 557 | $online_time = time() - $time_limit * 60; |
||
| 558 | $current_date = api_get_utc_datetime($online_time); |
||
| 559 | $courseId = api_get_course_int_id($coursecode); |
||
| 560 | |||
| 561 | if (empty($courseId)) { |
||
| 562 | return false; |
||
| 563 | } |
||
| 564 | |||
| 565 | $urlCondition = ''; |
||
| 566 | $urlJoin = ''; |
||
| 567 | if (api_is_multiple_url_enabled()) { |
||
| 568 | $accessUrlUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||
| 569 | $urlId = api_get_current_access_url_id(); |
||
| 570 | $urlJoin = " INNER JOIN $accessUrlUser a ON (a.user_id = u.id) "; |
||
| 571 | $urlCondition = " AND a.access_url_id = $urlId "; |
||
| 572 | } |
||
| 573 | |||
| 574 | $query = "SELECT count(login_user_id) as count |
||
| 575 | FROM $track_online_table o |
||
| 576 | INNER JOIN $tableUser u |
||
| 577 | ON (login_user_id = u.id) |
||
| 578 | $urlJoin |
||
| 579 | WHERE |
||
| 580 | u.status <> '".ANONYMOUS."' AND |
||
| 581 | c_id = $courseId AND |
||
| 582 | login_date >= '$current_date' |
||
| 583 | $urlCondition |
||
| 584 | "; |
||
| 585 | $result = Database::query($query); |
||
| 586 | if (Database::num_rows($result) > 0) { |
||
| 587 | $row = Database::fetch_array($result); |
||
| 588 | |||
| 589 | return $row['count']; |
||
| 590 | } else { |
||
| 591 | return false; |
||
| 592 | } |
||
| 593 | } |
||
| 594 | |||
| 595 | /** |
||
| 596 | * @param string $timeLimit |
||
| 597 | * @param int $sessionId |
||
| 598 | * |
||
| 599 | * @return bool |
||
| 600 | */ |
||
| 601 | function whoIsOnlineInThisSessionCount($timeLimit, $sessionId) |
||
| 602 | { |
||
| 603 | if (!$sessionId) { |
||
| 604 | return 0; |
||
| 605 | } |
||
| 606 | |||
| 607 | $tblTrackOnline = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
||
| 608 | $tableUser = Database::get_main_table(TABLE_MAIN_USER); |
||
| 609 | |||
| 610 | $timeLimit = Database::escape_string($timeLimit); |
||
| 611 | $online_time = time() - $timeLimit * 60; |
||
| 612 | $current_date = api_get_utc_datetime($online_time); |
||
| 613 | |||
| 614 | $urlCondition = ''; |
||
| 615 | $urlJoin = ''; |
||
| 616 | if (api_is_multiple_url_enabled()) { |
||
| 617 | $accessUrlUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||
| 618 | $urlId = api_get_current_access_url_id(); |
||
| 619 | $urlJoin = " INNER JOIN $accessUrlUser a ON (a.user_id = u.id) "; |
||
| 620 | $urlCondition = " AND a.access_url_id = $urlId "; |
||
| 621 | } |
||
| 622 | |||
| 623 | $query = "SELECT count(login_user_id) as count |
||
| 624 | FROM $tblTrackOnline o |
||
| 625 | INNER JOIN $tableUser u |
||
| 626 | ON (login_user_id = u.id) |
||
| 627 | $urlJoin |
||
| 628 | WHERE |
||
| 629 | u.status <> '".ANONYMOUS."' AND |
||
| 630 | session_id = $sessionId AND |
||
| 631 | login_date >= '$current_date' |
||
| 632 | $urlCondition |
||
| 633 | "; |
||
| 634 | $result = Database::query($query); |
||
| 635 | |||
| 636 | if (Database::num_rows($result) > 0) { |
||
| 637 | $row = Database::fetch_assoc($result); |
||
| 638 | |||
| 639 | return $row['count']; |
||
| 640 | } |
||
| 641 | |||
| 642 | return 0; |
||
| 643 | } |
||
| 644 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.