MDL-26609 Provide a link to a docs page for more help with Moodle versions and their...
[moodle.git] / admin / index.php
blobddc0cbad3858a6d6b5774f9129309caac4eaab82
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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/>.
18 /**
19 * Main administration script.
21 * @package core
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 // Check that config.php exists, if not then call the install script
27 if (!file_exists('../config.php')) {
28 header('Location: ../install.php');
29 die;
32 // Check that PHP is of a sufficient version as soon as possible
33 if (version_compare(phpversion(), '5.2.0') < 0) {
34 $phpversion = phpversion();
35 // do NOT localise - lang strings would not work here and we CAN NOT move it to later place
36 echo "Sorry, Moodle 2.0 requires PHP 5.2.8 or later (currently using version $phpversion). ";
37 echo "Please upgrade your server software or use latest Moodle 1.9.x instead.";
38 die;
41 define('NO_OUTPUT_BUFFERING', true);
43 require('../config.php');
44 require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
45 require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
47 $id = optional_param('id', '', PARAM_TEXT);
48 $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
49 $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
50 $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL);
51 $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
53 // Check some PHP server settings
55 $PAGE->set_url('/admin/index.php');
56 $PAGE->set_pagelayout('admin'); // Set a default pagelayout
58 $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
60 if (ini_get_bool('session.auto_start')) {
61 print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
64 if (ini_get_bool('magic_quotes_runtime')) {
65 print_error('phpvaroff', 'debug', '', (object)array('name'=>'magic_quotes_runtime', 'link'=>$documentationlink));
68 if (!ini_get_bool('file_uploads')) {
69 print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
72 if (is_float_problem()) {
73 print_error('phpfloatproblem', 'admin', '', $documentationlink);
76 // Set some necessary variables during set-up to avoid PHP warnings later on this page
77 if (!isset($CFG->framename)) {
78 $CFG->framename = '_top';
80 if (!isset($CFG->release)) {
81 $CFG->release = '';
83 if (!isset($CFG->version)) {
84 $CFG->version = '';
87 $version = null;
88 $release = null;
89 require("$CFG->dirroot/version.php"); // defines $version, $release and $maturity
90 $CFG->target_release = $release; // used during installation and upgrades
92 if (!$version or !$release) {
93 print_error('withoutversion', 'debug'); // without version, stop
96 // Turn off xmlstrictheaders during upgrade.
97 $origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
98 $CFG->xmlstrictheaders = false;
100 if (!core_tables_exist()) {
101 $PAGE->set_pagelayout('maintenance');
102 $PAGE->set_popup_notification_allowed(false);
104 // fake some settings
105 $CFG->docroot = 'http://docs.moodle.org';
107 $strinstallation = get_string('installation', 'install');
109 // remove current session content completely
110 session_get_instance()->terminate_current();
112 if (empty($agreelicense)) {
113 $strlicense = get_string('license');
114 $PAGE->navbar->add($strlicense);
115 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
116 $PAGE->set_heading($strinstallation);
117 $PAGE->set_cacheable(false);
118 echo $OUTPUT->header();
119 echo $OUTPUT->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
120 echo $OUTPUT->heading(get_string('copyrightnotice'));
121 $copyrightnotice = text_to_html(get_string('gpl3'));
122 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
123 echo $OUTPUT->box($copyrightnotice, 'copyrightnotice');
124 echo '<br />';
125 $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
126 echo $OUTPUT->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/en/License");
127 echo $OUTPUT->footer();
128 die;
130 if (empty($confirmrelease)) {
131 $strcurrentrelease = get_string('currentrelease');
132 $PAGE->navbar->add($strcurrentrelease);
133 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
134 $PAGE->set_heading($strinstallation);
135 $PAGE->set_cacheable(false);
136 echo $OUTPUT->header();
137 echo $OUTPUT->heading("Moodle $release");
139 if (isset($maturity)) {
140 // main version.php declares moodle code maturity
141 if ($maturity < MATURITY_STABLE) {
142 $maturitylevel = get_string('maturity'.$maturity, 'admin');
143 echo $OUTPUT->box(
144 $OUTPUT->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
145 $OUTPUT->container($OUTPUT->doc_link('admin/versions', get_string('morehelp'))),
146 'generalbox maturitywarning');
150 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
151 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
152 echo $OUTPUT->box($releasenoteslink, 'generalbox releasenoteslink');
154 require_once($CFG->libdir.'/environmentlib.php');
155 if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
156 print_upgrade_reload("index.php?agreelicense=1&amp;lang=$CFG->lang");
157 } else {
158 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
159 echo $OUTPUT->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
162 echo $OUTPUT->footer();
163 die;
166 $strdatabasesetup = get_string('databasesetup');
167 upgrade_init_javascript();
168 $PAGE->navbar->add($strdatabasesetup);
169 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
170 $PAGE->set_heading($strinstallation);
171 $PAGE->set_cacheable(false);
172 echo $OUTPUT->header();
174 if (!$DB->setup_is_unicodedb()) {
175 if (!$DB->change_db_encoding()) {
176 // If could not convert successfully, throw error, and prevent installation
177 print_error('unicoderequired', 'admin');
181 install_core($version, true);
185 // Check version of Moodle code on disk compared with database
186 // and upgrade if possible.
188 $stradministration = get_string('administration');
189 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
191 if (empty($CFG->version)) {
192 print_error('missingconfigversion', 'debug');
195 if ($version > $CFG->version) { // upgrade
196 $PAGE->set_pagelayout('maintenance');
197 $PAGE->set_popup_notification_allowed(false);
199 $a->oldversion = "$CFG->release ($CFG->version)";
200 $a->newversion = "$release ($version)";
201 $strdatabasechecking = get_string('databasechecking', '', $a);
203 if (empty($confirmupgrade)) {
204 $PAGE->navbar->add($strdatabasechecking);
205 $PAGE->set_title($strdatabasechecking);
206 $PAGE->set_heading($stradministration);
207 $PAGE->set_cacheable(false);
208 echo $OUTPUT->header();
209 if (isset($maturity)) {
210 // main version.php declares moodle code maturity
211 if ($maturity < MATURITY_STABLE) {
212 $maturitylevel = get_string('maturity'.$maturity, 'admin');
213 echo $OUTPUT->box(
214 $OUTPUT->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
215 $OUTPUT->container($OUTPUT->doc_link('admin/versions', get_string('morehelp'))),
216 'generalbox maturitywarning');
219 $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
220 $cancelurl = new moodle_url('index.php');
221 echo $OUTPUT->confirm(get_string('upgradesure', 'admin', $a->newversion), $continueurl, $cancelurl);
222 echo $OUTPUT->footer();
223 exit;
225 } else if (empty($confirmrelease)){
226 $strcurrentrelease = get_string('currentrelease');
227 $PAGE->navbar->add($strcurrentrelease);
228 $PAGE->set_title($strcurrentrelease);
229 $PAGE->set_heading($strcurrentrelease);
230 $PAGE->set_cacheable(false);
231 echo $OUTPUT->header();
232 echo $OUTPUT->heading("Moodle $release");
233 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
234 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
235 echo $OUTPUT->box($releasenoteslink);
237 require_once($CFG->libdir.'/environmentlib.php');
238 if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
239 print_upgrade_reload('index.php?confirmupgrade=1');
240 } else {
241 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
242 if (empty($CFG->skiplangupgrade)) {
243 echo $OUTPUT->box_start('generalbox', 'notice');
244 print_string('langpackwillbeupdated', 'admin');
245 echo $OUTPUT->box_end();
247 echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1');
250 echo $OUTPUT->footer();
251 die;
253 } elseif (empty($confirmplugins)) {
254 $strplugincheck = get_string('plugincheck');
255 $PAGE->navbar->add($strplugincheck);
256 $PAGE->set_title($strplugincheck);
257 $PAGE->set_heading($strplugincheck);
258 $PAGE->set_cacheable(false);
259 echo $OUTPUT->header();
260 echo $OUTPUT->heading($strplugincheck);
261 echo $OUTPUT->box_start('generalbox', 'notice');
262 print_string('pluginchecknotice');
263 echo $OUTPUT->box_end();
264 print_plugin_tables();
265 print_upgrade_reload('index.php?confirmupgrade=1&amp;confirmrelease=1');
266 $button = new single_button(new moodle_url('index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1)), get_string('upgradestart', 'admin'), 'get');
267 $button->class = 'continuebutton';
268 echo $OUTPUT->render($button);
269 echo $OUTPUT->footer();
270 die();
272 } else {
273 // Launch main upgrade
274 upgrade_core($version, true);
276 } else if ($version < $CFG->version) {
277 // better stop here, we can not continue with plugin upgrades or anything else
278 throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/'));
281 // Updated human-readable release version if necessary
282 if ($release <> $CFG->release) { // Update the release version
283 set_config('release', $release);
286 if (moodle_needs_upgrading()) {
287 if (!$PAGE->headerprinted) {
288 // means core upgrade or installation was not already done
289 if (!$confirmplugins) {
290 $PAGE->set_pagelayout('maintenance');
291 $PAGE->set_popup_notification_allowed(false);
292 $strplugincheck = get_string('plugincheck');
293 $PAGE->navbar->add($strplugincheck);
294 $PAGE->set_title($strplugincheck);
295 $PAGE->set_heading($strplugincheck);
296 $PAGE->set_cacheable(false);
297 echo $OUTPUT->header();
298 echo $OUTPUT->heading($strplugincheck);
299 echo $OUTPUT->box_start('generalbox', 'notice');
300 print_string('pluginchecknotice');
301 echo $OUTPUT->box_end();
302 print_plugin_tables();
303 print_upgrade_reload('index.php');
304 $button = new single_button(new moodle_url('index.php', array('confirmplugincheck'=>1)), get_string('upgradestart', 'admin'), 'get');
305 $button->class = 'continuebutton';
306 echo $OUTPUT->render($button);
307 echo $OUTPUT->footer();
308 die();
311 // install/upgrade all plugins and other parts
312 upgrade_noncore(true);
315 // If this is the first install, indicate that this site is fully configured
316 // except the admin password
317 if (during_initial_install()) {
318 set_config('rolesactive', 1); // after this, during_initial_install will return false.
319 set_config('adminsetuppending', 1);
320 // we need this redirect to setup proper session
321 upgrade_finished("index.php?sessionstarted=1&amp;lang=$CFG->lang");
324 // make sure admin user is created - this is the last step because we need
325 // session to be working properly in order to edit admin account
326 if (!empty($CFG->adminsetuppending)) {
327 $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL);
328 if (!$sessionstarted) {
329 redirect("index.php?sessionstarted=1&lang=$CFG->lang");
330 } else {
331 $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL);
332 if (!$sessionverify) {
333 $SESSION->sessionverify = 1;
334 redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
335 } else {
336 if (empty($SESSION->sessionverify)) {
337 print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
339 unset($SESSION->sessionverify);
343 // at this stage there can be only one admin - users may change username, so do not rely on that
344 $adminuser = get_complete_user_data('id', $CFG->siteadmins);
346 if ($adminuser->password === 'adminsetuppending') {
347 // prevent installation hijacking
348 if ($adminuser->lastip !== getremoteaddr()) {
349 print_error('installhijacked', 'admin');
351 // login user and let him set password and admin details
352 $adminuser->newadminuser = 1;
353 message_set_default_message_preferences($adminuser);
354 complete_user_login($adminuser, false);
355 redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
357 } else {
358 unset_config('adminsetuppending');
361 } else {
362 // just make sure upgrade logging is properly terminated
363 upgrade_finished('upgradesettings.php');
366 // Turn xmlstrictheaders back on now.
367 $CFG->xmlstrictheaders = $origxmlstrictheaders;
368 unset($origxmlstrictheaders);
370 // Check for valid admin user - no guest autologin
371 require_login(0, false);
372 $context = get_context_instance(CONTEXT_SYSTEM);
373 require_capability('moodle/site:config', $context);
375 // check that site is properly customized
376 $site = get_site();
377 if (empty($site->shortname)) {
378 // probably new installation - lets return to frontpage after this step
379 // remove settings that we want uninitialised
380 unset_config('registerauth');
381 redirect('upgradesettings.php?return=site');
384 // Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
385 if (!empty($id) and $id == $CFG->siteidentifier) {
386 set_config('registered', time());
389 // setup critical warnings before printing admin tree block
390 $insecuredataroot = is_dataroot_insecure(true);
391 $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
393 $adminroot = admin_get_root();
395 // Check if there are any new admin settings which have still yet to be set
396 if (any_new_admin_settings($adminroot)){
397 redirect('upgradesettings.php');
400 // Everything should now be set up, and the user is an admin
402 // Print default admin page with notifications.
403 admin_externalpage_setup('adminnotifications');
404 echo $OUTPUT->header();
406 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
407 echo $OUTPUT->box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning');
408 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
409 echo $OUTPUT->box(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'generalbox adminerror');
413 if (defined('WARN_DISPLAY_ERRORS_ENABLED')) {
414 echo $OUTPUT->box(get_string('displayerrorswarning', 'admin'), 'generalbox adminwarning');
417 // If no recently cron run
418 $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
419 if (time() - $lastcron > 3600 * 24) {
420 $helpbutton = $OUTPUT->help_icon('cron', 'admin');
421 echo $OUTPUT->box(get_string('cronwarning', 'admin').'&nbsp;'.$helpbutton, 'generalbox adminwarning');
424 // Hidden bloglevel upgrade
425 $showbloglevelupgrade = ($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete);
426 if ($showbloglevelupgrade) {
427 echo $OUTPUT->box(get_string('bloglevelupgradenotice', 'admin'), 'generalbox adminwarning');
430 // diagnose DB, especially the sloppy MyISAM tables
431 $diagnose = $DB->diagnose();
432 if ($diagnose !== NULL) {
433 echo $OUTPUT->box($diagnose, 'generalbox adminwarning');
436 // Alert if we are currently in maintenance mode
437 if (!empty($CFG->maintenance_enabled)) {
438 echo $OUTPUT->box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning');
441 //////////////////////////////////////////////////////////////////////////////////////////////////
442 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
443 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
444 '<a href="http://docs.moodle.org/en/Release" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
445 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
446 'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />'.
447 '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
448 echo $OUTPUT->box($copyrighttext, 'copyright');
449 //////////////////////////////////////////////////////////////////////////////////////////////////
451 echo $OUTPUT->footer();