Automatic installer.php lang files by installer_builder (20081224)
[moodle.git] / admin / index.php
blobee8f2fc9cf4a406c8133f029ef27c8d16cab21da
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 /// 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;
17 /// Turn off time limits and try to flush everything all the time, sometimes upgrades can be slow.
19 @set_time_limit(0);
20 @ob_implicit_flush(true);
21 while(@ob_end_clean()); // ob_end_flush prevents sending of headers
24 require_once('../config.php');
25 include_once($CFG->dirroot.'/lib/adminlib.php'); // Contains various admin-only functions
27 $id = optional_param('id', '', PARAM_ALPHANUM);
28 $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
29 $agreelicence = optional_param('agreelicence',0, PARAM_BOOL);
32 /// Check some PHP server settings
34 $documentationlink = "please read the <a href=\"../doc/?frame=install.html&amp;sub=webserver\">install documentation</a>";
36 if (ini_get_bool('session.auto_start')) {
37 error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
40 if (ini_get_bool('magic_quotes_runtime')) {
41 error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink");
44 if (!ini_get_bool('file_uploads')) {
45 error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
49 /// Check that config.php has been edited
51 if ($CFG->wwwroot == "http://example.com/moodle") {
52 error("Moodle has not been configured yet. You need to edit config.php first.");
56 /// Check settings in config.php
58 $dirroot = dirname(realpath("../index.php"));
59 if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
60 error("Please fix your settings in config.php:
61 <p>You have:
62 <p>\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
63 <p>but it should be:
64 <p>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
65 "./");
68 /// Set some necessary variables during set-up to avoid PHP warnings later on this page
69 if (!isset($CFG->framename)) {
70 $CFG->framename = "_top";
72 if (!isset($CFG->release)) {
73 $CFG->release = "";
75 if (!isset($CFG->version)) {
76 $CFG->version = "";
79 /// Check if the main tables have been installed yet or not.
81 if (! $tables = $db->Metatables() ) { // No tables yet at all.
82 $maintables = false;
84 } else { // Check for missing main tables
85 $maintables = true;
86 $mtables = array("config", "course", "course_categories", "course_modules",
87 "course_sections", "log", "log_display", "modules",
88 "user", "user_admins", "user_students", "user_teachers");
89 foreach ($mtables as $mtable) {
90 if (!in_array($CFG->prefix.$mtable, $tables)) {
91 $maintables = false;
92 break;
97 if (! $maintables) {
98 if (empty($agreelicence)) {
99 $strlicense = get_string("license");
100 print_header($strlicense, $strlicense, $strlicense, "", "", false, "&nbsp;", "&nbsp;");
101 print_heading("<a href=\"http://moodle.org\">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment");
102 print_heading(get_string("copyrightnotice"));
103 print_simple_box_start('center');
104 echo text_to_html(get_string("gpl"));
105 print_simple_box_end();
106 echo "<br />";
107 notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
108 "http://docs.moodle.org/en/License");
109 exit;
112 $strdatabasesetup = get_string("databasesetup");
113 $strdatabasesuccess = get_string("databasesuccess");
114 print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup, "", "", false, "&nbsp;", "&nbsp;");
115 if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
116 $db->debug = true;
117 if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
118 $db->debug = false;
119 notify($strdatabasesuccess, "green");
120 } else {
121 $db->debug = false;
122 error("Error: Main databases NOT set up successfully");
124 } else {
125 error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle. See the lib/db directory.");
127 print_continue("index.php");
128 die;
132 /// Check version of Moodle code on disk compared with database
133 /// and upgrade if possible.
135 include_once("$CFG->dirroot/version.php"); # defines $version
136 include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines upgrades
138 $stradministration = get_string("administration");
140 if ($CFG->version) {
141 if ($version > $CFG->version) { // upgrade
143 $a->oldversion = "$CFG->release ($CFG->version)";
144 $a->newversion = "$release ($version)";
145 $strdatabasechecking = get_string("databasechecking", "", $a);
147 if (empty($confirmupgrade)) {
148 print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
149 "", "", false, "&nbsp;", "&nbsp;");
150 notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=yes', 'index.php');
151 exit;
153 } else {
154 $strdatabasesuccess = get_string("databasesuccess");
155 print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
156 "", "", false, "&nbsp;", "&nbsp;");
157 print_heading($strdatabasechecking);
158 $db->debug=true;
159 if (main_upgrade($CFG->version)) {
160 $db->debug=false;
161 if (set_config("version", $version)) {
162 remove_dir($CFG->dataroot . '/cache', true); // flush cache
163 notify($strdatabasesuccess, "green");
164 print_continue("index.php");
165 exit;
166 } else {
167 notify("Upgrade failed! (Could not update version in config table)");
169 } else {
170 $db->debug=false;
171 notify("Upgrade failed! See /version.php");
174 } else if ($version < $CFG->version) {
175 notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
178 } else {
179 $strcurrentversion = get_string("currentversion");
180 print_header($strcurrentversion, $stradministration, $strcurrentversion,
181 "", "", false, "&nbsp;", "&nbsp;");
183 if (!set_config("version", $version)) {
184 $db->debug=true;
185 if (main_upgrade(0)) {
186 print_continue("index.php");
187 } else {
188 error("A problem occurred inserting current version into databases");
190 $db->debug=false;
194 /// Updated human-readable release version if necessary
196 if ($release <> $CFG->release) { // Update the release version
197 $strcurrentrelease = get_string("currentrelease");
198 print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, "&nbsp;", "&nbsp;");
199 print_heading("Moodle $release");
200 if (!set_config("release", $release)) {
201 notify("ERROR: Could not update release version in database!!");
203 notice(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'), 'index.php');
204 exit;
207 /// Insert default values for any important configuration variables
209 include_once("$CFG->dirroot/lib/defaults.php");
211 foreach ($defaults as $name => $value) {
212 if (!isset($CFG->$name)) {
213 $CFG->$name = $value;
214 set_config($name, $value);
215 $configchange = true;
219 /// Send $CFG->unicodedb to DB to have it available for next requests
220 set_config('unicodedb', $CFG->unicodedb);
222 /// If any new configurations were found then send to the config page to check
224 if (!empty($configchange)) {
225 redirect("config.php?installing=1");
228 /// Find and check all main modules and load them up or upgrade them if necessary
229 upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
231 /// Check all questiontype plugins and upgrade if necessary
232 // It is important that this is done AFTER the quiz module has been upgraded
233 upgrade_plugins('qtype', 'question/type', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
235 /// Upgrade backup/restore system if necessary
236 require_once("$CFG->dirroot/backup/lib.php");
237 upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
239 /// Upgrade blocks system if necessary
240 require_once("$CFG->dirroot/lib/blocklib.php");
241 upgrade_blocks_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
243 /// Check all blocks and load (or upgrade them if necessary)
244 upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
246 /// Check all enrolment plugins and upgrade if necessary
247 upgrade_plugins('enrol', 'enrol', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
249 /// Check for local database customisations
250 require_once("$CFG->dirroot/lib/locallib.php");
251 upgrade_local_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
254 /// Set up the overall site name etc.
255 if (! $site = get_site()) {
256 redirect("site.php");
259 /// Define the unique site ID code if it isn't already
260 if (empty($CFG->siteidentifier)) { // Unique site identification code
261 set_config('siteidentifier', random_string(32).$_SERVER['HTTP_HOST']);
264 /// Check if the guest user exists. If not, create one.
265 if (! record_exists("user", "username", "guest")) {
266 $guest->auth = "manual";
267 $guest->username = "guest";
268 $guest->password = md5("guest");
269 $guest->firstname = addslashes(get_string("guestuser"));
270 $guest->lastname = " ";
271 $guest->email = "root@localhost";
272 $guest->description = addslashes(get_string("guestuserinfo"));
273 $guest->confirmed = 1;
274 $guest->lang = $CFG->lang;
275 $guest->timemodified= time();
277 if (! $guest->id = insert_record("user", $guest)) {
278 notify("Could not create guest user record !!!");
282 /// Set up the admin user
283 if (! record_exists("user_admins")) { // No admin user yet
284 redirect("user.php");
287 /// Check for valid admin user
288 require_login();
290 if (!isadmin()) {
291 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
294 /// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
296 if (!empty($id)) {
297 if ($id == $CFG->siteidentifier) {
298 set_config('registered', time());
302 /// At this point everything is set up and the user is an admin, so print menu
304 $stradministration = get_string("administration");
305 print_header("$site->shortname: $stradministration","$site->fullname", "$stradministration");
306 print_simple_box_start('center', '100%', '', 20);
307 print_heading($stradministration);
309 /// Deprecated database! Warning!!
310 if (!empty($CFG->migrated_to_new_db)) {
311 print_simple_box_start('center','60%');
312 print_string('dbmigrationdeprecateddb','admin');
313 print_simple_box_end();
316 if (!empty($CFG->upgrade)) { // Print notice about extra upgrading that needs to be done
317 print_simple_box(get_string("upgrade$CFG->upgrade", "admin",
318 "$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"), "center", '60%');
319 print_spacer(10,10);
322 if (ini_get_bool('register_globals')) {
323 print_simple_box(get_string('globalswarning', 'admin'), 'center', '60%');
326 if (is_dataroot_insecure()) {
327 print_simple_box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'center', '60%');
330 /// If no recently cron run
331 $lastcron = get_field_sql('SELECT max(lastcron) FROM ' . $CFG->prefix . 'modules');
332 if (time() - $lastcron > 3600 * 24) {
333 $strinstallation = get_string('installation', 'install');
334 $helpbutton = helpbutton('install', $strinstallation, 'moodle', true, false, '', true);
335 print_simple_box(get_string('cronwarning', 'admin')."&nbsp;".$helpbutton, 'center', '60%');
338 /// Alert if we are currently in maintenance mode
339 if (file_exists($CFG->dataroot.'/1/maintenance.html')) {
340 print_simple_box(get_string('sitemaintenancewarning', 'admin') , 'center', '60%');
343 /// Alert if we are currently in maintenance mode
344 if (empty($CFG->unicodedb)) {
345 print_simple_box(get_string('unicodeupgradenotice', 'admin') , 'center', '60%');
348 /// Print slightly annoying registration button every six months ;-)
349 /// You can set the "registered" variable to something far in the future
350 /// if you really want to prevent this. eg 9999999999
351 if (!isset($CFG->registered) || $CFG->registered < (time() - 3600*24*30*6)) {
352 $options = array();
353 $options['sesskey'] = $USER->sesskey;
354 print_simple_box_start('center','60%');
355 echo '<div align="center">';
356 print_string('pleaseregister', 'admin');
357 print_single_button('register.php', $options, get_string('registration'));
358 echo '</div>';
359 print_simple_box_end();
362 $table->tablealign = "center";
363 $table->align = array ("right", "left");
364 $table->wrap = array ("nowrap", "nowrap");
365 $table->cellpadding = 5;
366 $table->cellspacing = 0;
367 $table->width = '40%';
369 $configdata = '<div class="adminlink"><a href="config.php">'.get_string('configvariables', 'admin').
370 '</a> - <span class="explanation">'.get_string('adminhelpconfigvariables').'</span></div>';
371 $configdata .= '<div class="adminlink"><a href="site.php">'.get_string('sitesettings').
372 '</a> - <span class="explanation">'.get_string('adminhelpsitesettings').'</span></div>';
373 $configdata .= '<div class="adminlink"><a href="../theme/index.php">'.get_string('themes').
374 '</a> - <span class="explanation">'.get_string('adminhelpthemes').'</span></div>';
375 $configdata .= '<div class="adminlink"><a href="lang.php">'.get_string('language').
376 '</a> - <span class="explanation">'.get_string('adminhelplanguage').'</span></div>';
377 $configdata .= '<div class="adminlink"><a href="modules.php">'.get_string('managemodules').
378 '</a> - <span class="explanation">'.get_string('adminhelpmanagemodules').'</span></div>';
379 $configdata .= '<div class="adminlink"><a href="blocks.php">'.get_string('manageblocks').
380 '</a> - <span class="explanation">'.get_string('adminhelpmanageblocks').'</span></div>';
381 $configdata .= '<div class="adminlink"><a href="filters.php">'.get_string('managefilters').
382 '</a> - <span class="explanation">'.get_string('adminhelpmanagefilters').'</span></div>';
383 if (!isset($CFG->disablescheduledbackups)) {
384 $configdata .= '<div class="adminlink"><a href="backup.php">'.get_string('backup').
385 '</a> - <span class="explanation">'.get_string('adminhelpbackup').'</span></div>';
387 $configdata .= '<div class="adminlink"><a href="editor.php">'.get_string('editorsettings').
388 '</a> - <span class="explanation">'.get_string('adminhelpeditorsettings').'</span></div>';
389 $configdata .= '<div class="adminlink"><a href="calendar.php">'.get_string('calendarsettings', 'admin').
390 '</a> - <span class="explanation">'.get_string('helpcalendarsettings', 'admin').'</span></div>';
391 $configdata .= '<div class="adminlink"><a href="maintenance.php">'.get_string('sitemaintenancemode', 'admin').
392 '</a> - <span class="explanation">'.get_string('helpsitemaintenance', 'admin').'</span></div>';
394 $table->data[] = array('<strong><a href="configure.php">'.get_string('configuration').'</a></strong>', $configdata);
397 $userdata = '<div class="adminlink"><a href="auth.php?sesskey='.$USER->sesskey.'">'.get_string("authentication").
398 '</a> - <span class="explanation">'.get_string('adminhelpauthentication').'</span></div>';
399 $userdata .= '<div class="adminlink"><a href="user.php">'.get_string('edituser').
400 '</a> - <span class="explanation">'.get_string('adminhelpedituser').'</span></div>';
401 $userdata .= '<div class="adminlink"><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/user.php?newuser=true&amp;sesskey='.$USER->sesskey.'">'.
402 get_string('addnewuser').'</a> - <span class="explanation">'.get_string('adminhelpaddnewuser').'</span></div>';
403 $userdata .= '<div class="adminlink"><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/uploaduser.php?sesskey='.$USER->sesskey.'">'.
404 get_string('uploadusers').'</a> - <span class="explanation">'.get_string('adminhelpuploadusers').'</span></div>';
406 $table->data[] = array('<strong><a href="users.php">'.get_string('users').'</a></strong>', $userdata);
408 $coursedata = '<div class="adminlink"><a href="../course/index.php?edit=on&amp;sesskey='.$USER->sesskey.'">'.get_string('managecourses').
409 '</a> - <span class="explanation">'.get_string('adminhelpcourses').'</span></div>';
410 $coursedata .= '<div class="adminlink"><a href="enrol.php?sesskey='.$USER->sesskey.'">'.get_string('enrolmentplugins').
411 '</a> - <span class="explanation">'.get_string('adminhelpenrolments').'</span></div>';
412 $coursedata .= '<div class="adminlink"><a href="../course/index.php?edit=off&amp;sesskey='.$USER->sesskey.'">'.
413 get_string('assignstudents').'</a> - <span class="explanation">'.get_string('adminhelpassignstudents').'</span></div>';
414 $coursedata .= '<div class="adminlink"><a href="../course/index.php?edit=on&amp;sesskey='.$USER->sesskey.'">'.
415 get_string('assignteachers').'</a> - <span class="explanation">'.get_string('adminhelpassignteachers').
416 ' <img src="../pix/t/user.gif" height="11" width="11" alt="" /></span></div>';
417 $coursedata .= '<div class="adminlink"><a href="creators.php?sesskey='.$USER->sesskey.'">'.get_string('assigncreators').
418 '</a> - <span class="explanation">'.get_string('adminhelpassigncreators').'</span></div>';
419 $coursedata .= '<div class="adminlink"><a href="admin.php?sesskey='.$USER->sesskey.'">'.get_string('assignadmins').
420 '</a> - <span class="explanation">'.get_string('adminhelpassignadmins').'</span></div>';
422 $table->data[] = array('<strong><a href="courses.php">'.get_string('courses').'</a></strong>', $coursedata);
424 $miscdata = '<div class="adminlink"><a href="../files/index.php?id='.$site->id.'">'.get_string('sitefiles').
425 '</a> - <span class="explanation">'.get_string('adminhelpsitefiles').'</span></div>';
426 $miscdata .= '<div class="adminlink"><a href="stickyblocks.php">'.get_string('stickyblocks','admin').
427 '</a> - <span class="explanation">'.get_string('adminhelpstickyblocks').'</span></div>';
428 $miscdata .= '<div class="adminlink"><a href="report.php">'.get_string('reports').
429 '</a> - <span class="explanation">'.get_string('adminhelpreports').'</span></div>';
430 //to be enabled later
431 /* $miscdata .= '<div class="adminlink"><a href="health.php">'.get_string('healthcenter').
432 '</a> - <span class="explanation">'.get_string('adminhelphealthcenter').'</span></div>';*/
433 $miscdata .= '<div class="adminlink"><a href="environment.php">'.get_string('environment', 'admin').
434 '</a> - <span class="explanation">'.get_string('adminhelpenvironment').'</span></div>';
435 /// Optional stuff
436 if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
437 $miscdata .= '<div class="adminlink"><a href="'.$CFG->dbtype.'/frame.php">'.get_string('managedatabase').
438 '</a> - <span class="explanation">'.get_string('adminhelpmanagedatabase').'</span></div>';
441 $table->data[] = array('<strong><a href="misc.php">'.get_string('miscellaneous').'</a></strong>', $miscdata);
444 /// Hooks for Matt Oquists contrib code for repositories and portfolio.
445 /// The eventual official versions may not look like this
446 if (isset($CFG->portfolio) && file_exists("$CFG->dirroot/$CFG->portfolio")) {
447 $table->data[] = array("<strong><a href=\"../portfolio/\">".get_string('portfolio','portfolio').'</a></
448 trong>',
449 '<div class="explanation">'.get_string('adminhelpportfolio','portfolio').'</div>');
452 if (isset($CFG->repo) && file_exists("$CFG->dirroot/$CFG->repo")) {
453 $table->data[] = array("<strong><a href=\"../repository/?repoid=1&action=list\">".get_string('repository','
454 epository').'</a></strong>',
455 '<div class="explanation">'.get_string('adminhelprepository','repository').'</div>');
460 print_table($table);
462 //////////////////////////////////////////////////////////////////////////////////////////////////
463 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO REMOVE OR MODIFY THE COPYRIGHT NOTICE BELOW ////
464 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
465 '<a href="http://docs.moodle.org/en/Release">'.$CFG->release.'</a> ('.$CFG->version.')<br />'.
466 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
467 '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
468 echo '<p class="copyright">'.$copyrighttext.'</p>';
469 //////////////////////////////////////////////////////////////////////////////////////////////////
472 echo '<div align="center">';
473 $options = array();
474 $options['sesskey'] = $USER->sesskey;
475 print_single_button('register.php', $options, get_string('registration'));
476 echo '</div>';
479 print_simple_box_end();
482 print_footer($site);