moodle/admin/index.php

407 lines
16 KiB
PHP
Raw Normal View History

2001-11-22 06:23:56 +00:00
<?PHP // $Id$
/// Check that config.php exists
if (!file_exists("../config.php")) {
echo "<H2 align=center>You need to create a config.php.<BR>
See the <A HREF=\"http://moodle.com/doc/?frame=install.html\">installation instructions</A>.</H2>";
die;
}
require_once("../config.php");
2001-11-22 06:23:56 +00:00
/// Check that PHP is of a sufficient version
if (!check_php_version("4.1.0")) {
$version = phpversion();
print_heading("Sorry, Moodle requires PHP 4.1.0 or later (currently using version $version)");
die;
}
/// Check some PHP server settings
$documentationlink = "please read the <A HREF=\"../doc/?frame=install.html&sub=webserver\">install documentation</A>";
if (ini_get_bool('session.auto_start')) {
error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
}
if (ini_get_bool('magic_quotes_runtime')) {
error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink");
}
if (!ini_get_bool('magic_quotes_gpc')) {
error("The PHP server variable 'magic_quotes_gpc' is not turned On - $documentationlink");
}
if (!ini_get_bool('file_uploads')) {
error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
}
if (!ini_get_bool('short_open_tag')) {
error("The PHP server variable 'short_open_tag' is not turned On - $documentationlink");
}
/// Check that sessions are supported
if (!is_readable(ini_get('session.save_path')) and !ini_get_bool('safe_mode')) {
$sessionpath = ini_get('session.save_path');
notify("Warning: It appears your server does not support sessions (session.save_path = '$sessionpath')");
}
/// Check that config.php has been edited
if ($CFG->wwwroot == "http://example.com/moodle") {
2001-11-22 06:23:56 +00:00
error("Moodle has not been configured yet. You need to to edit config.php first.");
}
/// Check settings in config.php
$dirroot = dirname(realpath("../config.php"));
if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
error("Please fix your settings in config.php:
<P>You have:
<P>\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
<P>but it should be:
<P>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
"./");
}
/// Set some necessary variables during set-up to avoid PHP warnings later on this page
if (!isset($CFG->framename)) {
$CFG->framename = "_top";
}
if (!isset($CFG->release)) {
$CFG->release = "";
}
if (!isset($CFG->version)) {
$CFG->version = "";
}
/// Check if the main tables have been installed yet or not.
if (! $tables = $db->Metatables() ) { // No tables yet at all.
$maintables = false;
} else { // Check for missing main tables
$maintables = true;
$mtables = array("config", "course", "course_categories", "course_modules",
"course_sections", "log", "log_display", "modules",
"user", "user_admins", "user_students", "user_teachers");
foreach ($mtables as $mtable) {
if (!in_array($CFG->prefix.$mtable, $tables)) {
$maintables = false;
break;
}
}
}
if (! $maintables) {
if (empty($agreelicence)) {
$strlicense = get_string("license");
print_header($strlicense, $strlicense, $strlicense, "", "", false, "&nbsp;", "&nbsp;");
print_heading("<A HREF=\"http://moodle.org\">Moodle</A> - Modular Object-Oriented Dynamic Learning Environment");
print_heading(get_string("copyrightnotice"));
print_simple_box_start("center");
echo text_to_html(get_string("gpl"));
print_simple_box_end();
echo "<br />";
notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
"http://moodle.org/doc/?frame=licence.html");
exit;
}
$strdatabasesetup = get_string("databasesetup");
$strdatabasesuccess = get_string("databasesuccess");
print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup, "", "", false, "&nbsp;", "&nbsp;");
if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
$db->debug = true;
set_time_limit(0); // To allow slow databases to complete the long SQL
if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
$db->debug = false;
notify($strdatabasesuccess, "green");
} else {
$db->debug = false;
error("Error: Main databases NOT set up successfully");
}
2001-11-22 06:23:56 +00:00
} else {
error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle. See the lib/db directory.");
2001-11-22 06:23:56 +00:00
}
print_continue("index.php");
2001-11-22 06:23:56 +00:00
die;
}
/// Check version of Moodle code on disk compared with database
/// and upgrade if possible.
include_once("$CFG->dirroot/version.php"); # defines $version
include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines upgrades
if ($CFG->version) {
if ($version > $CFG->version) { // upgrade
$a->oldversion = $CFG->version;
$a->newversion = $version;
$strdatabasechecking = get_string("databasechecking", "", $a);
$strdatabasesuccess = get_string("databasesuccess");
print_header($strdatabasechecking, $strdatabasechecking, $strdatabasechecking,
"", "", false, "&nbsp;", "&nbsp;");
print_heading($strdatabasechecking);
$db->debug=true;
if (main_upgrade($CFG->version)) {
$db->debug=false;
if (set_config("version", $version)) {
notify($strdatabasesuccess, "green");
print_continue("index.php");
die;
} else {
notify("Upgrade failed! (Could not update version in config table)");
}
} else {
$db->debug=false;
notify("Upgrade failed! See /version.php");
}
} else if ($version < $CFG->version) {
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
}
} else {
$strcurrentversion = get_string("currentversion");
print_header($strcurrentversion, $strcurrentversion, $strcurrentversion,
"", "", false, "&nbsp;", "&nbsp;");
if (set_config("version", $version)) {
print_heading("You are currently using Moodle version $version (Release $release)");
print_continue("index.php");
die;
} else {
$db->debug=true;
if (main_upgrade(0)) {
print_continue("index.php");
} else {
error("A problem occurred inserting current version into databases");
}
$db->debug=false;
}
}
/// Updated human-readable release version if necessary
if ($release <> $CFG->release) { // Update the release version
$strcurrentrelease = get_string("currentrelease");
print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, "&nbsp;", "&nbsp;");
2003-05-29 03:24:50 +00:00
print_heading("Moodle $release");
if (!set_config("release", $release)) {
notify("ERROR: Could not update release version in database!!");
}
print_continue("index.php");
print_simple_box_start("CENTER");
include("$CFG->dirroot/lang/en/docs/release.html");
print_simple_box_end();
print_continue("index.php");
exit;
}
/// Upgrade backup/restore system if necessary
require_once("$CFG->dirroot/backup/lib.php");
upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
/// Find and check all modules and load them up or upgrade them if necessary
2001-11-22 06:23:56 +00:00
if (!$mods = get_list_of_plugins("mod") ) {
error("No modules installed!");
}
foreach ($mods as $mod) {
if ($mod == "NEWMODULE") { // Someone has unzipped the template, ignore it
continue;
}
2001-11-22 06:23:56 +00:00
$fullmod = "$CFG->dirroot/mod/$mod";
unset($module);
if ( is_readable("$fullmod/version.php")) {
include_once("$fullmod/version.php"); # defines $module with version etc
} else {
notify("Module $mod: $fullmod/version.php was not readable");
continue;
}
if ( is_readable("$fullmod/db/$CFG->dbtype.php")) {
include_once("$fullmod/db/$CFG->dbtype.php"); # defines upgrading function
} else {
notify("Module $mod: $fullmod/db/$CFG->dbtype.php was not readable");
continue;
}
2001-11-22 06:23:56 +00:00
if (!isset($module)) {
continue;
}
$module->name = $mod; // The name MUST match the directory
if ($currmodule = get_record("modules", "name", $module->name)) {
if ($currmodule->version == $module->version) {
// do nothing
} else if ($currmodule->version < $module->version) {
print_heading("$module->name module needs upgrading");
$upgrade_function = $module->name."_upgrade";
if (function_exists($upgrade_function)) {
$db->debug=true;
if ($upgrade_function($currmodule->version, $module)) {
$db->debug=false;
// OK so far, now update the modules record
$module->id = $currmodule->id;
if (! update_record("modules", $module)) {
error("Could not update $module->name record in modules table!");
}
notify(get_string("modulesuccess", "", $module->name), "green");
echo "<HR>";
} else {
$db->debug=false;
notify("Upgrading $module->name from $currmodule->version to $module->version FAILED!");
}
}
$updated_modules = true;
2001-11-22 06:23:56 +00:00
} else {
error("Version mismatch: $module->name can't downgrade $currmodule->version -> $module->version !");
}
} else { // module not installed yet, so install it
if (empty($updated_modules)) {
$strmodulesetup = get_string("modulesetup");
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, "", "", false, "&nbsp;", "&nbsp;");
}
print_heading($module->name);
$updated_modules = true;
$db->debug = true;
set_time_limit(0); // To allow slow databases to complete the long SQL
if (modify_database("$fullmod/db/$CFG->dbtype.sql")) {
$db->debug = false;
2001-11-22 06:23:56 +00:00
if ($module->id = insert_record("modules", $module)) {
notify(get_string("modulesuccess", "", $module->name), "green");
echo "<HR>";
2001-11-22 06:23:56 +00:00
} else {
error("$module->name module could not be added to the module list!");
}
} else {
2001-11-22 06:23:56 +00:00
error("$module->name tables could NOT be set up successfully!");
}
}
}
if (!empty($updated_modules)) {
print_continue("index.php");
die;
}
/// Insert default values for any important configuration variables
include_once("$CFG->dirroot/lib/defaults.php");
foreach ($defaults as $name => $value) {
if (!isset($CFG->$name)) {
$CFG->$name = $value;
set_config($name, $value);
$configchange = true;
}
}
/// If any new configurations were found then send to the config page to check
if (!empty($configchange)) {
redirect("config.php");
}
/// Set up the overall site name etc.
if (! $site = get_site()) {
redirect("site.php");
2001-11-22 06:23:56 +00:00
}
/// Set up the admin user
if (! record_exists("user_admins")) { // No admin user yet
redirect("user.php");
}
/// Check for valid admin user
if (!isadmin()) {
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
2001-11-22 06:23:56 +00:00
}
/// At this point everything is set up and the user is an admin, so print menu
2001-11-22 06:23:56 +00:00
$stradministration = get_string("administration");
print_header("$site->shortname: $stradministration","$site->fullname", "$stradministration");
print_simple_box_start("center", "80%", "#FFFFFF", 20);
print_heading($stradministration);
$table->align = array ("right", "left");
$table->data[] = array("<a href=\"../course/index.php?edit=on\">".get_string("courses")."</a>",
"<font size=-1>".get_string("adminhelpcourses"));
$table->data[] = array("<a href=\"users.php\">".get_string("users")."</a>",
"<font size=-1>".get_string("adminhelpusers"));
$table->data[] = array("<a href=\"config.php\">".get_string("configvariables")."</a>",
"<font size=-1>".get_string("adminhelpconfiguration"));
$table->data[] = array("<a href=\"site.php\">".get_string("sitesettings")."</a>",
"<font size=-1>".get_string("adminhelpsitesettings"));
$table->data[] = array("<a href=\"../files/index.php?id=$site->id\">".get_string("sitefiles")."</a>",
"<font size=-1>".get_string("adminhelpsitefiles"));
$table->data[] = array("<a href=\"../theme/index.php\">".get_string("themes")."</a>",
"<font size=-1>".get_string("adminhelpthemes"));
$table->data[] = array("<a href=\"lang.php\">".get_string("language")."</a>",
"<font size=-1>".get_string("adminhelplanguage"));
$table->data[] = array("<a href=\"modules.php\">".get_string("managemodules")."</a>",
"<font size=-1>".get_string("adminhelpmanagemodules"));
$table->data[] = array("<a href=\"../course/log.php?id=$site->id.php\">".get_string("logs")."</a>",
"<font size=-1>".get_string("adminhelplogs"));
if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) {
$table->data[] = array("<a href=\"$CFG->dbtype/frame.php\">".get_string("managedatabase")."</a>",
"<font size=-1>".get_string("adminhelpmanagedatabase"));
}
$table->width = "90%";
print_table($table);
$copyrighttext = "<a href=\"http://moodle.org/\">Moodle</a> ".
"<a href=\"../doc/?frame=release.html\">$CFG->release</a> ($CFG->version)<br />".
"Open Source under the terms of the ".
"<a href=\"../doc/?frame=licence.html\">GNU Public License</a><br />".
"Copyright &copy; 2000-2003 Martin Dougiamas";
echo "<center><p><font size=1>$copyrighttext</font></p></center>";
echo "<table border=0 align=center width=100%><tr>";
echo "<td align=center width=50%>";
2003-01-06 08:23:13 +00:00
print_single_button("$CFG->wwwroot/doc", NULL, get_string("documentation"));
echo "</td>";
2003-01-06 08:23:13 +00:00
echo "<td align=center width=50%>";
print_single_button("register.php", NULL, get_string("registration"));
echo "</td>";
echo "<tr></table>";
print_simple_box_end();
2002-09-27 06:19:18 +00:00
print_footer($site);
2001-11-22 06:23:56 +00:00
?>