OKAY! THIS IS IT! MOODLE 1.6!
[moodle.git] / admin / index.php
blobc78af9422d267dbe5ce745e753758d09554ecc06
1 <?php // $Id$
3 /// Check that config.php exists, if not then call the install script
4 if (!file_exists('../config.php')) {
5 header('Location: ../install.php');
6 die;
9 require_once('../config.php');
10 include_once($CFG->dirroot.'/lib/adminlib.php'); // Contains various admin-only functions
12 $id = optional_param('id', '', PARAM_ALPHANUM);
13 $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
14 $agreelicence = optional_param('agreelicence',0, PARAM_BOOL);
15 /// Check that PHP is of a sufficient version
17 if (!check_php_version("4.1.0")) { //TODO: should we bump it up to 4.3.0??
18 $phpversion = phpversion();
19 print_heading("Sorry, Moodle requires PHP 4.1.0 or later (currently using version $phpversion)");
20 die;
24 /// Check some PHP server settings
26 $documentationlink = "please read the <a href=\"../doc/?frame=install.html&amp;sub=webserver\">install documentation</a>";
28 if (ini_get_bool('session.auto_start')) {
29 error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
32 if (ini_get_bool('magic_quotes_runtime')) {
33 error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink");
36 if (!ini_get_bool('file_uploads')) {
37 error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
41 /// Check that config.php has been edited
43 if ($CFG->wwwroot == "http://example.com/moodle") {
44 error("Moodle has not been configured yet. You need to edit config.php first.");
48 /// Check settings in config.php
50 $dirroot = dirname(realpath("../index.php"));
51 if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
52 error("Please fix your settings in config.php:
53 <p>You have:
54 <p>\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
55 <p>but it should be:
56 <p>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
57 "./");
60 /// Set some necessary variables during set-up to avoid PHP warnings later on this page
61 if (!isset($CFG->framename)) {
62 $CFG->framename = "_top";
64 if (!isset($CFG->release)) {
65 $CFG->release = "";
67 if (!isset($CFG->version)) {
68 $CFG->version = "";
71 /// Turn off time limits and try to flush everything all the time, sometimes upgrades can be slow.
73 @set_time_limit(0);
74 @ob_implicit_flush(true);
75 @ob_end_flush();
78 /// Check if the main tables have been installed yet or not.
80 if (! $tables = $db->Metatables() ) { // No tables yet at all.
81 $maintables = false;
83 } else { // Check for missing main tables
84 $maintables = true;
85 $mtables = array("config", "course", "course_categories", "course_modules",
86 "course_sections", "log", "log_display", "modules",
87 "user", "user_admins", "user_students", "user_teachers");
88 foreach ($mtables as $mtable) {
89 if (!in_array($CFG->prefix.$mtable, $tables)) {
90 $maintables = false;
91 break;
96 if (! $maintables) {
97 if (empty($agreelicence)) {
98 $strlicense = get_string("license");
99 print_header($strlicense, $strlicense, $strlicense, "", "", false, "&nbsp;", "&nbsp;");
100 print_heading("<a href=\"http://moodle.org\">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment");
101 print_heading(get_string("copyrightnotice"));
102 print_simple_box_start('center');
103 echo text_to_html(get_string("gpl"));
104 print_simple_box_end();
105 echo "<br />";
106 notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
107 "http://docs.moodle.org/en/License");
108 exit;
111 $strdatabasesetup = get_string("databasesetup");
112 $strdatabasesuccess = get_string("databasesuccess");
113 print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup, "", "", false, "&nbsp;", "&nbsp;");
114 if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
115 $db->debug = true;
116 if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
117 $db->debug = false;
118 notify($strdatabasesuccess, "green");
119 } else {
120 $db->debug = false;
121 error("Error: Main databases NOT set up successfully");
123 } else {
124 error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle. See the lib/db directory.");
126 print_continue("index.php");
127 die;
131 /// Check version of Moodle code on disk compared with database
132 /// and upgrade if possible.
134 include_once("$CFG->dirroot/version.php"); # defines $version
135 include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines upgrades
137 $stradministration = get_string("administration");
139 if ($CFG->version) {
140 if ($version > $CFG->version) { // upgrade
142 $a->oldversion = "$CFG->release ($CFG->version)";
143 $a->newversion = "$release ($version)";
144 $strdatabasechecking = get_string("databasechecking", "", $a);
146 if (empty($confirmupgrade)) {
147 print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
148 "", "", false, "&nbsp;", "&nbsp;");
149 notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=yes', 'index.php');
150 exit;
152 } else {
153 $strdatabasesuccess = get_string("databasesuccess");
154 print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
155 "", "", false, "&nbsp;", "&nbsp;");
156 print_heading($strdatabasechecking);
157 $db->debug=true;
158 if (main_upgrade($CFG->version)) {
159 $db->debug=false;
160 if (set_config("version", $version)) {
161 remove_dir($CFG->dataroot . '/cache', true); // flush cache
162 notify($strdatabasesuccess, "green");
163 print_continue("index.php");
164 exit;
165 } else {
166 notify("Upgrade failed! (Could not update version in config table)");
168 } else {
169 $db->debug=false;
170 notify("Upgrade failed! See /version.php");
173 } else if ($version < $CFG->version) {
174 notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
177 } else {
178 $strcurrentversion = get_string("currentversion");
179 print_header($strcurrentversion, $stradministration, $strcurrentversion,
180 "", "", false, "&nbsp;", "&nbsp;");
182 if (!set_config("version", $version)) {
183 $db->debug=true;
184 if (main_upgrade(0)) {
185 print_continue("index.php");
186 } else {
187 error("A problem occurred inserting current version into databases");
189 $db->debug=false;
193 /// Updated human-readable release version if necessary
195 if ($release <> $CFG->release) { // Update the release version
196 $strcurrentrelease = get_string("currentrelease");
197 print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, "&nbsp;", "&nbsp;");
198 print_heading("Moodle $release");
199 if (!set_config("release", $release)) {
200 notify("ERROR: Could not update release version in database!!");
202 notice(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'), 'index.php');
203 exit;
206 /// Insert default values for any important configuration variables
208 include_once("$CFG->dirroot/lib/defaults.php");
210 foreach ($defaults as $name => $value) {
211 if (!isset($CFG->$name)) {
212 $CFG->$name = $value;
213 set_config($name, $value);
214 $configchange = true;
218 /// Send $CFG->unicodedb to DB to have it available for next requests
219 set_config('unicodedb', $CFG->unicodedb);
221 /// If any new configurations were found then send to the config page to check
223 if (!empty($configchange)) {
224 redirect("config.php");
227 /// Find and check all main modules and load them up or upgrade them if necessary
228 upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
230 /// Check all questiontype plugins and upgrade if necessary
231 // It is important that this is done AFTER the quiz module has been upgraded
232 upgrade_plugins('qtype', 'question/type', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
234 /// Upgrade backup/restore system if necessary
235 require_once("$CFG->dirroot/backup/lib.php");
236 upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
238 /// Upgrade blocks system if necessary
239 require_once("$CFG->dirroot/lib/blocklib.php");
240 upgrade_blocks_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
242 /// Check all blocks and load (or upgrade them if necessary)
243 upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
245 /// Check all enrolment plugins and upgrade if necessary
246 upgrade_plugins('enrol', 'enrol', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
248 /// Check for local database customisations
249 require_once("$CFG->dirroot/lib/locallib.php");
250 upgrade_local_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
253 /// Set up the overall site name etc.
254 if (! $site = get_site()) {
255 redirect("site.php");
258 /// Define the unique site ID code if it isn't already
259 if (empty($CFG->siteidentifier)) { // Unique site identification code
260 set_config('siteidentifier', random_string(32));
263 /// Check if the guest user exists. If not, create one.
264 if (! record_exists("user", "username", "guest")) {
265 $guest->auth = "manual";
266 $guest->username = "guest";
267 $guest->password = md5("guest");
268 $guest->firstname = addslashes(get_string("guestuser"));
269 $guest->lastname = " ";
270 $guest->email = "root@localhost";
271 $guest->description = addslashes(get_string("guestuserinfo"));
272 $guest->confirmed = 1;
273 $guest->lang = $CFG->lang;
274 $guest->timemodified= time();
276 if (! $guest->id = insert_record("user", $guest)) {
277 notify("Could not create guest user record !!!");
281 /// Set up the admin user
282 if (! record_exists("user_admins")) { // No admin user yet
283 redirect("user.php");
286 /// Check for valid admin user
287 require_login();
289 if (!isadmin()) {
290 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
293 /// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
295 if (!empty($id)) {
296 if ($id == $CFG->siteidentifier) {
297 set_config('registered', time());
301 /// At this point everything is set up and the user is an admin, so print menu
303 $stradministration = get_string("administration");
304 print_header("$site->shortname: $stradministration","$site->fullname", "$stradministration");
305 print_simple_box_start('center', '100%', '', 20);
306 print_heading($stradministration);
308 /// Deprecated database! Warning!!
309 if (!empty($CFG->migrated_to_new_db)) {
310 print_simple_box_start('center','60%');
311 print_string('dbmigrationdeprecateddb','admin');
312 print_simple_box_end();
315 if (!empty($CFG->upgrade)) { // Print notice about extra upgrading that needs to be done
316 print_simple_box(get_string("upgrade$CFG->upgrade", "admin",
317 "$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"), "center", '60%');
318 print_spacer(10,10);
321 if (ini_get_bool('register_globals') && !ini_get_bool('magic_quotes_gpc')) {
322 print_simple_box(get_string('globalsquoteswarning', 'admin'), 'center', '60%');
326 /// If no recently cron run
327 $lastcron = get_field_sql('SELECT max(lastcron) FROM ' . $CFG->prefix . 'modules');
328 if (time() - $lastcron > 3600 * 24) {
329 $strinstallation = get_string('installation', 'install');
330 $helpbutton = helpbutton('install', $strinstallation, 'moodle', true, false, '', true);
331 print_simple_box(get_string('cronwarning', 'admin')."&nbsp;".$helpbutton, 'center', '60%');
334 /// Alert if we are currently in maintenance mode
335 if (file_exists($CFG->dataroot.'/1/maintenance.html')) {
336 print_simple_box(get_string('sitemaintenancewarning', 'admin') , 'center', '60%');
339 /// Alert if we are currently in maintenance mode
340 if (empty($CFG->unicodedb)) {
341 print_simple_box(get_string('unicodeupgradenotice', 'admin') , 'center', '60%');
344 /// Print slightly annoying registration button every six months ;-)
345 /// You can set the "registered" variable to something far in the future
346 /// if you really want to prevent this. eg 9999999999
347 if (!isset($CFG->registered) || $CFG->registered < (time() - 3600*24*30*6)) {
348 $options = array();
349 $options['sesskey'] = $USER->sesskey;
350 print_simple_box_start('center','60%');
351 echo '<div align="center">';
352 print_string('pleaseregister', 'admin');
353 print_single_button('register.php', $options, get_string('registration'));
354 echo '</div>';
355 print_simple_box_end();
358 $table->tablealign = "center";
359 $table->align = array ("right", "left");
360 $table->wrap = array ("nowrap", "nowrap");
361 $table->cellpadding = 5;
362 $table->cellspacing = 0;
363 $table->width = '40%';
365 $configdata = '<div class="adminlink"><a href="config.php">'.get_string('configvariables', 'admin').
366 '</a> - <span class="explanation">'.get_string('adminhelpconfigvariables').'</span></div>';
367 $configdata .= '<div class="adminlink"><a href="site.php">'.get_string('sitesettings').
368 '</a> - <span class="explanation">'.get_string('adminhelpsitesettings').'</span></div>';
369 $configdata .= '<div class="adminlink"><a href="../theme/index.php">'.get_string('themes').
370 '</a> - <span class="explanation">'.get_string('adminhelpthemes').'</span></div>';
371 $configdata .= '<div class="adminlink"><a href="lang.php">'.get_string('language').
372 '</a> - <span class="explanation">'.get_string('adminhelplanguage').'</span></div>';
373 $configdata .= '<div class="adminlink"><a href="modules.php">'.get_string('managemodules').
374 '</a> - <span class="explanation">'.get_string('adminhelpmanagemodules').'</span></div>';
375 $configdata .= '<div class="adminlink"><a href="blocks.php">'.get_string('manageblocks').
376 '</a> - <span class="explanation">'.get_string('adminhelpmanageblocks').'</span></div>';
377 $configdata .= '<div class="adminlink"><a href="filters.php">'.get_string('managefilters').
378 '</a> - <span class="explanation">'.get_string('adminhelpmanagefilters').'</span></div>';
379 if (!isset($CFG->disablescheduledbackups)) {
380 $configdata .= '<div class="adminlink"><a href="backup.php">'.get_string('backup').
381 '</a> - <span class="explanation">'.get_string('adminhelpbackup').'</span></div>';
383 $configdata .= '<div class="adminlink"><a href="editor.php">'.get_string('editorsettings').
384 '</a> - <span class="explanation">'.get_string('adminhelpeditorsettings').'</span></div>';
385 $configdata .= '<div class="adminlink"><a href="calendar.php">'.get_string('calendarsettings', 'admin').
386 '</a> - <span class="explanation">'.get_string('helpcalendarsettings', 'admin').'</span></div>';
387 $configdata .= '<div class="adminlink"><a href="maintenance.php">'.get_string('sitemaintenancemode', 'admin').
388 '</a> - <span class="explanation">'.get_string('helpsitemaintenance', 'admin').'</span></div>';
390 $table->data[] = array('<strong><a href="configure.php">'.get_string('configuration').'</a></strong>', $configdata);
393 $userdata = '<div class="adminlink"><a href="auth.php?sesskey='.$USER->sesskey.'">'.get_string("authentication").
394 '</a> - <span class="explanation">'.get_string('adminhelpauthentication').'</span></div>';
395 $userdata .= '<div class="adminlink"><a href="user.php">'.get_string('edituser').
396 '</a> - <span class="explanation">'.get_string('adminhelpedituser').'</span></div>';
397 $userdata .= '<div class="adminlink"><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/user.php?newuser=true&amp;sesskey='.$USER->sesskey.'">'.
398 get_string('addnewuser').'</a> - <span class="explanation">'.get_string('adminhelpaddnewuser').'</span></div>';
399 $userdata .= '<div class="adminlink"><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/uploaduser.php?sesskey='.$USER->sesskey.'">'.
400 get_string('uploadusers').'</a> - <span class="explanation">'.get_string('adminhelpuploadusers').'</span></div>';
402 $userdata .= '<hr /><div class="adminlink"><a href="enrol.php?sesskey='.$USER->sesskey.'">'.get_string('enrolmentplugins').
403 '</a> - <span class="explanation">'.get_string('adminhelpenrolments').'</span></div>';
404 $userdata .= '<div class="adminlink"><a href="../course/index.php?edit=off&amp;sesskey='.$USER->sesskey.'">'.
405 get_string('assignstudents').'</a> - <span class="explanation">'.get_string('adminhelpassignstudents').'</span></div>';
407 $userdata .= '<div class="adminlink"><a href="../course/index.php?edit=on&amp;sesskey='.$USER->sesskey.'">'.
408 get_string('assignteachers').'</a> - <span class="explanation">'.get_string('adminhelpassignteachers').
409 ' <img src="../pix/t/user.gif" height="11" width="11" alt="" /></span></div>';
410 $userdata .= '<div class="adminlink"><a href="creators.php?sesskey='.$USER->sesskey.'">'.get_string('assigncreators').
411 '</a> - <span class="explanation">'.get_string('adminhelpassigncreators').'</span></div>';
412 $userdata .= '<div class="adminlink"><a href="admin.php?sesskey='.$USER->sesskey.'">'.get_string('assignadmins').
413 '</a> - <span class="explanation">'.get_string('adminhelpassignadmins').'</span></div>';
415 $table->data[] = array('<strong><a href="users.php">'.get_string('users').'</a></strong>', $userdata);
417 $table->data[] = array('<strong><a href="../course/index.php?edit=on&amp;sesskey='.$USER->sesskey.'">'.get_string('courses').'</a></strong>',
418 '<div class="explanation">'.get_string('adminhelpcourses').'</div>');
419 $table->data[] = array('<strong><a href="../files/index.php?id='.$site->id.'">'.get_string('sitefiles').'</a></strong>',
420 '<div class="explanation">'.get_string('adminhelpsitefiles').'</div>');
421 $table->data[] = array('<strong><a href="stickyblocks.php">'.get_string('stickyblocks','admin').'</a></strong>',
422 '<div class="explanation">'.get_string('adminhelpstickyblocks').'</div>');
423 $table->data[] = array('<strong><a href="report.php">'.get_string('reports').'</a></strong>',
424 '<div class="explanation">'.get_string('adminhelpreports').'</div>');
425 $table->data[] = array('<strong><a href="environment.php">'.get_string('environment','admin').'</a></strong>',
426 '<div class="explanation">'.get_string('adminhelpenvironment').'</div>');
428 /// Optional stuff
429 if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
430 $table->data[] = array("<strong><a href=\"$CFG->dbtype/frame.php\">".get_string('managedatabase').'</a></strong>',
431 '<div class="explanation">'.get_string('adminhelpmanagedatabase').'</div>');
434 /// Hooks for Matt Oquists contrib code for repositories and portfolio.
435 /// The eventual official versions may not look like this
436 if (isset($CFG->portfolio) && file_exists("$CFG->dirroot/$CFG->portfolio")) {
437 $table->data[] = array("<strong><a href=\"../portfolio/\">".get_string('portfolio','portfolio').'</a></
438 trong>',
439 '<div class="explanation">'.get_string('adminhelpportfolio','portfolio').'</div>');
442 if (isset($CFG->repo) && file_exists("$CFG->dirroot/$CFG->repo")) {
443 $table->data[] = array("<strong><a href=\"../repository/?repoid=1&action=list\">".get_string('repository','
444 epository').'</a></strong>',
445 '<div class="explanation">'.get_string('adminhelprepository','repository').'</div>');
450 print_table($table);
452 //////////////////////////////////////////////////////////////////////////////////////////////////
453 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO REMOVE OR MODIFY THE COPYRIGHT NOTICE BELOW ////
454 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
455 '<a href="http://docs.moodle.org/en/Release">'.$CFG->release.'</a> ('.$CFG->version.')<br />'.
456 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
457 '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
458 echo '<p class="copyright">'.$copyrighttext.'</p>';
459 //////////////////////////////////////////////////////////////////////////////////////////////////
462 echo '<div align="center">';
463 $options = array();
464 $options['sesskey'] = $USER->sesskey;
465 print_single_button('register.php', $options, get_string('registration'));
466 echo '</div>';
469 print_simple_box_end();
472 if (optional_param('dbmigrate')) { // ??? Is this actually used?
473 print_simple_box_start('center','60%');
474 require_once($CFG->dirroot.'/admin/utfdbmigrate.php');
475 db_migrate2utf8();
476 print_simple_box_end();
480 print_footer($site);