3 require("../config.php");
6 /// Check that PHP is of a sufficient version
8 if ( ! check_php_version("4.1.0") ) {
9 $version = phpversion();
10 print_heading("Sorry, Moodle requires PHP 4.1.0 or later (currently using version $version)");
14 /// Check that config.php has been edited
16 if ($CFG->wwwroot == "http://example.com/moodle") {
17 error("Moodle has not been configured yet. You need to to edit config.php first.");
20 /// Check databases and modules and install as needed.
21 if (! $db->Metatables() ) {
24 $strlicense = get_string("license");
25 print_header($strlicense, $strlicense, $strlicense);
26 print_heading("<A HREF=\"http://moodle.com\">Moodle</A> - Modular Object-Oriented Dynamic Learning Environment");
27 print_heading(get_string("copyrightnotice"));
28 print_simple_box_start("CENTER");
29 echo text_to_html(get_string("gpl"));
30 print_simple_box_end();
32 notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
33 "http://www.gnu.org/copyleft/gpl.html");
37 $strdatabasesetup = get_string("databasesetup");
38 $strdatabasesuccess = get_string("databasesuccess");
39 print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup);
40 if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
42 if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
44 notify($strdatabasesuccess);
47 error("Error: Main databases NOT set up successfully");
50 error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle. See the lib/db directory.");
52 print_continue("index.php");
56 /// Check version of Moodle code on disk compared with database
57 /// and upgrade if possible.
59 include_once("$CFG->dirroot/version.php"); # defines $version
60 include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines upgrades
63 if ($version > $CFG->version) { // upgrade
64 $a->oldversion = $CFG->version;
65 $a->newversion = $version;
66 $strdatabasechecking = get_string("databasechecking", "", $a);
67 $strdatabasesuccess = get_string("databasesuccess");
68 print_header($strdatabasechecking, $strdatabasechecking, $strdatabasechecking);
69 notify($strdatabasechecking);
71 if (main_upgrade($CFG->version)) {
73 if (set_config("version", $version)) {
74 notify($strdatabasesuccess);
75 print_continue("index.php");
78 notify("Upgrade failed! (Could not update version in config table)");
82 notify("Upgrade failed! See /version.php");
84 } else if ($version < $CFG->version) {
85 notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
89 $strdatabaseupgrades = get_string("databaseupgrades");
90 print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
92 if (set_config("version", $version)) {
93 notify("You are currently using Moodle version $version (Release $release)");
94 print_continue("index.php");
98 if (main_upgrade(0)) {
99 print_continue("index.php");
101 error("A problem occurred inserting current version into databases");
107 /// Updated human-readable release version if necessary
109 if ($release <> $CFG->release) { // Update the release version
110 $strdatabaseupgrades = get_string("databaseupgrades");
111 print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
112 print_heading($release);
113 if (!set_config("release", $release)) {
114 notify("ERROR: Could not update release version in database!!");
116 print_continue("index.php");
117 print_simple_box_start("CENTER");
118 include("$CFG->dirroot/RELEASE.html");
119 print_simple_box_end();
120 print_continue("index.php");
125 /// Find and check all modules and load them up or upgrade them if necessary
127 if (!$mods = get_list_of_plugins("mod") ) {
128 error("No modules installed!");
131 foreach ($mods as $mod) {
132 $fullmod = "$CFG->dirroot/mod/$mod";
136 include_once("$fullmod/version.php"); # defines $module with version etc
137 include_once("$fullmod/db/$CFG->dbtype.php"); # defines upgrading function
139 if (!isset($module)) {
143 $module->name = $mod; // The name MUST match the directory
145 if ($currmodule = get_record("modules", "name", $module->name)) {
146 if ($currmodule->version == $module->version) {
148 } else if ($currmodule->version < $module->version) {
149 notify("$module->name module needs upgrading");
150 $upgrade_function = $module->name."_upgrade";
151 if (function_exists($upgrade_function)) {
153 if ($upgrade_function($currmodule->version, $module)) {
155 // OK so far, now update the modules record
156 $module->id = $currmodule->id;
157 if (! update_record("modules", $module)) {
158 error("Could not update $module->name record in modules table!");
160 notify(get_string("modulesuccess", "", $module->name));
163 notify("Upgrading $module->name from $currmodule->version to $module->version FAILED!");
166 $updated_modules = true;
168 error("Version mismatch: $module->name can't downgrade $currmodule->version -> $module->version !");
171 } else { // module not installed yet, so install it
172 if (!$updated_modules) {
173 $strmodulesetup = get_string("modulesetup");
174 print_header($strmodulesetup, $strmodulesetup, $strmodulesetup);
176 $updated_modules = true;
178 if (modify_database("$fullmod/db/$CFG->dbtype.sql")) {
180 if ($module->id = insert_record("modules", $module)) {
181 notify(get_string("modulesuccess", "", $module->name));
183 error("$module->name module could not be added to the module list!");
186 error("$module->name tables could NOT be set up successfully!");
191 if ($updated_modules) {
192 print_continue("index.php");
197 /// Insert default values for any important configuration variables
199 include_once("$CFG->dirroot/lib/defaults.php");
202 foreach ($defaults as $name => $value) {
203 if (!isset($CFG[$name])) {
204 $config->name = $name;
205 $config->value = $CFG[$name] = $value;
206 insert_record("config", $config);
207 $configchange = true;
212 /// If any new configurations were found then send to the config page to check
215 redirect("config.php");
218 /// Set up the overall site name etc.
219 if (! $site = get_site()) {
220 redirect("site.php");
223 /// Set up the admin user
224 if (! record_exists_sql("SELECT * FROM user_admins")) { // No admin user yet
225 redirect("user.php");
228 /// Check for valid admin user
230 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
234 /// At this point everything is set up and the user is an admin, so print menu
236 $stradministration = get_string("administration");
237 print_header("$site->shortname: $stradministration","$site->fullname: $stradministration", "$stradministration");
239 $table->head = array (get_string("site"), get_string("courses"), get_string("users"));
240 $table->align = array ("CENTER", "CENTER", "CENTER");
241 $table->data[0][0] = "<P><A HREF=\"config.php\">".get_string("configvariables")."</A></P>".
242 "<P><A HREF=\"site.php\">".get_string("sitesettings")."</A></P>".
243 "<P><A HREF=\"../course/log.php?id=$site->id\">".get_string("sitelogs")."</A></P>".
244 "<P><A HREF=\"../theme/index.php\">".get_string("choosetheme")."</A></P>".
245 "<P><A HREF=\"lang.php\">".get_string("checklanguage")."</A></P>";
246 if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) {
247 $table->data[0][0] .= "<P><A HREF=\"$CFG->dbtype/\">".get_string("managedatabase")."</A></P>";
249 $table->data[0][1] = "<P><A HREF=\"../course/edit.php\">".get_string("addnewcourse")."</A></P>".
250 "<P><A HREF=\"../course/teacher.php\">".get_string("assignteachers")."</A></P>".
251 "<P><A HREF=\"../course/delete.php\">".get_string("deletecourse")."</A></P>".
252 "<P><A HREF=\"../course/categories.php\">".get_string("categories")."</A></P>";
253 $table->data[0][2] = "<P><A HREF=\"user.php?newuser=true\">".get_string("addnewuser")."</A></P>".
254 "<P><A HREF=\"user.php\">".get_string("edituser")."</A></P>";
258 print_heading("Moodle $CFG->release ($CFG->version)", "CENTER", 1);