MDL-19676 MDL-14408 MDL-8776 Blog improvements
[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 *
21 * @package moodlecore
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
41// try to flush everything all the time
42@ob_implicit_flush(true);
c3d0e149 43while(@ob_end_clean()); // ob_end_flush prevents sending of headers
00be1916 44
45require('../config.php');
bc76b3c0 46require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
47require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
00be1916 48
49$id = optional_param('id', '', PARAM_TEXT);
50$confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
51$confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
52$confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL);
53$agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
54
55// Check some PHP server settings
56
ee73b1ff 57$PAGE->set_url($CFG->admin . '/index.php');
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
77// Check settings in config.php
78
bc76b3c0 79$dirroot = dirname(realpath('../index.php'));
00be1916 80// Check correct dirroot, ignoring slashes (though should be always forward slashes). MDL-18195
81if (!empty($dirroot) and str_replace('\\', '/', $dirroot) != str_replace('\\', '/', $CFG->dirroot)) {
82 print_error('fixsetting', 'debug', '', (object)array('current'=>$CFG->dirroot, 'found'=>str_replace('\\', '/', $dirroot)));
83}
84
85// Set some necessary variables during set-up to avoid PHP warnings later on this page
86if (!isset($CFG->framename)) {
bc76b3c0 87 $CFG->framename = '_top';
00be1916 88}
89if (!isset($CFG->release)) {
bc76b3c0 90 $CFG->release = '';
00be1916 91}
92if (!isset($CFG->version)) {
bc76b3c0 93 $CFG->version = '';
00be1916 94}
95
96$version = null;
97$release = null;
98require("$CFG->dirroot/version.php"); // defines $version and $release
99$CFG->target_release = $release; // used during installation and upgrades
100
101if (!$version or !$release) {
102 print_error('withoutversion', 'debug'); // without version, stop
103}
104
00be1916 105// Turn off xmlstrictheaders during upgrade.
106$origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
107$CFG->xmlstrictheaders = false;
108
3316fe24 109if (!core_tables_exist()) {
d4a03c00 110 $PAGE->set_generaltype('maintenance');
00be1916 111
112 // fake some settings
113 $CFG->docroot = 'http://docs.moodle.org';
114
115 $strinstallation = get_string('installation', 'install');
116
117 // remove current session content completely
118 session_get_instance()->terminate_current();
119
120 if (empty($agreelicense)) {
121 $strlicense = get_string('license');
69d77c23 122 $PAGE->navbar->add($strlicense);
123 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
124 $PAGE->set_heading($strinstallation);
125 $PAGE->set_cacheable(false);
126 echo $OUTPUT->header();
2fff8846 127 echo $OUTPUT->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
128 echo $OUTPUT->heading(get_string('copyrightnotice'));
00be1916 129 $copyrightnotice = text_to_html(get_string('gpl'));
130 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
20486a5a 131 echo $OUTPUT->box($copyrightnotice, 'copyrightnotice');
bc76b3c0 132 echo '<br />';
414a4a91 133 echo $OUTPUT->confirm(get_string('doyouagree'), "index.php?agreelicense=1&lang=$CFG->lang", "http://docs.moodle.org/en/License");
73d6f52f 134 echo $OUTPUT->footer();
249ab745 135 die;
136 }
00be1916 137 if (empty($confirmrelease)) {
bc76b3c0 138 $strcurrentrelease = get_string('currentrelease');
69d77c23 139 $PAGE->navbar->add($strcurrentrelease);
140 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
141 $PAGE->set_heading($strinstallation);
142 $PAGE->set_cacheable(false);
143 echo $OUTPUT->header();
2fff8846 144 echo $OUTPUT->heading("Moodle $release");
00be1916 145 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
146 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
20486a5a 147 echo $OUTPUT->box($releasenoteslink, 'generalbox boxaligncenter boxwidthwide');
00be1916 148
149 require_once($CFG->libdir.'/environmentlib.php');
150 if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
151 print_upgrade_reload("index.php?agreelicense=1&amp;lang=$CFG->lang");
152 } else {
8fbce1c8 153 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
154 echo $OUTPUT->continue_button("index.php?agreelicense=1&confirmrelease=1&lang=$CFG->lang");
00be1916 155 }
249ab745 156
73d6f52f 157 echo $OUTPUT->footer();
00be1916 158 die;
1dd24519 159 }
160
bc76b3c0 161 $strdatabasesetup = get_string('databasesetup');
e29380f3 162 upgrade_get_javascript();
69d77c23 163 $PAGE->navbar->add($strdatabasesetup);
164 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
2ea05146 165 $PAGE->set_heading($strinstallation);
69d77c23 166 $PAGE->set_cacheable(false);
167 echo $OUTPUT->header();
d02bc6ce 168
00be1916 169 if (!$DB->setup_is_unicodedb()) {
170 if (!$DB->change_db_encoding()) {
171 // If could not convert successfully, throw error, and prevent installation
172 print_error('unicoderequired', 'admin');
db5af934 173 }
db5af934 174 }
90509582 175
00be1916 176 install_core($version, true);
177}
db5af934 178
db5af934 179
00be1916 180// Check version of Moodle code on disk compared with database
181// and upgrade if possible.
db5af934 182
00be1916 183$stradministration = get_string('administration');
184$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
db5af934 185
00be1916 186if (empty($CFG->version)) {
187 print_error('missingconfigversion', 'debug');
188}
db5af934 189
00be1916 190if ($version > $CFG->version) { // upgrade
d4a03c00 191 $PAGE->set_generaltype('maintenance');
192
00be1916 193 $a->oldversion = "$CFG->release ($CFG->version)";
194 $a->newversion = "$release ($version)";
bc76b3c0 195 $strdatabasechecking = get_string('databasechecking', '', $a);
db5af934 196
00be1916 197 if (empty($confirmupgrade)) {
69d77c23 198 $PAGE->navbar->add($strdatabasechecking);
199 $PAGE->set_title($strdatabasechecking);
52273536 200 $PAGE->set_heading($stradministration);
69d77c23 201 $PAGE->set_cacheable(false);
202 echo $OUTPUT->header();
a8597584 203 $continueform = new html_form();
204 $continueform->method = 'get';
205 $continueform->url = new moodle_url('index.php', array('confirmupgrade' => 1));
1f1aa445 206 $cancelform = new html_form();
207 $cancelform->url = new moodle_url('index.php');
208 $cancelform->button->text = get_string('no');
209 echo $OUTPUT->confirm(get_string('upgradesure', 'admin', $a->newversion), $continueform, $cancelform);
73d6f52f 210 echo $OUTPUT->footer();
00be1916 211 exit;
db5af934 212
00be1916 213 } else if (empty($confirmrelease)){
bc76b3c0 214 $strcurrentrelease = get_string('currentrelease');
69d77c23 215 $PAGE->navbar->add($strcurrentrelease);
216 $PAGE->set_title($strcurrentrelease);
52273536 217 $PAGE->set_heading($strcurrentrelease);
69d77c23 218 $PAGE->set_cacheable(false);
219 echo $OUTPUT->header();
2fff8846 220 echo $OUTPUT->heading("Moodle $release");
00be1916 221 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
222 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
20486a5a 223 echo $OUTPUT->box($releasenoteslink);
db5af934 224
00be1916 225 require_once($CFG->libdir.'/environmentlib.php');
226 if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
227 print_upgrade_reload('index.php?confirmupgrade=1');
db5af934 228 } else {
8fbce1c8 229 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
00be1916 230 if (empty($CFG->skiplangupgrade)) {
20486a5a 231 echo $OUTPUT->box_start('generalbox', 'notice');
00be1916 232 print_string('langpackwillbeupdated', 'admin');
20486a5a 233 echo $OUTPUT->box_end();
00be1916 234 }
8fbce1c8 235 echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1');
db5af934 236 }
db5af934 237
73d6f52f 238 echo $OUTPUT->footer();
00be1916 239 die;
db5af934 240
00be1916 241 } elseif (empty($confirmplugins)) {
242 $strplugincheck = get_string('plugincheck');
69d77c23 243 $PAGE->navbar->add($strplugincheck);
244 $PAGE->set_title($strplugincheck);
52273536 245 $PAGE->set_heading($strplugincheck);
69d77c23 246 $PAGE->set_cacheable(false);
247 echo $OUTPUT->header();
2fff8846 248 echo $OUTPUT->heading($strplugincheck);
20486a5a 249 echo $OUTPUT->box_start('generalbox', 'notice');
00be1916 250 print_string('pluginchecknotice');
20486a5a 251 echo $OUTPUT->box_end();
00be1916 252 print_plugin_tables();
253 print_upgrade_reload('index.php?confirmupgrade=1&amp;confirmrelease=1');
8fbce1c8 254 echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1&confirmplugincheck=1');
73d6f52f 255 echo $OUTPUT->footer();
00be1916 256 die();
db5af934 257
00be1916 258 } else {
259 // Launch main upgrade
260 upgrade_core($version, true);
88582df4 261 }
00be1916 262} else if ($version < $CFG->version) {
8fbce1c8 263 echo $OUTPUT->notification('WARNING!!! The code you are using is OLDER than the version that made these databases!');
00be1916 264}
265
266// Updated human-readable release version if necessary
267if ($release <> $CFG->release) { // Update the release version
bc76b3c0 268 set_config('release', $release);
00be1916 269}
270
271// upgrade all plugins and other parts
272upgrade_noncore(true);
273
31a99877 274// If this is the first install, indicate that this site is fully configured
275// except the admin password
276if (during_initial_install()) {
277 set_config('rolesactive', 1); // after this, during_initial_install will return false.
00be1916 278 set_config('adminsetuppending', 1);
279 // we neeed this redirect to setup proper session
280 upgrade_finished("index.php?sessionstarted=1&amp;lang=$CFG->lang");
281}
282
283// make sure admin user is created - this is the last step because we need
284// session to be working properly in order to edit admin account
285 if (!empty($CFG->adminsetuppending)) {
286 $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL);
287 if (!$sessionstarted) {
288 redirect("index.php?sessionstarted=1&lang=$CFG->lang");
289 } else {
290 $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL);
291 if (!$sessionverify) {
292 $SESSION->sessionverify = 1;
293 redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
88582df4 294 } else {
00be1916 295 if (empty($SESSION->sessionverify)) {
296 print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
88582df4 297 }
00be1916 298 unset($SESSION->sessionverify);
88582df4 299 }
00be1916 300 }
88582df4 301
00be1916 302 $adminuser = get_complete_user_data('username', 'admin');
88582df4 303
00be1916 304 if ($adminuser->password === 'adminsetuppending') {
305 // prevent installation hijacking
306 if ($adminuser->lastip !== getremoteaddr()) {
307 print_error('installhijacked', 'admin');
35d6a2a4 308 }
00be1916 309 // login user and let him set password and admin details
310 $adminuser->newadminuser = 1;
311 message_set_default_message_preferences($adminuser);
312 complete_user_login($adminuser, false);
313 redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
db5af934 314
5c144d60 315 } else {
00be1916 316 unset_config('adminsetuppending');
4da1a0a1 317 }
318
00be1916 319} else {
320 // just make sure upgrade logging is properly terminated
321 upgrade_finished('upgradesettings.php');
322}
b3732604 323
00be1916 324// Turn xmlstrictheaders back on now.
325$CFG->xmlstrictheaders = $origxmlstrictheaders;
326unset($origxmlstrictheaders);
327
328// Check for valid admin user - no guest autologin
329require_login(0, false);
330$context = get_context_instance(CONTEXT_SYSTEM);
331require_capability('moodle/site:config', $context);
332
333// check that site is properly customized
334$site = get_site();
335if (empty($site->shortname)) {
336 // probably new installation - lets return to frontpage after this step
337 // remove settings that we want uninitialised
338 unset_config('registerauth');
339 redirect('upgradesettings.php?return=site');
340}
341
342// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
343if (!empty($id) and $id == $CFG->siteidentifier) {
344 set_config('registered', time());
345}
346
347// setup critical warnings before printing admin tree block
bc76b3c0 348$insecuredataroot = is_dataroot_insecure(true);
00be1916 349$SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
350
351$adminroot = admin_get_root();
352
353// Check if there are any new admin settings which have still yet to be set
354if (any_new_admin_settings($adminroot)){
355 redirect('upgradesettings.php');
356}
357
358// Everything should now be set up, and the user is an admin
359
360// Print default admin page with notifications.
00be1916 361admin_externalpage_setup('adminnotifications');
362admin_externalpage_print_header();
363
00be1916 364if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
20486a5a 365 echo $OUTPUT->box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning');
00be1916 366} else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
20486a5a 367 echo $OUTPUT->box(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'generalbox adminerror');
00be1916 368
369}
370
371if (defined('WARN_DISPLAY_ERRORS_ENABLED')) {
20486a5a 372 echo $OUTPUT->box(get_string('displayerrorswarning', 'admin'), 'generalbox adminwarning');
00be1916 373}
374
375// If no recently cron run
376$lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
377if (time() - $lastcron > 3600 * 24) {
378 $strinstallation = get_string('installation', 'install');
8fbce1c8 379 $helpbutton = $OUTPUT->help_icon(moodle_help_icon::make('install', $strinstallation));
20486a5a 380 echo $OUTPUT->box(get_string('cronwarning', 'admin').'&nbsp;'.$helpbutton, 'generalbox adminwarning');
00be1916 381}
382
383// Print multilang upgrade notice if needed
384if (empty($CFG->filter_multilang_converted)) {
20486a5a 385 echo $OUTPUT->box(get_string('multilangupgradenotice', 'admin'), 'generalbox adminwarning');
00be1916 386}
387
1c7b8b93
NC
388// Hidden bloglevel upgrade
389$showbloglevelupgrade = ($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete);
390if ($showbloglevelupgrade) {
391 echo $OUTPUT->box(get_string('bloglevelupgradenotice', 'admin'), 'generalbox adminwarning');
392}
393
00be1916 394// Alert if we are currently in maintenance mode
4fe2250a 395if (!empty($CFG->maintenance_enabled)) {
20486a5a 396 echo $OUTPUT->box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning');
00be1916 397}
398
399
400//////////////////////////////////////////////////////////////////////////////////////////////////
401//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
402$copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
403 '<a href="http://docs.moodle.org/en/Release" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
404 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
405 'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />'.
406 '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
20486a5a 407echo $OUTPUT->box($copyrighttext, 'copyright');
00be1916 408//////////////////////////////////////////////////////////////////////////////////////////////////
409
73d6f52f 410echo $OUTPUT->footer();
74944b73 411