UNIX_TIMESTAMP(login_course_date) ORDER by diff DESC LIMIT $limit "; // contidos //SELECT course_access_id, counter, (UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) / 60 / 60 diff, login_course_date, logout_course_date FROM track_e_course_access WHERE UNIX_TIMESTAMP(logout_course_date) > UNIX_TIMESTAMP(login_course_date) order by diff DESC limit 10; $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;"; 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 ); }