MDL-10107 Fixed the definition of message providers ... it now works through files...
[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());
89a169fe 11 if (version_compare(phpversion(), "5.2.0") < 0) {
249ab745 12 $phpversion = phpversion();
06dc4dc1 13 echo "Sorry, Moodle requires PHP 5.2.0 or later (currently using version $phpversion)";
249ab745 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
e6d8bc8c 26 require_once($CFG->libdir.'/db/upgradelib.php'); // Upgrade-related functions
4d00e5e4 27
b27b1473 28 $id = optional_param('id', '', PARAM_TEXT);
045e9e24 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);
1e92bb91 34 $confirmplugincheck = optional_param('confirmplugincheck', 0, PARAM_BOOL);
74944b73 35
583fad99 36/// check upgrade status first
7cdd8b22 37 if ($ignoreupgradewarning) {
38 $SESSION->upgraderunning = 0;
635c0e0b 39 }
40 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 41
371a32e3 42/// set install/upgrade autocontinue session flag
43 if ($autopilot) {
7cdd8b22 44 $SESSION->installautopilot = $autopilot;
371a32e3 45 }
46
d686bf50 47/// Check some PHP server settings
48
95056a03 49 $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
d686bf50 50
c39c66a5 51 if (ini_get_bool('session.auto_start')) {
78664df0 52 print_error('phpvaroff', 'debug', '', array('session.auto_start', $documentationlink));
d686bf50 53 }
c39c66a5 54
55 if (ini_get_bool('magic_quotes_runtime')) {
78664df0 56 print_error('phpvaroff', 'debug', '', array('magic_quotes_runtime', $documentationlink));
d686bf50 57 }
58
c39c66a5 59 if (!ini_get_bool('file_uploads')) {
78664df0 60 print_error('phpvaron', 'debug', '', array('file_uploads', $documentationlink));
d686bf50 61 }
62
74944b73 63/// Check that config.php has been edited
64
65c687a5 65 if ($CFG->wwwroot == "http://example.com/moodle") {
78664df0 66 print_error('configmoodle', 'debug');
f9903ed0 67 }
68
d98228e4 69
70/// Check settings in config.php
71
cf3eb7c3 72 $dirroot = dirname(realpath("../index.php"));
cb5e3cb9 73 if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
fad52934 74 print_error('fixsetting', 'debug', '', array($CFG->dirroot, $dirroot));
d98228e4 75 }
76
1dd24519 77/// Set some necessary variables during set-up to avoid PHP warnings later on this page
78 if (!isset($CFG->framename)) {
79 $CFG->framename = "_top";
80 }
81 if (!isset($CFG->release)) {
82 $CFG->release = "";
83 }
84 if (!isset($CFG->version)) {
85 $CFG->version = "";
86 }
87
d02bc6ce 88 if (is_readable("$CFG->dirroot/version.php")) {
5a2a5331 89 include_once("$CFG->dirroot/version.php"); // defines $version
d02bc6ce 90 }
91
92 if (!$version or !$release) {
78664df0 93 print_error('withoutversion', 'debug'); // without version, stop
d02bc6ce 94 }
95
7e5e076a 96/// Check if the main tables have been installed yet or not.
f33e1ed4 97 if (!$tables = $DB->get_tables() ) { // No tables yet at all.
7e5e076a 98 $maintables = false;
99
100 } else { // Check for missing main tables
101 $maintables = true;
6e3e7e0e 102 $mtables = array("config", "course", "course_categories", "course_modules",
103 "course_sections", "log", "log_display", "modules",
d76a5a7f 104 "user");
7e5e076a 105 foreach ($mtables as $mtable) {
f33e1ed4 106 if (!in_array($mtable, $tables)) {
7e5e076a 107 $maintables = false;
108 break;
109 }
110 }
111 }
eee5d9bb 112
7e5e076a 113 if (! $maintables) {
aa893d6b 114 /// hide errors from headers in case debug enabled in config.php
115 $origdebug = $CFG->debug;
7eb0b60a 116 $CFG->debug = DEBUG_MINIMAL;
aa893d6b 117 error_reporting($CFG->debug);
371a32e3 118 if (empty($agreelicense)) {
c7b8ac33 119 $strlicense = get_string('license');
f1af7aaa 120 $navigation = build_navigation(array(array('name'=>$strlicense, 'link'=>null, 'type'=>'misc')));
121 print_header($strlicense, $strlicense, $navigation, "", "", false, "&nbsp;", "&nbsp;");
0cdd1381 122 print_heading("<a href=\"http://moodle.org\">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment");
c7b8ac33 123 print_heading(get_string('copyrightnotice'));
124 print_box(text_to_html(get_string('gpl')), 'copyrightnotice');
1dd24519 125 echo "<br />";
371a32e3 126 notice_yesno(get_string('doyouagree'), "index.php?agreelicense=1",
9bb4d21f 127 "http://docs.moodle.org/en/License");
4ed13ed8 128 print_footer('none');
b1887065 129 exit;
130 }
371a32e3 131 if (empty($confirmrelease)) {
132 $strcurrentrelease = get_string("currentrelease");
f1af7aaa 133 $navigation = build_navigation(array(array('name'=>$strcurrentrelease, 'link'=>null, 'type'=>'misc')));
134 print_header($strcurrentrelease, $strcurrentrelease, $navigation, "", "", false, "&nbsp;", "&nbsp;");
371a32e3 135 print_heading("Moodle $release");
4ed13ed8 136 print_box(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'), 'generalbox boxaligncenter boxwidthwide');
2ce10f29 137 echo '<form action="index.php"><div>';
371a32e3 138 echo '<input type="hidden" name="agreelicense" value="1" />';
139 echo '<input type="hidden" name="confirmrelease" value="1" />';
2ce10f29 140 echo '</div>';
371a32e3 141 echo '<div class="continuebutton"><input name="autopilot" id="autopilot" type="checkbox" value="1" /><label for="autopilot">'.get_string('unattendedoperation', 'admin').'</label>';
142 echo '<br /><br /><input type="submit" value="'.get_string('continue').'" /></div>';
143 echo '</form>';
144 print_footer('none');
145 die;
146 }
b1887065 147
169d3404 148 $strdatabasesetup = get_string("databasesetup");
149 $strdatabasesuccess = get_string("databasesuccess");
f1af7aaa 150 $navigation = build_navigation(array(array('name'=>$strdatabasesetup, 'link'=>null, 'type'=>'misc')));
151 print_header($strdatabasesetup, $strdatabasesetup, $navigation,
371a32e3 152 "", upgrade_get_javascript(), false, "&nbsp;", "&nbsp;");
aa893d6b 153 /// return to original debugging level
154 $CFG->debug = $origdebug;
155 error_reporting($CFG->debug);
015e946d 156 upgrade_log_start();
f33e1ed4 157 $DB->set_debug(true);
015e946d 158
159 /// Both old .sql files and new install.xml are supported
ecaf56e5 160 /// But we prioritise install.xml (XMLDB) if present
f1af7aaa 161
f33e1ed4 162 if (!$DB->setup_is_unicodedb()) {
163 if (!$DB->change_db_encoding()) {
164 // If could not convert successfully, throw error, and prevent installation
165 print_error('unicoderequired', 'admin');
166 }
810944af 167 }
f1af7aaa 168
eee5d9bb 169 $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
f1700fab 170
3733f1e6 171 // all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
172 set_config('unicodedb', 1);
173
015e946d 174 /// Continue with the instalation
f33e1ed4 175 $DB->set_debug(false);
eee5d9bb 176
177 /// Groups install is now in core above.
178
179 // Install the roles system.
180 moodle_install_roles();
181
120b3758 182 // Install core event handlers
eee5d9bb 183 events_update_definition();
184
120b3758 185 // Install core message providers
186 require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
187 message_update_providers();
188
eee5d9bb 189 /// This is used to handle any settings that must exist in $CFG but which do not exist in
190 /// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
191 apply_default_exception_settings(array('auth' => 'email',
192 'auth_pop3mailbox' => 'INBOX',
193 'enrol' => 'manual',
194 'enrol_plugins_enabled' => 'manual',
195 'style' => 'default',
196 'template' => 'default',
197 'theme' => 'standardwhite',
198 'filter_multilang_converted' => 1));
199
200 // Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
201 // (this should only have any effect during initial install).
202 admin_apply_default_settings(NULL, true);
203
204 notify($strdatabasesuccess, "green");
205 require_once $CFG->dirroot.'/mnet/lib.php';
206
f1700fab 207 print_continue('index.php');
acdd790f 208 print_footer('none');
f9903ed0 209 die;
210 }
211
f28db22d 212
74944b73 213/// Check version of Moodle code on disk compared with database
214/// and upgrade if possible.
c3175af5 215 require_once("$CFG->dirroot/lib/db/upgrade.php"); # defines new upgrades
cbd1170e 216
69817927 217 $stradministration = get_string("administration");
218
6e3e7e0e 219 if ($CFG->version) {
74944b73 220 if ($version > $CFG->version) { // upgrade
69817927 221
47bc16f6 222 /// If the database is not already Unicode then we do not allow upgrading!
223 /// Instead, we print an error telling them to upgrade to 1.7 first. MDL-6857
224 if (empty($CFG->unicodedb)) {
225 print_error('unicodeupgradeerror', 'error', '', $version);
226 }
227
69817927 228 $a->oldversion = "$CFG->release ($CFG->version)";
229 $a->newversion = "$release ($version)";
169d3404 230 $strdatabasechecking = get_string("databasechecking", "", $a);
69817927 231
aa893d6b 232 // hide errors from headers in case debug is enabled
233 $origdebug = $CFG->debug;
7eb0b60a 234 $CFG->debug = DEBUG_MINIMAL;
aa893d6b 235 error_reporting($CFG->debug);
236
3483ea57 237 // logo ut in case we are upgrading from pre 1.9 version in order to prevent
238 // weird session/role problems caused by incorrect data in USER and SESSION
239 if ($CFG->version < 2007101500) {
aa893d6b 240 require_logout();
241 }
242
993ef10d 243 if (empty($confirmupgrade)) {
f1af7aaa 244 $navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc')));
245 print_header($strdatabasechecking, $stradministration, $navigation,
69817927 246 "", "", false, "&nbsp;", "&nbsp;");
d210e12e 247
371a32e3 248 notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=1', 'index.php');
e225e5fa 249 print_footer('none');
69817927 250 exit;
6e3e7e0e 251
371a32e3 252 } else if (empty($confirmrelease)){
253 $strcurrentrelease = get_string("currentrelease");
f1af7aaa 254 $navigation = build_navigation(array(array('name'=>$strcurrentrelease, 'link'=>null, 'type'=>'misc')));
255 print_header($strcurrentrelease, $strcurrentrelease, $navigation, "", "", false, "&nbsp;", "&nbsp;");
371a32e3 256 print_heading("Moodle $release");
257 print_box(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'));
29e05913 258
259 require_once($CFG->libdir.'/environmentlib.php');
260 print_heading(get_string('environment', 'admin'));
261 if (!check_moodle_environment($release, $environment_results, true)) {
045fe536 262 print_box_start('generalbox', 'notice'); // MDL-8330
263 print_string('langpackwillbeupdated', 'admin');
264 print_box_end();
f1af7aaa 265 notice_yesno(get_string('environmenterrorupgrade', 'admin'),
29e05913 266 'index.php?confirmupgrade=1&confirmrelease=1', 'index.php');
267 } else {
268 notify(get_string('environmentok', 'admin'), 'notifysuccess');
045fe536 269 print_box_start('generalbox', 'notice'); // MDL-8330
270 print_string('langpackwillbeupdated', 'admin');
220a90c5 271 print_box_end();
2ce10f29 272 echo '<form action="index.php"><div>';
29e05913 273 echo '<input type="hidden" name="confirmupgrade" value="1" />';
274 echo '<input type="hidden" name="confirmrelease" value="1" />';
2ce10f29 275 echo '</div>';
09d58b85 276 echo '<div class="continuebutton">';
29e05913 277 echo '<br /><br /><input type="submit" value="'.get_string('continue').'" /></div>';
278 echo '</form>';
279 }
280
371a32e3 281 print_footer('none');
282 die;
eee5d9bb 283 } elseif (empty($confirmplugincheck)) {
1e92bb91 284 $strplugincheck = get_string('plugincheck');
285 $navigation = build_navigation(array(array('name'=>$strplugincheck, 'link'=>null, 'type'=>'misc')));
286 print_header($strplugincheck, $strplugincheck, $navigation, "", "", false, "&nbsp;", "&nbsp;");
287 print_heading($strplugincheck);
288 print_box_start('generalbox', 'notice'); // MDL-8330
289 print_string('pluginchecknotice');
290 print_box_end();
291 print_plugin_tables();
292 echo "<br />";
95f9fa4d 293 echo '<div class="continuebutton">';
294 print_single_button('index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1), get_string('reload'), 'get');
295 echo '</div><br />';
09d58b85 296 echo '<form action="index.php"><div>';
297 echo '<input type="hidden" name="confirmupgrade" value="1" />';
298 echo '<input type="hidden" name="confirmrelease" value="1" />';
299 echo '<input type="hidden" name="confirmplugincheck" value="1" />';
300 echo '</div>';
301 echo '<div class="continuebutton"><input name="autopilot" id="autopilot" type="checkbox" value="1" /><label for="autopilot">'.get_string('unattendedoperation', 'admin').'</label>';
302 echo '<br /><br /><input type="submit" value="'.get_string('continue').'" /></div>';
303 echo '</form>';
1e92bb91 304 print_footer('none');
305 die();
eee5d9bb 306
69817927 307 } else {
308 $strdatabasesuccess = get_string("databasesuccess");
f1af7aaa 309 $navigation = build_navigation(array(array('name'=>$strdatabasesuccess, 'link'=>null, 'type'=>'misc')));
310 print_header($strdatabasechecking, $stradministration, $navigation,
371a32e3 311 "", upgrade_get_javascript(), false, "&nbsp;", "&nbsp;");
d210e12e 312
aa893d6b 313 /// return to original debugging level
314 $CFG->debug = $origdebug;
315 error_reporting($CFG->debug);
583fad99 316 upgrade_log_start();
d210e12e 317
318 /// Upgrade current language pack if we can
f1af7aaa 319 upgrade_language_pack();
d210e12e 320
69817927 321 print_heading($strdatabasechecking);
f33e1ed4 322 $DB->set_debug(true);
3430fb29 323 /// Launch the old main upgrade (if exists)
324 $status = true;
325 if (function_exists('main_upgrade')) {
326 $status = main_upgrade($CFG->version);
327 }
c779eb1a 328 /// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
f2e0049d 329 if ($status && function_exists('xmldb_main_upgrade')) {
c779eb1a 330 $status = xmldb_main_upgrade($CFG->version);
331 }
f33e1ed4 332 $DB->set_debug(false);
c779eb1a 333 /// If successful, continue upgrading roles and setting everything properly
334 if ($status) {
a5ca5003 335 if (!update_capabilities()) {
78664df0 336 print_error('cannotupgradecapabilities', 'debug');
bbbf2d40 337 }
5811a8e8 338
120b3758 339 // Update core events
109463e4 340 events_update_definition();
f1af7aaa 341
120b3758 342 // Update core message providers
343 require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
344 message_update_providers();
345
69817927 346 if (set_config("version", $version)) {
d6ead3a2 347 remove_dir($CFG->dataroot . '/cache', true); // flush cache
69817927 348 notify($strdatabasesuccess, "green");
f1700fab 349 print_continue("upgradesettings.php");
acdd790f 350 print_footer('none');
69817927 351 exit;
352 } else {
78664df0 353 print_error('cannotupdateversion', 'debug');
69817927 354 }
c779eb1a 355 /// Main upgrade not success
cbd1170e 356 } else {
d02bc6ce 357 notify('Main Upgrade failed! See lib/db/upgrade.php');
1e92bb91 358 print_continue('index.php?confirmupgrade=1&amp;confirmrelease=1&amp;confirmplugincheck=1');
d02bc6ce 359 print_footer('none');
360 die;
cbd1170e 361 }
583fad99 362 upgrade_log_finish();
cbd1170e 363 }
74944b73 364 } else if ($version < $CFG->version) {
dedb2304 365 upgrade_log_start();
cbd1170e 366 notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
dedb2304 367 upgrade_log_finish();
cbd1170e 368 }
cbd1170e 369 } else {
d87a9d73 370 if (!set_config("version", $version)) {
78664df0 371 print_error('cannotupdateversion', 'debug');
cbd1170e 372 }
373 }
374
74944b73 375/// Updated human-readable release version if necessary
c646b70d 376
b35f948b 377 if ($release <> $CFG->release) { // Update the release version
b35f948b 378 if (!set_config("release", $release)) {
78664df0 379 print_error("cannotupdaterelease", 'debug');
c646b70d 380 }
c646b70d 381 }
2eb68e6f 382
2524b0f2 383/// Groups install/upgrade is now in core above.
e4be47a0 384
385
0143fb9f 386/// Find and check all main modules and load them up or upgrade them if necessary
420f6836 387/// first old *.php update and then the new upgrade.php script
0143fb9f 388 upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
389
5bf3aee8 390/// Check all questiontype plugins and upgrade if necessary
420f6836 391/// first old *.php update and then the new upgrade.php script
392/// It is important that this is done AFTER the quiz module has been upgraded
effbd108 393 upgrade_plugins('qtype', 'question/type', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
5bf3aee8 394
10dcde40 395/// Upgrade backup/restore system if necessary
420f6836 396/// first old *.php update and then the new upgrade.php script
10dcde40 397 require_once("$CFG->dirroot/backup/lib.php");
398 upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
10dcde40 399
0f3fe4b6 400/// Upgrade blocks system if necessary
420f6836 401/// first old *.php update and then the new upgrade.php script
0f3fe4b6 402 require_once("$CFG->dirroot/lib/blocklib.php");
403 upgrade_blocks_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
404
405/// Check all blocks and load (or upgrade them if necessary)
420f6836 406/// first old *.php update and then the new upgrade.php script
0f3fe4b6 407 upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
6deb891b 408
1108bebd 409/// Check all enrolment plugins and upgrade if necessary
420f6836 410/// first old *.php update and then the new upgrade.php script
ead29342 411 upgrade_plugins('enrol', 'enrol', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
6e3e7e0e 412
0e13d28f 413/// Check all auth plugins and upgrade if necessary
414 upgrade_plugins('auth','auth',"$CFG->wwwroot/$CFG->admin/index.php");
415
ae628043 416/// Check all course formats and upgrade if necessary
417 upgrade_plugins('format','course/format',"$CFG->wwwroot/$CFG->admin/index.php");
418
43e664cc 419/// Check for local database customisations
420f6836 420/// first old *.php update and then the new upgrade.php script
43e664cc 421 require_once("$CFG->dirroot/lib/locallib.php");
422 upgrade_local_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
c88f014a 423
d14383e0 424/// Check for changes to RPC functions
220a90c5 425 require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
d14383e0 426 upgrade_RPC_functions("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
427
ce34ed3a 428/// Upgrade all plugins for gradebook
429 upgrade_plugins('gradeexport', 'grade/export', "$CFG->wwwroot/$CFG->admin/index.php");
430 upgrade_plugins('gradeimport', 'grade/import', "$CFG->wwwroot/$CFG->admin/index.php");
431 upgrade_plugins('gradereport', 'grade/report', "$CFG->wwwroot/$CFG->admin/index.php");
d14383e0 432
c023ea03 433/// Check all message output plugins and upgrade if necessary
434 upgrade_plugins('message','message/output',"$CFG->wwwroot/$CFG->admin/index.php");
435
d9b06327 436/// Check all admin report plugins and upgrade if necessary
437 upgrade_plugins('report', $CFG->admin.'/report', "$CFG->wwwroot/$CFG->admin/index.php");
438
7cdd8b22 439/// Check all quiz report plugins and upgrade if necessary
abcaa273 440 upgrade_plugins('quizreport', 'mod/quiz/report', "$CFG->wwwroot/$CFG->admin/index.php");
7cdd8b22 441
67a87e7d 442/// Check all portfolio plugins and upgrade if necessary
443 upgrade_plugins('portfolio', 'portfolio/type', "$CFG->wwwroot/$CFG->admin/index.php");
c023ea03 444
583fad99 445/// just make sure upgrade logging is properly terminated
446 upgrade_log_finish();
74944b73 447
7cdd8b22 448 unset($SESSION->installautopilot);
371a32e3 449
e0f6e995 450/// Set up the blank site - to be customized later at the end of install.
a83fded1 451 if (! $site = get_site()) {
e0f6e995 452 // We are about to create the site "course"
02cc05a7 453 require_once($CFG->libdir.'/blocklib.php');
e0f6e995 454
c626c2f4 455 $newsite = new object();
e0f6e995 456 $newsite->fullname = "";
457 $newsite->shortname = "";
c626c2f4 458 $newsite->summary = NULL;
e0f6e995 459 $newsite->newsitems = 3;
460 $newsite->numsections = 0;
461 $newsite->category = 0;
462 $newsite->format = 'site'; // Only for this course
463 $newsite->teacher = get_string("defaultcourseteacher");
464 $newsite->teachers = get_string("defaultcourseteachers");
465 $newsite->student = get_string("defaultcoursestudent");
466 $newsite->students = get_string("defaultcoursestudents");
467 $newsite->timemodified = time();
468
f33e1ed4 469 if (!$newid = $DB->insert_record('course', $newsite)) {
78664df0 470 print_error('cannotsetupsite', 'error');
c626c2f4 471 }
472 // make sure course context exists
473 get_context_instance(CONTEXT_COURSE, $newid);
e0f6e995 474
c626c2f4 475 // Site created, add blocks for it
476 $page = page_create_object(PAGE_COURSE_VIEW, $newid);
477 blocks_repopulate_page($page); // Return value not checked because you can always edit later
1d28d87b 478
0cbe8111 479 // create default course category
480 $cat = get_course_category();
c626c2f4 481
482 redirect('index.php');
f9903ed0 483 }
484
b1631fef 485 // initialise default blocks on admin and site page if needed
02cc05a7 486 if (empty($CFG->adminblocks_initialised)) {
487 require_once("$CFG->dirroot/$CFG->admin/pagelib.php");
488 require_once($CFG->libdir.'/blocklib.php');
489 page_map_class(PAGE_ADMIN, 'page_admin');
490 $page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
491 blocks_repopulate_page($page);
b1631fef 492
493 //add admin_tree block to site if not already present
f33e1ed4 494 if ($admintree = $DB->get_record('block', array('name'=>'admin_tree'))) {
b1631fef 495 $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
2d80e388 496 $pageblocks=blocks_get_by_page($page);
497 blocks_execute_action($page, $pageblocks, 'add', (int)$admintree->id, false, false);
f33e1ed4 498 if ($admintreeinstance = $DB->get_record('block_instance', array('pagetype'=>$page->type, 'pageid'=>SITEID, 'blockid'=>$admintree->id))) {
2d80e388 499 $pageblocks=blocks_get_by_page($page);
500 blocks_execute_action($page, $pageblocks, 'moveleft', $admintreeinstance, false, false);
eef868d1 501 }
b1631fef 502 }
64c4f9c4 503
504 set_config('adminblocks_initialised', 1);
02cc05a7 505 }
506
a61b898a 507/// Define the unique site ID code if it isn't already
508 if (empty($CFG->siteidentifier)) { // Unique site identification code
d53a487d 509 set_config('siteidentifier', random_string(32).$_SERVER['HTTP_HOST']);
a61b898a 510 }
ee1fb969 511
7b3c273b 512/// ugly hack - if mnet is not initialised include the mnet lib, it adds needed mnet records and configures config options
513/// we should not do such crazy stuff in lib functions!!!
514 if (empty($CFG->mnet_localhost_id)) {
515 require_once $CFG->dirroot.'/mnet/lib.php';
516 }
517
e163bf2d 518/// Check if the guest user exists. If not, create one.
f33e1ed4 519 if (!$DB->record_exists('user', array('username'=>'guest'))) {
08103c93 520 if (! $guest = create_guest_record()) {
e163bf2d 521 notify("Could not create guest user record !!!");
522 }
523 }
a61b898a 524
74944b73 525/// Set up the admin user
e0f6e995 526 if (empty($CFG->rolesactive)) {
8a4d32d8 527 build_context_path(); // just in case - should not be needed
ad6226fb 528 create_admin_user();
2be8b28f 529 }
530
cb0e9fbd 531/// Check for valid admin user - no guest autologin
532 require_login(0, false);
01f29000 533
957f6fc9 534 $context = get_context_instance(CONTEXT_SYSTEM);
bbbf2d40 535
f2e21e6c 536 require_capability('moodle/site:config', $context);
537
e0f6e995 538/// check that site is properly customized
8e5da17a 539 if (empty($site->shortname)) {
540 // probably new installation - lets return to frontpage after this step
e9180ff8 541 // remove settings that we want uninitialised
542 unset_config('registerauth');
8e5da17a 543 redirect('upgradesettings.php?return=site');
e0f6e995 544 }
f9903ed0 545
a2a3c590 546/// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
547
993ef10d 548 if (!empty($id)) {
549 if ($id == $CFG->siteidentifier) {
a2a3c590 550 set_config('registered', time());
551 }
552 }
553
220a90c5 554 $adminroot =& admin_get_root();
2acc1f96 555
556/// Check if there are any new admin settings which have still yet to be set
220a90c5 557 if (any_new_admin_settings($adminroot)){
2acc1f96 558 redirect('upgradesettings.php');
559 }
560
6e0993ee 561/// Everything should now be set up, and the user is an admin
f9903ed0 562
6e0993ee 563/// Print default admin page with notifications.
90a73bb3 564
1ae083e4 565 admin_externalpage_setup('adminnotifications');
566 admin_externalpage_print_header();
6e0993ee 567
cb8229d0 568/// Deprecated database! Warning!!
569 if (!empty($CFG->migrated_to_new_db)) {
4ed13ed8 570 print_box(print_string('dbmigrationdeprecateddb', 'admin'), 'generalbox adminwarning');
cb8229d0 571 }
572
6e0993ee 573/// Check for any special upgrades that might need to be run
eef868d1 574 if (!empty($CFG->upgrade)) {
0a8d5d77 575 print_box(get_string("upgrade$CFG->upgrade", "admin", "$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"));
4da1a0a1 576 }
577
bb7152cc 578 if (ini_get_bool('register_globals')) {
579 print_box(get_string('globalswarning', 'admin'), 'generalbox adminwarning');
3699264c 580 }
581
57e35f32 582 if (is_dataroot_insecure()) {
4ed13ed8 583 print_box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning');
57e35f32 584 }
585
b3732604 586 if (defined('WARN_DISPLAY_ERRORS_ENABLED')) {
587 print_box(get_string('displayerrorswarning', 'admin'), 'generalbox adminwarning');
588 }
589
93b2ed94 590 if (substr($CFG->wwwroot, -1) == '/') {
591 print_box(get_string('cfgwwwrootslashwarning', 'admin'), 'generalbox adminwarning');
592 }
593 if (strpos($ME, $CFG->httpswwwroot.'/') === false) {
594 print_box(get_string('cfgwwwrootwarning', 'admin'), 'generalbox adminwarning');
595 }
596
35de9e24 597/// If no recently cron run
a5d424df 598 $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
35de9e24 599 if (time() - $lastcron > 3600 * 24) {
0301965a 600 $strinstallation = get_string('installation', 'install');
601 $helpbutton = helpbutton('install', $strinstallation, 'moodle', true, false, '', true);
4ed13ed8 602 print_box(get_string('cronwarning', 'admin')."&nbsp;".$helpbutton, 'generalbox adminwarning');
35de9e24 603 }
604
f16242ce 605/// Print multilang upgrade notice if needed
606 if (empty($CFG->filter_multilang_converted)) {
4ed13ed8 607 print_box(get_string('multilangupgradenotice', 'admin'), 'generalbox adminwarning');
f16242ce 608 }
609
1695b680 610/// Alert if we are currently in maintenance mode
611 if (file_exists($CFG->dataroot.'/1/maintenance.html')) {
4ed13ed8 612 print_box(get_string('sitemaintenancewarning', 'admin'), 'generalbox adminwarning');
799ce77d 613 }
614
1695b680 615
b27b1473 616/// Print slightly annoying registration button
617 $options = array();
618 $options['sesskey'] = $USER->sesskey;
619 print_box_start('generalbox adminwarning');
620 if(!isset($CFG->registered)) {
621 print_string('pleaseregister', 'admin');
a2a3c590 622 }
b27b1473 623 else { /* if (isset($CFG->registered) && $CFG->registered < (time() - 3600*24*30*6)) { */
624 print_string('pleaserefreshregistration', 'admin', userdate($CFG->registered));
625 }
626 print_single_button('register.php', $options, get_string('registration'));
627 print_box_end();
628
a2a3c590 629
c15421f2 630 //////////////////////////////////////////////////////////////////////////////////////////////////
e4d81c60 631 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
e58e1a94 632 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
8cd94820 633 '<a href="http://docs.moodle.org/en/Release" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
c4d044b5 634 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
e4d81c60 635 'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />'.
c4d044b5 636 '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
0a8d5d77 637 print_box($copyrighttext, 'copyright');
c15421f2 638 //////////////////////////////////////////////////////////////////////////////////////////////////
55e4b5f9 639
1ae083e4 640 admin_externalpage_print_footer();
74944b73 641
2f8d2e1a 642?>