3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
21 * This script looks through all the module directories for cron.php files
22 * and runs them. These files can contain cleanup functions, email functions
23 * or anything that needs to be run on a regular basis.
25 * This file is best run from cron on the host system (ie outside PHP).
26 * It is strongly recommended to add password protection via admin settings.
28 * eg wget -q -O /dev/null 'http: *moodle.somewhere.edu/admin/cron.php?password=SeCreT666'
30 * It is also possible to use CLI script admin/cli/cron.php instead,
31 * you can not call this script from command line any more.
35 * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 if (defined('STDIN')) {
41 fwrite(STDERR
, "ERROR: This script no longer supports CLI, please use admin/cli/cron.php instead\n");
45 // This is a fake CLI script, it is a really ugly hack which emulates
46 // CLI via web interface, please do not use this hack elsewhere
47 define('CLI_SCRIPT', true);
48 define('WEB_CRON_EMULATED_CLI', 'defined'); // ugly ugly hack, do not use elsewhere please
49 define('NO_OUTPUT_BUFFERING', true);
51 require('../config.php');
52 require_once($CFG->libdir
.'/clilib.php');
53 require_once($CFG->libdir
.'/cronlib.php');
56 session_get_instance()->write_close();
58 // check if execution allowed
59 if (!empty($CFG->cronclionly
)) {
60 // This script can only be run via the cli.
61 print_error('cronerrorclionly', 'admin');
64 // This script is being called via the web, so check the password if there is one.
65 if (!empty($CFG->cronremotepassword
)) {
66 $pass = optional_param('password', '', PARAM_RAW
);
67 if ($pass != $CFG->cronremotepassword
) {
69 print_error('cronerrorpassword', 'admin');
74 // send mime type and encoding
75 if (check_browser_version('MSIE')) {
76 //ugly IE hack to work around downloading instead of viewing
77 @header
('Content-Type: text/html; charset=utf-8');
78 echo "<xmp>"; //<pre> is not good enough for us here
80 //send proper plaintext header
81 @header
('Content-Type: text/plain; charset=utf-8');
88 if (check_browser_version('MSIE')) {