MDL-27171 messages: implement new syntax in messages.php and update processing
[moodle.git] / admin / index.php
CommitLineData
8580535b 1<?php
2
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.
14//
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/>.
17
18/**
19 * Main administration script.
20 *
d078f6d3 21 * @package core
8580535b 22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
f9903ed0 25
00be1916 26// Check that config.php exists, if not then call the install script
27if (!file_exists('../config.php')) {
28 header('Location: ../install.php');
29 die;
30}
31
32// Check that PHP is of a sufficient version as soon as possible
bc76b3c0 33if (version_compare(phpversion(), '5.2.0') < 0) {
00be1916 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;
39}
40
cbad562e 41define('NO_OUTPUT_BUFFERING', true);
00be1916 42
43require('../config.php');
bc76b3c0 44require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
45require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
00be1916 46
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);
b9934a17 51$showallplugins = optional_param('showallplugins', 0, PARAM_BOOL);
00be1916 52$agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
53
54// Check some PHP server settings
55
a6855934 56$PAGE->set_url('/admin/index.php');
6d80fad4 57$PAGE->set_pagelayout('admin'); // Set a default pagelayout
ee73b1ff 58
00be1916 59$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
60
61if (ini_get_bool('session.auto_start')) {
62 print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
63}
64
65if (ini_get_bool('magic_quotes_runtime')) {
66 print_error('phpvaroff', 'debug', '', (object)array('name'=>'magic_quotes_runtime', 'link'=>$documentationlink));
67}
68
69if (!ini_get_bool('file_uploads')) {
70 print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
71}
72
73if (is_float_problem()) {
74 print_error('phpfloatproblem', 'admin', '', $documentationlink);
75}
76
00be1916 77// Set some necessary variables during set-up to avoid PHP warnings later on this page
78if (!isset($CFG->framename)) {
bc76b3c0 79 $CFG->framename = '_top';
00be1916 80}
81if (!isset($CFG->release)) {
bc76b3c0 82 $CFG->release = '';
00be1916 83}
84if (!isset($CFG->version)) {
bc76b3c0 85 $CFG->version = '';
00be1916 86}
87
88$version = null;
89$release = null;
3d673fc4 90require("$CFG->dirroot/version.php"); // defines $version, $release and $maturity
00be1916 91$CFG->target_release = $release; // used during installation and upgrades
92
93if (!$version or !$release) {
94 print_error('withoutversion', 'debug'); // without version, stop
95}
96
00be1916 97// Turn off xmlstrictheaders during upgrade.
98$origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
99$CFG->xmlstrictheaders = false;
100
3316fe24 101if (!core_tables_exist()) {
78946b9b 102 $PAGE->set_pagelayout('maintenance');
d3875524 103 $PAGE->set_popup_notification_allowed(false);
00be1916 104
105 // fake some settings
106 $CFG->docroot = 'http://docs.moodle.org';
107
108 $strinstallation = get_string('installation', 'install');
109
110 // remove current session content completely
111 session_get_instance()->terminate_current();
112
113 if (empty($agreelicense)) {
114 $strlicense = get_string('license');
69d77c23 115 $PAGE->navbar->add($strlicense);
116 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
117 $PAGE->set_heading($strinstallation);
118 $PAGE->set_cacheable(false);
119 echo $OUTPUT->header();
2fff8846 120 echo $OUTPUT->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
121 echo $OUTPUT->heading(get_string('copyrightnotice'));
852a1f66 122 $copyrightnotice = text_to_html(get_string('gpl3'));
00be1916 123 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
20486a5a 124 echo $OUTPUT->box($copyrightnotice, 'copyrightnotice');
bc76b3c0 125 echo '<br />';
66f3df17
PS
126 $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
127 echo $OUTPUT->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/en/License");
73d6f52f 128 echo $OUTPUT->footer();
249ab745 129 die;
130 }
00be1916 131 if (empty($confirmrelease)) {
bc76b3c0 132 $strcurrentrelease = get_string('currentrelease');
69d77c23 133 $PAGE->navbar->add($strcurrentrelease);
1a4d6a5b
DM
134 $PAGE->set_title($strinstallation);
135 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release);
69d77c23 136 $PAGE->set_cacheable(false);
137 echo $OUTPUT->header();
2fff8846 138 echo $OUTPUT->heading("Moodle $release");
3d673fc4
DM
139
140 if (isset($maturity)) {
141 // main version.php declares moodle code maturity
142 if ($maturity < MATURITY_STABLE) {
143 $maturitylevel = get_string('maturity'.$maturity, 'admin');
dc41abd8
DM
144 echo $OUTPUT->box(
145 $OUTPUT->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
146 $OUTPUT->container($OUTPUT->doc_link('admin/versions', get_string('morehelp'))),
147 'generalbox maturitywarning');
3d673fc4
DM
148 }
149 }
150
00be1916 151 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
152 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
3d673fc4 153 echo $OUTPUT->box($releasenoteslink, 'generalbox releasenoteslink');
00be1916 154
155 require_once($CFG->libdir.'/environmentlib.php');
1c71748d 156 if (!check_moodle_environment(normalize_version($release), $environment_results, true, ENV_SELECT_RELEASE)) {
00be1916 157 print_upgrade_reload("index.php?agreelicense=1&amp;lang=$CFG->lang");
158 } else {
8fbce1c8 159 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
66f3df17 160 echo $OUTPUT->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
00be1916 161 }
249ab745 162
73d6f52f 163 echo $OUTPUT->footer();
00be1916 164 die;
1dd24519 165 }
166
bc76b3c0 167 $strdatabasesetup = get_string('databasesetup');
543f54d3 168 upgrade_init_javascript();
69d77c23 169 $PAGE->navbar->add($strdatabasesetup);
170 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
2ea05146 171 $PAGE->set_heading($strinstallation);
69d77c23 172 $PAGE->set_cacheable(false);
173 echo $OUTPUT->header();
d02bc6ce 174
00be1916 175 if (!$DB->setup_is_unicodedb()) {
176 if (!$DB->change_db_encoding()) {
177 // If could not convert successfully, throw error, and prevent installation
178 print_error('unicoderequired', 'admin');
db5af934 179 }
db5af934 180 }
90509582 181
00be1916 182 install_core($version, true);
183}
db5af934 184
db5af934 185
00be1916 186// Check version of Moodle code on disk compared with database
187// and upgrade if possible.
db5af934 188
00be1916 189$stradministration = get_string('administration');
190$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
db5af934 191
00be1916 192if (empty($CFG->version)) {
193 print_error('missingconfigversion', 'debug');
194}
db5af934 195
00be1916 196if ($version > $CFG->version) { // upgrade
a95682b2 197 purge_all_caches();
78946b9b 198 $PAGE->set_pagelayout('maintenance');
d3875524 199 $PAGE->set_popup_notification_allowed(false);
d4a03c00 200
00be1916 201 $a->oldversion = "$CFG->release ($CFG->version)";
202 $a->newversion = "$release ($version)";
bc76b3c0 203 $strdatabasechecking = get_string('databasechecking', '', $a);
db5af934 204
00be1916 205 if (empty($confirmupgrade)) {
1a4d6a5b
DM
206 $PAGE->set_title($stradministration);
207 $PAGE->set_heading($strdatabasechecking);
69d77c23 208 $PAGE->set_cacheable(false);
209 echo $OUTPUT->header();
3d673fc4
DM
210 if (isset($maturity)) {
211 // main version.php declares moodle code maturity
212 if ($maturity < MATURITY_STABLE) {
213 $maturitylevel = get_string('maturity'.$maturity, 'admin');
dc41abd8
DM
214 echo $OUTPUT->box(
215 $OUTPUT->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
216 $OUTPUT->container($OUTPUT->doc_link('admin/versions', get_string('morehelp'))),
217 'generalbox maturitywarning');
218}
3d673fc4 219 }
8a138093
PS
220 $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
221 $cancelurl = new moodle_url('index.php');
222 echo $OUTPUT->confirm(get_string('upgradesure', 'admin', $a->newversion), $continueurl, $cancelurl);
73d6f52f 223 echo $OUTPUT->footer();
00be1916 224 exit;
db5af934 225
00be1916 226 } else if (empty($confirmrelease)){
bc76b3c0 227 $strcurrentrelease = get_string('currentrelease');
69d77c23 228 $PAGE->navbar->add($strcurrentrelease);
229 $PAGE->set_title($strcurrentrelease);
52273536 230 $PAGE->set_heading($strcurrentrelease);
69d77c23 231 $PAGE->set_cacheable(false);
232 echo $OUTPUT->header();
2fff8846 233 echo $OUTPUT->heading("Moodle $release");
00be1916 234 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
235 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
20486a5a 236 echo $OUTPUT->box($releasenoteslink);
db5af934 237
00be1916 238 require_once($CFG->libdir.'/environmentlib.php');
239 if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
240 print_upgrade_reload('index.php?confirmupgrade=1');
db5af934 241 } else {
8fbce1c8 242 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
00be1916 243 if (empty($CFG->skiplangupgrade)) {
20486a5a 244 echo $OUTPUT->box_start('generalbox', 'notice');
00be1916 245 print_string('langpackwillbeupdated', 'admin');
20486a5a 246 echo $OUTPUT->box_end();
00be1916 247 }
8fbce1c8 248 echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1');
db5af934 249 }
db5af934 250
73d6f52f 251 echo $OUTPUT->footer();
00be1916 252 die;
db5af934 253
00be1916 254 } elseif (empty($confirmplugins)) {
255 $strplugincheck = get_string('plugincheck');
69d77c23 256 $PAGE->navbar->add($strplugincheck);
257 $PAGE->set_title($strplugincheck);
52273536 258 $PAGE->set_heading($strplugincheck);
69d77c23 259 $PAGE->set_cacheable(false);
b9934a17
DM
260 $output = $PAGE->get_renderer('core', 'admin');
261 $pluginman = plugin_manager::instance();
262
263 echo $output->header();
264 echo $output->box_start('generalbox');
265 echo $output->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
266 echo $output->plugins_check($pluginman->get_plugins(), array('full' => $showallplugins));
267 echo $output->box_end();
00be1916 268 print_upgrade_reload('index.php?confirmupgrade=1&amp;confirmrelease=1');
575f245f
PS
269 $button = new single_button(new moodle_url('index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1)), get_string('upgradestart', 'admin'), 'get');
270 $button->class = 'continuebutton';
b9934a17
DM
271 echo $output->render($button);
272 echo $output->footer();
00be1916 273 die();
db5af934 274
00be1916 275 } else {
276 // Launch main upgrade
277 upgrade_core($version, true);
88582df4 278 }
00be1916 279} else if ($version < $CFG->version) {
80380bd7
PS
280 // better stop here, we can not continue with plugin upgrades or anything else
281 throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/'));
00be1916 282}
283
284// Updated human-readable release version if necessary
285if ($release <> $CFG->release) { // Update the release version
bc76b3c0 286 set_config('release', $release);
00be1916 287}
288
575f245f
PS
289if (moodle_needs_upgrading()) {
290 if (!$PAGE->headerprinted) {
2361b7dd 291 // means core upgrade or installation was not already done
575f245f 292 if (!$confirmplugins) {
2361b7dd 293 $PAGE->set_pagelayout('maintenance');
d3875524 294 $PAGE->set_popup_notification_allowed(false);
575f245f
PS
295 $strplugincheck = get_string('plugincheck');
296 $PAGE->navbar->add($strplugincheck);
297 $PAGE->set_title($strplugincheck);
298 $PAGE->set_heading($strplugincheck);
299 $PAGE->set_cacheable(false);
b9934a17
DM
300 $output = $PAGE->get_renderer('core', 'admin');
301 $pluginman = plugin_manager::instance();
302
303 echo $output->header();
304 echo $output->box_start('generalbox');
305 echo $output->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
306 echo $output->plugins_check($pluginman->get_plugins(), array('full' => $showallplugins));
307 echo $output->box_end();
575f245f
PS
308 print_upgrade_reload('index.php');
309 $button = new single_button(new moodle_url('index.php', array('confirmplugincheck'=>1)), get_string('upgradestart', 'admin'), 'get');
310 $button->class = 'continuebutton';
b9934a17
DM
311 echo $output->render($button);
312 echo $output->footer();
575f245f
PS
313 die();
314 }
315 }
316 // install/upgrade all plugins and other parts
317 upgrade_noncore(true);
318}
00be1916 319
31a99877 320// If this is the first install, indicate that this site is fully configured
321// except the admin password
322if (during_initial_install()) {
323 set_config('rolesactive', 1); // after this, during_initial_install will return false.
00be1916 324 set_config('adminsetuppending', 1);
c8ae55e9 325 // we need this redirect to setup proper session
00be1916 326 upgrade_finished("index.php?sessionstarted=1&amp;lang=$CFG->lang");
327}
328
329// make sure admin user is created - this is the last step because we need
330// session to be working properly in order to edit admin account
331 if (!empty($CFG->adminsetuppending)) {
332 $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL);
333 if (!$sessionstarted) {
334 redirect("index.php?sessionstarted=1&lang=$CFG->lang");
335 } else {
336 $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL);
337 if (!$sessionverify) {
338 $SESSION->sessionverify = 1;
339 redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
88582df4 340 } else {
00be1916 341 if (empty($SESSION->sessionverify)) {
342 print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
88582df4 343 }
00be1916 344 unset($SESSION->sessionverify);
88582df4 345 }
00be1916 346 }
88582df4 347
c8ae55e9
PS
348 // at this stage there can be only one admin - users may change username, so do not rely on that
349 $adminuser = get_complete_user_data('id', $CFG->siteadmins);
88582df4 350
00be1916 351 if ($adminuser->password === 'adminsetuppending') {
352 // prevent installation hijacking
353 if ($adminuser->lastip !== getremoteaddr()) {
354 print_error('installhijacked', 'admin');
35d6a2a4 355 }
00be1916 356 // login user and let him set password and admin details
357 $adminuser->newadminuser = 1;
00be1916 358 complete_user_login($adminuser, false);
359 redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
db5af934 360
5c144d60 361 } else {
00be1916 362 unset_config('adminsetuppending');
4da1a0a1 363 }
364
00be1916 365} else {
366 // just make sure upgrade logging is properly terminated
367 upgrade_finished('upgradesettings.php');
368}
b3732604 369
00be1916 370// Turn xmlstrictheaders back on now.
371$CFG->xmlstrictheaders = $origxmlstrictheaders;
372unset($origxmlstrictheaders);
373
374// Check for valid admin user - no guest autologin
375require_login(0, false);
376$context = get_context_instance(CONTEXT_SYSTEM);
377require_capability('moodle/site:config', $context);
378
379// check that site is properly customized
380$site = get_site();
381if (empty($site->shortname)) {
382 // probably new installation - lets return to frontpage after this step
383 // remove settings that we want uninitialised
384 unset_config('registerauth');
385 redirect('upgradesettings.php?return=site');
386}
387
388// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
389if (!empty($id) and $id == $CFG->siteidentifier) {
390 set_config('registered', time());
391}
392
393// setup critical warnings before printing admin tree block
bc76b3c0 394$insecuredataroot = is_dataroot_insecure(true);
00be1916 395$SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
396
397$adminroot = admin_get_root();
398
399// Check if there are any new admin settings which have still yet to be set
400if (any_new_admin_settings($adminroot)){
401 redirect('upgradesettings.php');
402}
403
404// Everything should now be set up, and the user is an admin
405
406// Print default admin page with notifications.
00be1916 407admin_externalpage_setup('adminnotifications');
61ef8f9f 408echo $OUTPUT->header();
00be1916 409
a95682b2
DM
410// Unstable code warning
411if (isset($maturity)) {
412 if ($maturity < MATURITY_STABLE) {
413 $maturitylevel = get_string('maturity'.$maturity, 'admin');
414 echo $OUTPUT->box(
415 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
416 $OUTPUT->doc_link('admin/versions', get_string('morehelp')),
417 'generalbox adminwarning maturityinfo');
418 }
419}
420
00be1916 421if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
20486a5a 422 echo $OUTPUT->box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning');
00be1916 423} else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
20486a5a 424 echo $OUTPUT->box(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'generalbox adminerror');
00be1916 425
426}
427
428if (defined('WARN_DISPLAY_ERRORS_ENABLED')) {
20486a5a 429 echo $OUTPUT->box(get_string('displayerrorswarning', 'admin'), 'generalbox adminwarning');
00be1916 430}
431
432// If no recently cron run
433$lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
434if (time() - $lastcron > 3600 * 24) {
9047d80e 435 $helpbutton = $OUTPUT->help_icon('cron', 'admin');
20486a5a 436 echo $OUTPUT->box(get_string('cronwarning', 'admin').'&nbsp;'.$helpbutton, 'generalbox adminwarning');
00be1916 437}
438
1c7b8b93
NC
439// Hidden bloglevel upgrade
440$showbloglevelupgrade = ($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete);
441if ($showbloglevelupgrade) {
442 echo $OUTPUT->box(get_string('bloglevelupgradenotice', 'admin'), 'generalbox adminwarning');
443}
444
d35ece6c
PS
445// diagnose DB, especially the sloppy MyISAM tables
446$diagnose = $DB->diagnose();
447if ($diagnose !== NULL) {
448 echo $OUTPUT->box($diagnose, 'generalbox adminwarning');
449}
450
00be1916 451// Alert if we are currently in maintenance mode
4fe2250a 452if (!empty($CFG->maintenance_enabled)) {
20486a5a 453 echo $OUTPUT->box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning');
00be1916 454}
455
00be1916 456//////////////////////////////////////////////////////////////////////////////////////////////////
457//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
458$copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
459 '<a href="http://docs.moodle.org/en/Release" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
460 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
461 'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />'.
462 '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
20486a5a 463echo $OUTPUT->box($copyrighttext, 'copyright');
00be1916 464//////////////////////////////////////////////////////////////////////////////////////////////////
465
73d6f52f 466echo $OUTPUT->footer();
74944b73 467