\n"; $timenow = time(); // Run all cron jobs for each module if ($mods = get_records_sql("SELECT * FROM modules WHERE cron > 0 AND (($timenow - lastcron) > cron)")) { foreach ($mods as $mod) { $libfile = "$CFG->dirroot/mod/$mod->name/lib.php"; if (file_exists($libfile)) { include_once($libfile); $cron_function = $mod->name."_cron"; if (function_exists($cron_function)) { if ($cron_function()) { if (! set_field("modules", "lastcron", $timenow, "id", $mod->id)) { echo "Error: could not update timestamp for $mod->fullname\n"; } } } } } } // Unenrol users who haven't logged in for $CFG->longtimenosee if ($CFG->longtimenosee) { // value in days $cutofftime = $timenow - ($CFG->longtimenosee * 3600 * 24); if ($users = get_records_sql("SELECT u.* FROM user u, user_students s WHERE lastaccess > '0' AND lastaccess < '$cutofftime' AND u.id = s.user GROUP BY u.id")) { foreach ($users as $user) { if (unenrol_student($user->id)) { echo "Deleted student enrolment for $user->firstname $user->lastname ($user->id)\n"; } } } } // Delete users who haven't confirmed within seven days $cutofftime = $timenow - (7 * 24 * 3600); if ($users = get_records_sql("SELECT * FROM user WHERE confirmed = '0' AND firstaccess > '0' AND firstaccess < '$cutofftime'")) { foreach ($users as $user) { if (delete_records("user", "id", $user->id)) { echo "Deleted unconfirmed user for $user->firstname $user->lastname ($user->id)\n"; } } } echo "Cron script completed correctly\n"; ?>