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