UNIX_TIMESTAMP(login_course_date) ORDER by diff DESC LIMIT $limit "; $result = Database::query($sql); $log = ''; while ($row = Database::fetch_array($result)) { if ($row['diff'] >= $maxSeconds) { $id = $row['course_access_id']; $loginDate = $row['login_course_date']; $logoutDate = $row['logout_course_date']; $diff = round($row['diff'] / 60 / 60); $login = api_strtotime($row['login_course_date'], 'UTC') + $addSecondsToLogin; $newLogout = api_get_utc_datetime($login); $sql = "UPDATE track_e_course_access SET logout_course_date = '$newLogout' WHERE course_access_id = $id ; "; // Uncomment to fix if ($update) { Database::query($sql); } $report = "Login : $loginDate "; $report .= PHP_EOL; $report .= "Logout: $logoutDate Diff in hours: $diff"; $report .= PHP_EOL; $report .= $sql; $report .= PHP_EOL; $report .= PHP_EOL; $log .= $report; echo $report; } } if ($sendMessage && !empty($log)) { $log = nl2br($log); MessageManager::send_message_simple( $userId, 'Course time spent fixes', $log, 1 ); }