MDL-8096 - user edit form splitting, refactoring, cleanup and fixing - work in progre...
[moodle.git] / admin / index.php
CommitLineData
4fa24bb8 1<?php // $Id$
f9903ed0 2
39a5a35d 3/// Check that config.php exists, if not then call the install script
045e9e24 4 if (!file_exists('../config.php')) {
39a5a35d 5 header('Location: ../install.php');
d98228e4 6 die;
7 }
249ab745 8
9/// Check that PHP is of a sufficient version
10/// Moved here because older versions do not allow while(@ob_end_clean());
11 if (version_compare(phpversion(), "4.3.0") < 0) {
12 $phpversion = phpversion();
13 echo "Sorry, Moodle requires PHP 4.3.0 or later (currently using version $phpversion)";
14 die;
15 }
16
17/// Turn off time limits and try to flush everything all the time, sometimes upgrades can be slow.
18
19 @set_time_limit(0);
20 @ob_implicit_flush(true);
21 while(@ob_end_clean()); // ob_end_flush prevents sending of headers
22
23
045e9e24 24 require_once('../config.php');
6e4dc10f 25 require_once($CFG->libdir.'/adminlib.php'); // Contains various admin-only functions
26 require_once($CFG->libdir.'/ddllib.php'); // Install/upgrade related db functions
4d00e5e4 27
045e9e24 28 $id = optional_param('id', '', PARAM_ALPHANUM);
29 $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
371a32e3 30 $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
31 $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
32 $autopilot = optional_param('autopilot', 0, PARAM_BOOL);
635c0e0b 33 $ignoreupgradewarning = optional_param('ignoreupgradewarning', 0, PARAM_BOOL);
74944b73 34
583fad99 35/// check upgrade status first
635c0e0b 36 if ($ignoreupgradewarning and !empty($_SESSION['upgraderunning'])) {
37 $_SESSION['upgraderunning'] = 0;
38 }
39 upgrade_check_running("Upgrade already running in this session, please wait!<br />Click on the exclamation marks to ignore this warning (<a href=\"index.php?ignoreupgradewarning=1\">!!!</a>).", 10);
583fad99 40
371a32e3 41/// set install/upgrade autocontinue session flag
42 if ($autopilot) {
43 $_SESSION['installautopilot'] = $autopilot;
44 }
45
d686bf50 46/// Check some PHP server settings
47
95056a03 48 $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
d686bf50 49
c39c66a5 50 if (ini_get_bool('session.auto_start')) {
51 error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
d686bf50 52 }
c39c66a5 53
54 if (ini_get_bool('magic_quotes_runtime')) {
d686bf50 55 error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink");
56 }
57
c39c66a5 58 if (!ini_get_bool('file_uploads')) {
59 error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
d686bf50 60 }
61
b6fd0630 62 if (empty($CFG->prefix) && $CFG->dbfamily != 'mysql') { //Enforce prefixes for everybody but mysql
10379887 63 error('$CFG->prefix can\'t be empty for your target DB (' . $CFG->dbtype . ')');
64 }
65
60b562c4 66 if ($CFG->dbfamily == 'oracle' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc
10379887 67 error('$CFG->prefix maximum allowed length for Oracle DBs is 2cc.');
68 }
c39c66a5 69
74944b73 70/// Check that config.php has been edited
71
65c687a5 72 if ($CFG->wwwroot == "http://example.com/moodle") {
6e3e7e0e 73 error("Moodle has not been configured yet. You need to edit config.php first.");
f9903ed0 74 }
75
d98228e4 76
77/// Check settings in config.php
78
cf3eb7c3 79 $dirroot = dirname(realpath("../index.php"));
cb5e3cb9 80 if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
d98228e4 81 error("Please fix your settings in config.php:
0cdd1381 82 <p>You have:
83 <p>\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
84 <p>but it should be:
85 <p>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
2e43b5d9 86 "./");
d98228e4 87 }
88
1dd24519 89/// Set some necessary variables during set-up to avoid PHP warnings later on this page
90 if (!isset($CFG->framename)) {
91 $CFG->framename = "_top";
92 }
93 if (!isset($CFG->release)) {
94 $CFG->release = "";
95 }
96 if (!isset($CFG->version)) {
97 $CFG->version = "";
98 }
99
d02bc6ce 100 if (is_readable("$CFG->dirroot/version.php")) {
101 include_once("$CFG->dirroot/version.php"); # defines $version
102 }
103
104 if (!$version or !$release) {
105 error('Main version.php was not readable or specified');# without version, stop
106 }
107
7e5e076a 108/// Check if the main tables have been installed yet or not.
109
110 if (! $tables = $db->Metatables() ) { // No tables yet at all.
111 $maintables = false;
112
113 } else { // Check for missing main tables
114 $maintables = true;
6e3e7e0e 115 $mtables = array("config", "course", "course_categories", "course_modules",
116 "course_sections", "log", "log_display", "modules",
d76a5a7f 117 "user");
7e5e076a 118 foreach ($mtables as $mtable) {
6e3e7e0e 119 if (!in_array($CFG->prefix.$mtable, $tables)) {
7e5e076a 120 $maintables = false;
121 break;
122 }
123 }
124 }
7e5e076a 125 if (! $maintables) {
aa893d6b 126 /// hide errors from headers in case debug enabled in config.php
127 $origdebug = $CFG->debug;
7eb0b60a 128 $CFG->debug = DEBUG_MINIMAL;
aa893d6b 129 error_reporting($CFG->debug);
371a32e3 130 if (empty($agreelicense)) {
c7b8ac33 131 $strlicense = get_string('license');
779a4a8d 132 print_header($strlicense, $strlicense, $strlicense, "", "", false, "&nbsp;", "&nbsp;");
0cdd1381 133 print_heading("<a href=\"http://moodle.org\">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment");
c7b8ac33 134 print_heading(get_string('copyrightnotice'));
135 print_box(text_to_html(get_string('gpl')), 'copyrightnotice');
1dd24519 136 echo "<br />";
371a32e3 137 notice_yesno(get_string('doyouagree'), "index.php?agreelicense=1",
9bb4d21f 138 "http://docs.moodle.org/en/License");
b1887065 139 exit;
140 }
371a32e3 141 if (empty($confirmrelease)) {
142 $strcurrentrelease = get_string("currentrelease");
143 print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, "&nbsp;", "&nbsp;");
144 print_heading("Moodle $release");
145 print_box(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'));
146 echo '<form action="index.php"><fieldset class="invisiblefieldset">';
147 echo '<input type="hidden" name="agreelicense" value="1" />';
148 echo '<input type="hidden" name="confirmrelease" value="1" />';
149 echo '</fieldset>';
150 echo '<div class="continuebutton"><input name="autopilot" id="autopilot" type="checkbox" value="1" /><label for="autopilot">'.get_string('unattendedoperation', 'admin').'</label>';
151 echo '<br /><br /><input type="submit" value="'.get_string('continue').'" /></div>';
152 echo '</form>';
153 print_footer('none');
154 die;
155 }
b1887065 156
169d3404 157 $strdatabasesetup = get_string("databasesetup");
158 $strdatabasesuccess = get_string("databasesuccess");
a36f058e 159 print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup,
371a32e3 160 "", upgrade_get_javascript(), false, "&nbsp;", "&nbsp;");
aa893d6b 161 /// return to original debugging level
162 $CFG->debug = $origdebug;
163 error_reporting($CFG->debug);
015e946d 164 upgrade_log_start();
165 $db->debug = true;
166
167 /// Both old .sql files and new install.xml are supported
ecaf56e5 168 /// But we prioritise install.xml (XMLDB) if present
a6eb09d9 169
170 change_db_encoding(); // first try to change db encoding to utf8
83ab5388 171 if (!setup_is_unicodedb()) {
172 // If could not convert successfully, throw error, and prevent installation
173 print_error('unicoderequired', 'admin');
810944af 174 }
83ab5388 175
015e946d 176 $status = false;
db8bd7a6 177 if (file_exists("$CFG->libdir/db/install.xml")) {
015e946d 178 $status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
179 } else if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
180 $status = modify_database("$CFG->libdir/db/$CFG->dbtype.sql"); //Old method
181 } else {
182 error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory.");
183 }
f1700fab 184
3733f1e6 185 // all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
186 set_config('unicodedb', 1);
187
015e946d 188 /// Continue with the instalation
189 $db->debug = false;
190 if ($status) {
191 // Install the roles system.
192 moodle_install_roles();
b4713311 193 set_config('statsrolesupgraded',time());
015e946d 194
195 // Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
196 // (this should only have any effect during initial install).
6e4dc10f 197 $adminroot = admin_get_root();
4672d955 198 $adminroot->prune('backups'); // backup settings table not created yet
6e4dc10f 199 apply_default_settings($adminroot);
015e946d 200
201 /// This is used to handle any settings that must exist in $CFG but which do not exist in
6e4dc10f 202 /// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
015e946d 203 apply_default_exception_settings(array('alternateloginurl' => '',
204 'auth' => 'email',
205 'auth_pop3mailbox' => 'INBOX',
206 'changepassword' => '',
dd04ab49 207 'enrol' => 'manual',
208 'enrol_plugins_enabled' => 'manual',
015e946d 209 'guestloginbutton' => 1,
015e946d 210 'style' => 'default',
211 'template' => 'default',
f16242ce 212 'theme' => 'standardwhite',
213 'filter_multilang_converted' => 1));
015e946d 214
215 notify($strdatabasesuccess, "green");
d14383e0 216 require_once $CFG->dirroot.'/mnet/lib.php';
f9903ed0 217 } else {
015e946d 218 error("Error: Main databases NOT set up successfully");
f9903ed0 219 }
f1700fab 220 print_continue('index.php');
acdd790f 221 print_footer('none');
f9903ed0 222 die;
223 }
224
f28db22d 225
74944b73 226/// Check version of Moodle code on disk compared with database
227/// and upgrade if possible.
cbd1170e 228
420f6836 229 if (file_exists("$CFG->dirroot/lib/db/$CFG->dbtype.php")) {
230 include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines old upgrades
231 }
db8bd7a6 232 if (file_exists("$CFG->dirroot/lib/db/upgrade.php")) {
c779eb1a 233 include_once("$CFG->dirroot/lib/db/upgrade.php"); # defines new upgrades
420f6836 234 }
cbd1170e 235
69817927 236 $stradministration = get_string("administration");
237
6e3e7e0e 238 if ($CFG->version) {
74944b73 239 if ($version > $CFG->version) { // upgrade
69817927 240
47bc16f6 241 /// If the database is not already Unicode then we do not allow upgrading!
242 /// Instead, we print an error telling them to upgrade to 1.7 first. MDL-6857
243 if (empty($CFG->unicodedb)) {
244 print_error('unicodeupgradeerror', 'error', '', $version);
245 }
246
69817927 247 $a->oldversion = "$CFG->release ($CFG->version)";
248 $a->newversion = "$release ($version)";
169d3404 249 $strdatabasechecking = get_string("databasechecking", "", $a);
69817927 250
aa893d6b 251 // hide errors from headers in case debug is enabled
252 $origdebug = $CFG->debug;
7eb0b60a 253 $CFG->debug = DEBUG_MINIMAL;
aa893d6b 254 error_reporting($CFG->debug);
255
256 // logout in case we are upgrading from pre 1.7 version - prevention of weird session problems
257 if ($CFG->version < 2006050600) {
258 require_logout();
259 }
260
993ef10d 261 if (empty($confirmupgrade)) {
6e3e7e0e 262 print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
69817927 263 "", "", false, "&nbsp;", "&nbsp;");
d210e12e 264
371a32e3 265 notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=1', 'index.php');
69817927 266 exit;
6e3e7e0e 267
371a32e3 268 } else if (empty($confirmrelease)){
269 $strcurrentrelease = get_string("currentrelease");
270 print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, "&nbsp;", "&nbsp;");
271 print_heading("Moodle $release");
272 print_box(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'));
273 echo '<form action="index.php"><fieldset class="invisiblefieldset">';
274 echo '<input type="hidden" name="confirmupgrade" value="1" />';
275 echo '<input type="hidden" name="confirmrelease" value="1" />';
276 echo '</fieldset>';
277 echo '<div class="continuebutton"><input name="autopilot" id="autopilot" type="checkbox" value="0" /><label for="autopilot">'.get_string('unattendedoperation', 'admin').'</label>';
278 echo '<br /><br /><input type="submit" value="'.get_string('continue').'" /></div>';
279 echo '</form>';
280 print_footer('none');
281 die;
69817927 282 } else {
283 $strdatabasesuccess = get_string("databasesuccess");
6e3e7e0e 284 print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
371a32e3 285 "", upgrade_get_javascript(), false, "&nbsp;", "&nbsp;");
d210e12e 286
aa893d6b 287 /// return to original debugging level
288 $CFG->debug = $origdebug;
289 error_reporting($CFG->debug);
583fad99 290 upgrade_log_start();
d210e12e 291
292 /// Upgrade current language pack if we can
293 upgrade_language_pack();
294
69817927 295 print_heading($strdatabasechecking);
296 $db->debug=true;
3430fb29 297 /// Launch the old main upgrade (if exists)
298 $status = true;
299 if (function_exists('main_upgrade')) {
300 $status = main_upgrade($CFG->version);
301 }
c779eb1a 302 /// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
f2e0049d 303 if ($status && function_exists('xmldb_main_upgrade')) {
c779eb1a 304 $status = xmldb_main_upgrade($CFG->version);
305 }
015e946d 306 $db->debug=false;
c779eb1a 307 /// If successful, continue upgrading roles and setting everything properly
308 if ($status) {
5ec8a4f0 309 if (empty($CFG->rolesactive)) {
0c30fdc9 310 // Upgrade to the roles system.
311 moodle_install_roles();
0c30fdc9 312 set_config('rolesactive', 1);
250934b8 313 } else if (!update_capabilities()) {
314 error('Had trouble upgrading the core capabilities for the Roles System');
bbbf2d40 315 }
bd2b8dde 316 require_once($CFG->libdir.'/statslib.php');
317 if (!stats_upgrade_for_roles_wrapper()) {
318 notify('Couldn\'t upgrade the stats tables to use the new roles system');
319 }
69817927 320 if (set_config("version", $version)) {
d6ead3a2 321 remove_dir($CFG->dataroot . '/cache', true); // flush cache
69817927 322 notify($strdatabasesuccess, "green");
f1700fab 323 print_continue("upgradesettings.php");
acdd790f 324 print_footer('none');
69817927 325 exit;
326 } else {
d02bc6ce 327 error('Upgrade failed! (Could not update version in config table)');
69817927 328 }
c779eb1a 329 /// Main upgrade not success
cbd1170e 330 } else {
d02bc6ce 331 notify('Main Upgrade failed! See lib/db/upgrade.php');
332 print_continue('index.php?confirmupgrade=1&amp;confirmrelease=1');
333 print_footer('none');
334 die;
cbd1170e 335 }
583fad99 336 upgrade_log_finish();
cbd1170e 337 }
74944b73 338 } else if ($version < $CFG->version) {
dedb2304 339 upgrade_log_start();
cbd1170e 340 notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
dedb2304 341 upgrade_log_finish();
cbd1170e 342 }
cbd1170e 343 } else {
d87a9d73 344 if (!set_config("version", $version)) {
015e946d 345 error("A problem occurred inserting current version into databases");
cbd1170e 346 }
347 }
348
74944b73 349/// Updated human-readable release version if necessary
c646b70d 350
b35f948b 351 if ($release <> $CFG->release) { // Update the release version
b35f948b 352 if (!set_config("release", $release)) {
d02bc6ce 353 error("ERROR: Could not update release version in database!!");
c646b70d 354 }
c646b70d 355 }
2eb68e6f 356
0143fb9f 357/// Find and check all main modules and load them up or upgrade them if necessary
420f6836 358/// first old *.php update and then the new upgrade.php script
0143fb9f 359 upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
360
5bf3aee8 361/// Check all questiontype plugins and upgrade if necessary
420f6836 362/// first old *.php update and then the new upgrade.php script
363/// It is important that this is done AFTER the quiz module has been upgraded
effbd108 364 upgrade_plugins('qtype', 'question/type', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
5bf3aee8 365
10dcde40 366/// Upgrade backup/restore system if necessary
420f6836 367/// first old *.php update and then the new upgrade.php script
10dcde40 368 require_once("$CFG->dirroot/backup/lib.php");
369 upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
10dcde40 370
0f3fe4b6 371/// Upgrade blocks system if necessary
420f6836 372/// first old *.php update and then the new upgrade.php script
0f3fe4b6 373 require_once("$CFG->dirroot/lib/blocklib.php");
374 upgrade_blocks_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
375
376/// Check all blocks and load (or upgrade them if necessary)
420f6836 377/// first old *.php update and then the new upgrade.php script
0f3fe4b6 378 upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
6deb891b 379
1108bebd 380/// Check all enrolment plugins and upgrade if necessary
420f6836 381/// first old *.php update and then the new upgrade.php script
ead29342 382 upgrade_plugins('enrol', 'enrol', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
6e3e7e0e 383
ae628043 384/// Check all course formats and upgrade if necessary
385 upgrade_plugins('format','course/format',"$CFG->wwwroot/$CFG->admin/index.php");
386
43e664cc 387/// Check for local database customisations
420f6836 388/// first old *.php update and then the new upgrade.php script
43e664cc 389 require_once("$CFG->dirroot/lib/locallib.php");
390 upgrade_local_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
c88f014a 391
f3f7610c
ML
392/// Check for new groups and upgrade if necessary. TODO:
393 require_once("$CFG->dirroot/group/db/upgrade.php");
394 upgrade_group_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
395
d14383e0 396/// Check for changes to RPC functions
397 require_once($CFG->dirroot.'/admin/mnet/adminlib.php');
398 upgrade_RPC_functions("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
399
400
583fad99 401/// just make sure upgrade logging is properly terminated
402 upgrade_log_finish();
74944b73 403
371a32e3 404 unset($_SESSION['installautopilot']);
405
e0f6e995 406/// Set up the blank site - to be customized later at the end of install.
a83fded1 407 if (! $site = get_site()) {
e0f6e995 408 // We are about to create the site "course"
02cc05a7 409 require_once($CFG->libdir.'/blocklib.php');
e0f6e995 410
411 $newsite = new Object();
412 $newsite->fullname = "";
413 $newsite->shortname = "";
414 $newsite->summary = "";
415 $newsite->newsitems = 3;
416 $newsite->numsections = 0;
417 $newsite->category = 0;
418 $newsite->format = 'site'; // Only for this course
419 $newsite->teacher = get_string("defaultcourseteacher");
420 $newsite->teachers = get_string("defaultcourseteachers");
421 $newsite->student = get_string("defaultcoursestudent");
422 $newsite->students = get_string("defaultcoursestudents");
423 $newsite->timemodified = time();
424
425 if ($newid = insert_record('course', $newsite)) {
426 // Site created, add blocks for it
427 $page = page_create_object(PAGE_COURSE_VIEW, $newid);
428 blocks_repopulate_page($page); // Return value not checked because you can always edit later
429
430 $cat = new Object();
431 $cat->name = get_string('miscellaneous');
432 if (insert_record('course_categories', $cat)) {
8dcc4476 433 redirect('index.php');
e0f6e995 434 } else {
435 error("Serious Error! Could not set up a default course category!");
436 }
437 } else {
438 error("Serious Error! Could not set up the site!");
439 }
f9903ed0 440 }
441
b1631fef 442 // initialise default blocks on admin and site page if needed
02cc05a7 443 if (empty($CFG->adminblocks_initialised)) {
444 require_once("$CFG->dirroot/$CFG->admin/pagelib.php");
445 require_once($CFG->libdir.'/blocklib.php');
446 page_map_class(PAGE_ADMIN, 'page_admin');
447 $page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
448 blocks_repopulate_page($page);
b1631fef 449
450 //add admin_tree block to site if not already present
451 if ($admintree = get_record('block', 'name', 'admin_tree')) {
b1631fef 452 $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
453 blocks_execute_action($page, blocks_get_by_page($page), 'add', (int)$admintree->id, false, false);
451d82c8 454 if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
455 blocks_execute_action($page, blocks_get_by_page($page), 'moveleft', $admintreeinstance, false, false);
eef868d1 456 }
b1631fef 457 }
64c4f9c4 458
459 set_config('adminblocks_initialised', 1);
02cc05a7 460 }
461
a61b898a 462/// Define the unique site ID code if it isn't already
463 if (empty($CFG->siteidentifier)) { // Unique site identification code
d53a487d 464 set_config('siteidentifier', random_string(32).$_SERVER['HTTP_HOST']);
a61b898a 465 }
ee1fb969 466
e163bf2d 467/// Check if the guest user exists. If not, create one.
468 if (! record_exists("user", "username", "guest")) {
ee1fb969 469 $guest->auth = "manual";
470 $guest->username = "guest";
e163bf2d 471 $guest->password = md5("guest");
472 $guest->firstname = addslashes(get_string("guestuser"));
473 $guest->lastname = " ";
474 $guest->email = "root@localhost";
475 $guest->description = addslashes(get_string("guestuserinfo"));
13c9d7e0 476 $guest->mnethostid = $CFG->mnet_localhost_id;
e163bf2d 477 $guest->confirmed = 1;
478 $guest->lang = $CFG->lang;
479 $guest->timemodified= time();
480
481 if (! $guest->id = insert_record("user", $guest)) {
482 notify("Could not create guest user record !!!");
483 }
484 }
a61b898a 485
0c30fdc9 486
74944b73 487/// Set up the admin user
e0f6e995 488 if (empty($CFG->rolesactive)) {
ad6226fb 489 create_admin_user();
2be8b28f 490 }
491
492/// Check for valid admin user
01f29000 493 require_login();
494
5ec8a4f0 495 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
bbbf2d40 496
f2e21e6c 497 require_capability('moodle/site:config', $context);
498
e0f6e995 499/// check that site is properly customized
500 if (empty($site->shortname) or empty($site->shortname)) {
55f3a4db 501 redirect('settings.php?section=frontpage&amp;return=site');
e0f6e995 502 }
f9903ed0 503
a2a3c590 504/// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
505
993ef10d 506 if (!empty($id)) {
507 if ($id == $CFG->siteidentifier) {
a2a3c590 508 set_config('registered', time());
509 }
510 }
511
6e0993ee 512/// Everything should now be set up, and the user is an admin
f9903ed0 513
6e0993ee 514/// Print default admin page with notifications.
90a73bb3 515
6e4dc10f 516 $adminroot = admin_get_root();
517 admin_externalpage_setup('adminnotifications', $adminroot);
518 admin_externalpage_print_header($adminroot);
6e0993ee 519
cb8229d0 520/// Deprecated database! Warning!!
521 if (!empty($CFG->migrated_to_new_db)) {
0a8d5d77 522 print_box(print_string('dbmigrationdeprecateddb','admin'));
cb8229d0 523 }
524
6e0993ee 525/// Check for any special upgrades that might need to be run
eef868d1 526 if (!empty($CFG->upgrade)) {
0a8d5d77 527 print_box(get_string("upgrade$CFG->upgrade", "admin", "$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"));
4da1a0a1 528 }
529
3699264c 530 if (ini_get_bool('register_globals') && !ini_get_bool('magic_quotes_gpc')) {
0a8d5d77 531 print_box(get_string('globalsquoteswarning', 'admin'));
3699264c 532 }
533
57e35f32 534 if (is_dataroot_insecure()) {
0a8d5d77 535 print_box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
57e35f32 536 }
537
35de9e24 538/// If no recently cron run
539 $lastcron = get_field_sql('SELECT max(lastcron) FROM ' . $CFG->prefix . 'modules');
540 if (time() - $lastcron > 3600 * 24) {
0301965a 541 $strinstallation = get_string('installation', 'install');
542 $helpbutton = helpbutton('install', $strinstallation, 'moodle', true, false, '', true);
0a8d5d77 543 print_box(get_string('cronwarning', 'admin')."&nbsp;".$helpbutton);
35de9e24 544 }
545
f16242ce 546/// Print multilang upgrade notice if needed
547 if (empty($CFG->filter_multilang_converted)) {
0a8d5d77 548 print_box(get_string('multilangupgradenotice', 'admin'));
f16242ce 549 }
550
1695b680 551/// Alert if we are currently in maintenance mode
552 if (file_exists($CFG->dataroot.'/1/maintenance.html')) {
0a8d5d77 553 print_box(get_string('sitemaintenancewarning', 'admin'));
799ce77d 554 }
555
1695b680 556
a2a3c590 557/// Print slightly annoying registration button every six months ;-)
eef868d1 558/// You can set the "registered" variable to something far in the future
a2a3c590 559/// if you really want to prevent this. eg 9999999999
560 if (!isset($CFG->registered) || $CFG->registered < (time() - 3600*24*30*6)) {
561 $options = array();
562 $options['sesskey'] = $USER->sesskey;
0a8d5d77 563 print_box_start();
a2a3c590 564 print_string('pleaseregister', 'admin');
565 print_single_button('register.php', $options, get_string('registration'));
0a8d5d77 566 print_box_end();
6e0993ee 567 $registrationbuttonshown = true;
a2a3c590 568 }
569
c15421f2 570 //////////////////////////////////////////////////////////////////////////////////////////////////
e4d81c60 571 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
e58e1a94 572 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
c4d044b5 573 '<a href="http://docs.moodle.org/en/Release">'.$CFG->release.'</a> ('.$CFG->version.')<br />'.
574 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
e4d81c60 575 'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />'.
c4d044b5 576 '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
0a8d5d77 577 print_box($copyrighttext, 'copyright');
c15421f2 578 //////////////////////////////////////////////////////////////////////////////////////////////////
55e4b5f9 579
fe930cf3 580
6e0993ee 581 if (empty($registrationbuttonshown)) {
6e0993ee 582 $options = array();
583 $options['sesskey'] = $USER->sesskey;
584 print_single_button('register.php', $options, get_string('registration'));
6e0993ee 585 }
fe930cf3 586
eef868d1 587
c452097e 588 if (optional_param('dbmigrate')) { // ??? Is this actually used?
0a8d5d77 589 print_box_start();
6859360c 590 require_once($CFG->dirroot.'/'.$CFG->admin.'/utfdbmigrate.php');
799ce77d 591 db_migrate2utf8();
0a8d5d77 592 print_box_end();
799ce77d 593 }
594
799ce77d 595
6e4dc10f 596 admin_externalpage_print_footer($adminroot);
74944b73 597
f1700fab 598
b1ce7811 599?>