3 /// Check that config.php exists, if not then call the install script
4 if (!file_exists("../config.php")) {
5 header('Location: ../install.php');
9 require_once("../config.php");
10 include_once("$CFG->dirroot/lib/adminlib.php"); // Contains various admin-only functions
13 /// Check that PHP is of a sufficient version
15 if (!check_php_version("4.1.0")) {
16 $version = phpversion();
17 print_heading("Sorry, Moodle requires PHP 4.1.0 or later (currently using version $version)");
22 /// Check some PHP server settings
24 $documentationlink = "please read the <a href=\"../doc/?frame=install.html&sub=webserver\">install documentation</a>";
26 if (ini_get_bool('session.auto_start')) {
27 error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
30 if (ini_get_bool('magic_quotes_runtime')) {
31 error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink");
34 if (!ini_get_bool('file_uploads')) {
35 error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
39 /// Check that config.php has been edited
41 if ($CFG->wwwroot
== "http://example.com/moodle") {
42 error("Moodle has not been configured yet. You need to edit config.php first.");
46 /// Check settings in config.php
48 $dirroot = dirname(realpath("../index.php"));
49 if (!empty($dirroot) and $dirroot != $CFG->dirroot
) {
50 error("Please fix your settings in config.php:
52 <p>\$CFG->dirroot = \"".addslashes($CFG->dirroot
)."\";
54 <p>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
58 /// Set some necessary variables during set-up to avoid PHP warnings later on this page
59 if (!isset($CFG->framename
)) {
60 $CFG->framename
= "_top";
62 if (!isset($CFG->release
)) {
65 if (!isset($CFG->version
)) {
69 /// Turn off time limits and try to flush everything all the time, sometimes upgrades can be slow.
72 @ob_implicit_flush
(true);
76 /// Check if the main tables have been installed yet or not.
78 if (! $tables = $db->Metatables() ) { // No tables yet at all.
81 } else { // Check for missing main tables
83 $mtables = array("config", "course", "course_categories", "course_modules",
84 "course_sections", "log", "log_display", "modules",
85 "user", "user_admins", "user_students", "user_teachers");
86 foreach ($mtables as $mtable) {
87 if (!in_array($CFG->prefix
.$mtable, $tables)) {
95 if (empty($agreelicence)) {
96 $strlicense = get_string("license");
97 print_header($strlicense, $strlicense, $strlicense, "", "", false, " ", " ");
98 print_heading("<a href=\"http://moodle.org\">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment");
99 print_heading(get_string("copyrightnotice"));
100 print_simple_box_start("center");
101 echo text_to_html(get_string("gpl"));
102 print_simple_box_end();
104 notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
105 "http://moodle.org/doc/?frame=licence.html");
109 $strdatabasesetup = get_string("databasesetup");
110 $strdatabasesuccess = get_string("databasesuccess");
111 print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup, "", "", false, " ", " ");
112 if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
114 if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
116 notify($strdatabasesuccess, "green");
119 error("Error: Main databases NOT set up successfully");
122 error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle. See the lib/db directory.");
124 print_continue("index.php");
129 /// Check version of Moodle code on disk compared with database
130 /// and upgrade if possible.
132 include_once("$CFG->dirroot/version.php"); # defines $version
133 include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines upgrades
135 $stradministration = get_string("administration");
138 if ($version > $CFG->version
) { // upgrade
140 $a->oldversion
= "$CFG->release ($CFG->version)";
141 $a->newversion
= "$release ($version)";
142 $strdatabasechecking = get_string("databasechecking", "", $a);
144 if (empty($_GET['confirmupgrade'])) {
145 print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
146 "", "", false, " ", " ");
147 notice_yesno(get_string('upgradesure', 'admin', $a->newversion
), 'index.php?confirmupgrade=yes', 'index.php');
151 $strdatabasesuccess = get_string("databasesuccess");
152 print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
153 "", "", false, " ", " ");
154 print_heading($strdatabasechecking);
156 if (main_upgrade($CFG->version
)) {
158 if (set_config("version", $version)) {
159 remove_dir($CFG->dataroot
. '/cache', true); // flush cache
160 notify($strdatabasesuccess, "green");
161 print_continue("index.php");
164 notify("Upgrade failed! (Could not update version in config table)");
168 notify("Upgrade failed! See /version.php");
171 } else if ($version < $CFG->version
) {
172 notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
176 $strcurrentversion = get_string("currentversion");
177 print_header($strcurrentversion, $stradministration, $strcurrentversion,
178 "", "", false, " ", " ");
180 if (set_config("version", $version)) {
181 print_heading("Moodle $release ($version)");
182 print_continue("index.php");
186 if (main_upgrade(0)) {
187 print_continue("index.php");
189 error("A problem occurred inserting current version into databases");
196 /// Updated human-readable release version if necessary
198 if ($release <> $CFG->release
) { // Update the release version
199 $strcurrentrelease = get_string("currentrelease");
200 print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, " ", " ");
201 print_heading("Moodle $release");
202 if (!set_config("release", $release)) {
203 notify("ERROR: Could not update release version in database!!");
205 print_continue("index.php");
206 print_simple_box_start("CENTER");
207 include("$CFG->dirroot/lang/en/docs/release.html");
208 print_simple_box_end();
209 print_continue("index.php");
215 /// Insert default values for any important configuration variables
217 include_once("$CFG->dirroot/lib/defaults.php");
219 foreach ($defaults as $name => $value) {
220 if (!isset($CFG->$name)) {
221 $CFG->$name = $value;
222 set_config($name, $value);
223 $configchange = true;
227 /// If any new configurations were found then send to the config page to check
229 if (!empty($configchange)) {
230 redirect("config.php");
235 /// Find and check all main modules and load them up or upgrade them if necessary
236 upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
238 /// Upgrade backup/restore system if necessary
239 require_once("$CFG->dirroot/backup/lib.php");
240 upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
242 /// Upgrade blocks system if necessary
243 require_once("$CFG->dirroot/lib/blocklib.php");
244 upgrade_blocks_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
246 /// Check all blocks and load (or upgrade them if necessary)
247 upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
249 /// Check all enrolment plugins and upgrade if necessary
250 upgrade_enrol_plugins("$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));
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
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($_GET['id'])) {
297 if ($_GET['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 if (!empty($CFG->upgrade
)) { // Print notice about extra upgrading that needs to be done
310 print_simple_box(get_string("upgrade$CFG->upgrade", "admin",
311 "$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"), "center");
315 /// If no recently cron run
316 $lastcron = get_field_sql('SELECT max(lastcron) FROM ' . $CFG->prefix
. 'modules');
317 if (time() - $lastcron > 3600 * 24) {
318 print_simple_box(get_string('cronwarning', 'admin') , 'center');
321 /// Alert if we are currently in maintenance mode
322 if (file_exists($CFG->dataroot
.'/1/maintenance.html')) {
323 print_simple_box(get_string('sitemaintenancewarning', 'admin') , 'center');
326 /// Print slightly annoying registration button every six months ;-)
327 /// You can set the "registered" variable to something far in the future
328 /// if you really want to prevent this. eg 9999999999
329 if (!isset($CFG->registered
) ||
$CFG->registered
< (time() - 3600*24*30*6)) {
331 $options['sesskey'] = $USER->sesskey
;
332 print_simple_box_start('center');
333 echo '<div align="center">';
334 print_string('pleaseregister', 'admin');
335 print_single_button('register.php', $options, get_string('registration'));
337 print_simple_box_end();
340 $table->tablealign
= "right";
341 $table->align
= array ("right", "left");
342 $table->wrap
= array ("nowrap", "nowrap");
343 $table->cellpadding
= 5;
344 $table->cellspacing
= 0;
345 $table->width
= "40%";
347 $configdata = "<font size=\"+1\"> </font><a href=\"config.php\">".get_string("configvariables", 'admin')."</a> - <font size=\"1\">".
348 get_string("adminhelpconfigvariables")."</font><br />";
349 $configdata .= "<font size=\"+1\"> </font><a href=\"site.php\">".get_string("sitesettings")."</a> - <font size=\"1\">".
350 get_string("adminhelpsitesettings")."</font><br />";
351 $configdata .= "<font size=\"+1\"> </font><a href=\"../theme/index.php\">".get_string("themes")."</a> - <font size=\"1\">".
352 get_string("adminhelpthemes")."</font><br />";
353 $configdata .= "<font size=\"+1\"> </font><a href=\"lang.php\">".get_string("language")."</a> - <font size=\"1\">".
354 get_string("adminhelplanguage")."</font><br />";
355 $configdata .= "<font size=\"+1\"> </font><a href=\"modules.php\">".get_string("managemodules")."</a> - <font size=\"1\">".
356 get_string("adminhelpmanagemodules")."</font><br />";
357 $configdata .= "<font size=\"+1\"> </font><a href=\"blocks.php\">".get_string("manageblocks")."</a> - <font size=\"1\">".
358 get_string("adminhelpmanageblocks")."</font><br />";
359 $configdata .= "<font size=\"+1\"> </font><a href=\"filters.php\">".get_string("managefilters")."</a> - <font size=\"1\">".
360 get_string("adminhelpmanagefilters")."</font><br />";
361 if (!isset($CFG->disablescheduledbackups
)) {
362 $configdata .= "<font size=\"+1\"> </font><a href=\"backup.php\">".get_string("backup")."</a> - <font size=\"1\">".
363 get_string("adminhelpbackup")."</font><br />";
365 $configdata .= "<font size=\"+1\"> </font><a href=\"editor.php\">". get_string("editorsettings") ."</a> - <font size=\"1\">".
366 get_string("adminhelpeditorsettings")."</font><br />";
367 $configdata .= "<font size=\"+1\"> </font><a href=\"calendar.php\">". get_string('calendarsettings', 'admin') ."</a> - <font size=\"1\">".
368 get_string('helpcalendarsettings', 'admin')."</font><br />";
369 $configdata .= "<font size=\"+1\"> </font><a href=\"maintenance.php\">". get_string('sitemaintenancemode', 'admin') ."</a> - <font size=\"1\">".
370 get_string('helpsitemaintenance', 'admin')."</font><br />";
372 $table->data
[] = array("<font size=\"+1\"><b><a href=\"configure.php\">".get_string("configuration")."</a></b></font>",
376 $userdata = "<font size=\"+1\"> </font><a href=\"auth.php?sesskey=$USER->sesskey\">".get_string("authentication")."</a> - <font size=\"1\">".
377 get_string("adminhelpauthentication")."</font><br />";
378 $userdata .= "<font size=\"+1\"> </font><a href=\"user.php\">".get_string("edituser")."</a> - <font size=\"1\">".
379 get_string("adminhelpedituser")."</font><br />";
380 $userdata .= "<font size=\"+1\"> </font><a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true&sesskey=$USER->sesskey\">".
381 get_string("addnewuser")."</a> - <font size=\"1\">".
382 get_string("adminhelpaddnewuser")."</font><br />";
383 $userdata .= "<font size=\"+1\"> </font><a href=\"$CFG->wwwroot/$CFG->admin/uploaduser.php?sesskey=$USER->sesskey\">".
384 get_string("uploadusers")."</a> - <font size=\"1\">".
385 get_string("adminhelpuploadusers")."</font><br />";
387 $userdata .= "<hr /><font size=\"+1\"> </font><a href=\"enrol.php?sesskey=$USER->sesskey\">".get_string("enrolments")."</a> - <font size=\"1\">".
388 get_string("adminhelpenrolments")."</font><br />";
389 $userdata .= "<font size=\"+1\"> </font><a href=\"../course/index.php?edit=off&sesskey=$USER->sesskey\">".get_string("assignstudents")."</a> - <font size=\"1\">".
390 get_string("adminhelpassignstudents")."</font><br />";
392 $userdata .= "<font size=\"+1\"> </font><a href=\"../course/index.php?edit=on&sesskey=$USER->sesskey\">".get_string("assignteachers")."</a> - <font size=\"1\">".
393 get_string("adminhelpassignteachers").
394 " <img src=\"../pix/t/user.gif\" height=\"11\" width=\"11\" alt=\"\" /></font><br />";
395 $userdata .= "<font size=\"+1\"> </font><a href=\"creators.php?sesskey=$USER->sesskey\">".get_string("assigncreators")."</a> - <font size=\"1\">".
396 get_string("adminhelpassigncreators")."</font><br />";
397 $userdata .= "<font size=\"+1\"> </font><a href=\"admin.php?sesskey=$USER->sesskey\">".get_string("assignadmins")."</a> - <font size=\"1\">".
398 get_string("adminhelpassignadmins")."</font><br />";
400 $table->data
[] = array("<font size=\"+1\"><b><a href=\"users.php\">".get_string("users")."</a></b></font>", $userdata);
402 $table->data
[] = array("<font size=\"+1\"><b><a href=\"../course/index.php?edit=on&sesskey=$USER->sesskey\">".get_string("courses")."</a></b></font>",
403 "<font size=\"+1\"> </font>".get_string("adminhelpcourses"));
404 $table->data
[] = array("<font size=\"+1\"><b><a href=\"../course/log.php?id=$site->id\">".get_string("logs")."</a></b></font>",
405 "<font size=\"+1\"> </font>".get_string("adminhelplogs"));
406 $table->data
[] = array("<font size=\"+1\"><b><a href=\"../files/index.php?id=$site->id\">".get_string("sitefiles")."</a></b></font>",
407 "<font size=\"+1\"> </font>".get_string("adminhelpsitefiles"));
408 if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
409 $table->data
[] = array("<font size=\"+1\"><b><a href=\"$CFG->dbtype/frame.php\">".get_string("managedatabase")."</a></b></font>",
410 "<font size=\"+1\"> </font>".get_string("adminhelpmanagedatabase"));
415 //////////////////////////////////////////////////////////////////////////////////////////////////
416 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO REMOVE OR MODIFY THE COPYRIGHT NOTICE BELOW ////
417 $copyrighttext = "<a href=\"http://moodle.org/\">Moodle</a> ".
418 "<a href=\"../doc/?frame=release.html\">$CFG->release</a> ($CFG->version)<br />".
419 "Copyright © 1999-2005 Martin Dougiamas<br />".
420 "<a href=\"../doc/?frame=licence.html\">GNU Public License</a>";
421 echo "<center><p><font size=\"1\">$copyrighttext</font></p></center>";
422 //////////////////////////////////////////////////////////////////////////////////////////////////
425 echo '<table width="100%" cellspacing="0"><tr>';
426 echo '<td align="center" width="33%">';
427 print_single_button($CFG->wwwroot
.'/doc/', NULL, get_string('documentation'));
430 echo '<td align="center" width="33%">';
431 print_single_button('phpinfo.php', NULL, get_string('phpinfo'));
434 echo '<td align="center" width="33%">';
436 $options['sesskey'] = $USER->sesskey
;
437 print_single_button('register.php', $options, get_string('registration'));
438 echo '</td></tr></table>';
440 print_simple_box_end();