diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index 6e9d651df7..ce2c5988d8 100755 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -34,6 +34,7 @@ require_once __DIR__.'/../../public/legacy.php'; // Check the PHP version api_check_php_version(__DIR__.'/'); + try { // Get settings from .env file created when installation Chamilo $envFile = __DIR__.'/../../.env'; @@ -55,6 +56,7 @@ try { $response = $kernel->handle($request); $container = $kernel->getContainer(); + if ($kernel->isInstalled()) { require_once $kernel->getConfigurationFile(); } else { @@ -526,51 +528,51 @@ try { // ===== "who is logged in?" module section ===== // check and modify the date of user in the track.e.online table - if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) { - preventMultipleLogin($_user["user_id"]); - LoginCheck(isset($_user['user_id']) ? $_user['user_id'] : ''); - } + if (isset($_user['user_id'])) { + if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) { + preventMultipleLogin($_user['user_id']); + LoginCheck($_user['user_id']); + } - // ===== end "who is logged in?" module section ===== - - // Update of the logout_date field in the table track_e_login - // (needed for the calculation of the total connection time) - if (!isset($_SESSION['login_as']) && isset($_user)) { - // if $_SESSION['login_as'] is set, then the user is an admin logged as the user - $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); - $sql = "SELECT login_id, login_date - FROM $tbl_track_login - WHERE - login_user_id='".$_user["user_id"]."' - ORDER BY login_date DESC - LIMIT 0,1"; - - $q_last_connection = Database::query($sql); - if (Database::num_rows($q_last_connection) > 0) { - $now = api_get_utc_datetime(); - $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id'); - - // is the latest logout_date still relevant? - $sql = "SELECT logout_date FROM $tbl_track_login - WHERE login_id = $i_id_last_connection"; - $q_logout_date = Database::query($sql); - $res_logout_date = convert_sql_date(Database::result($q_logout_date, 0, 'logout_date')); - $lifeTime = api_get_configuration_value('session_lifetime'); - - if ($res_logout_date < time() - $lifeTime) { - // it isn't, we should create a fresh entry - // now that it's created, we can get its ID and carry on - Event::eventLogin($_user['user_id']); - } else { - $sql = "UPDATE $tbl_track_login SET logout_date = '$now' - WHERE login_id = '$i_id_last_connection'"; + // Update of the logout_date field in the table track_e_login + // (needed for the calculation of the total connection time) + if (!isset($_SESSION['login_as'])) { + // if $_SESSION['login_as'] is set, then the user is an admin logged as the user + $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); + $sql = "SELECT login_id, login_date + FROM $tbl_track_login + WHERE + login_user_id='".$_user["user_id"]."' + ORDER BY login_date DESC + LIMIT 0,1"; + + $q_last_connection = Database::query($sql); + if (Database::num_rows($q_last_connection) > 0) { + $now = api_get_utc_datetime(); + $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id'); + + // is the latest logout_date still relevant? + $sql = "SELECT logout_date FROM $tbl_track_login + WHERE login_id = $i_id_last_connection"; + $q_logout_date = Database::query($sql); + $res_logout_date = convert_sql_date(Database::result($q_logout_date, 0, 'logout_date')); + $lifeTime = api_get_configuration_value('session_lifetime'); + + if ($res_logout_date < time() - $lifeTime) { + // it isn't, we should create a fresh entry + // now that it's created, we can get its ID and carry on + Event::eventLogin($_user['user_id']); + } else { + $sql = "UPDATE $tbl_track_login SET logout_date = '$now' + WHERE login_id = '$i_id_last_connection'"; + Database::query($sql); + } + + $tableUser = Database::get_main_table(TABLE_MAIN_USER); + $sql = "UPDATE $tableUser SET last_login = '$now' + WHERE user_id = ".$_user["user_id"]; Database::query($sql); } - - $tableUser = Database::get_main_table(TABLE_MAIN_USER); - $sql = "UPDATE $tableUser SET last_login = '$now' - WHERE user_id = ".$_user["user_id"]; - Database::query($sql); } } @@ -597,7 +599,9 @@ try { // Forcing PclZip library to use a custom temporary folder. define('PCLZIP_TEMPORARY_DIR', api_get_path(SYS_ARCHIVE_PATH)); } catch (Exception $e) { - /*var_dump($e->getMessage()); + error_log($e->getMessage()); + /* + var_dump($e->getMessage()); var_dump($e->getCode()); var_dump($e->getLine()); echo $e->getTraceAsString(); diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index 2b32aa4c4e..99644e4792 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -6456,9 +6456,9 @@ function api_request_uri() */ function api_get_current_access_url_id() { - $access_url_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL); + $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL); $path = Database::escape_string(api_get_path(WEB_PATH)); - $sql = "SELECT id FROM $access_url_table WHERE url = '".$path."'"; + $sql = "SELECT id FROM $table WHERE url = '".$path."'"; $result = Database::query($sql); if (Database::num_rows($result) > 0) { $access_url_id = Database::result($result, 0, 0); diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 757776f2da..ce1d7318d0 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -2578,7 +2578,7 @@ class Tracking if (!empty($sessionId)) { $conditions[] = " session_id = $sessionId "; } else { - $conditions[] = " (session_id = 0 OR session_id IS NULL) "; + $conditions[] = ' (session_id = 0 OR session_id IS NULL) '; } $conditionToString = implode('AND', $conditions);