2004-10-03 15:28:35 +00:00
< ? php // $Id$
2001-11-22 06:23:56 +00:00
2004-08-16 15:41:57 +00:00
/// Check that config.php exists, if not then call the install script
2006-03-06 13:22:37 +00:00
if ( ! file_exists ( '../config.php' )) {
2004-08-16 15:41:57 +00:00
header ( 'Location: ../install.php' );
2003-01-13 14:05:29 +00:00
die ;
}
2006-07-20 06:39:48 +00:00
/// Check that PHP is of a sufficient version
/// Moved here because older versions do not allow while(@ob_end_clean());
if ( version_compare ( phpversion (), " 4.3.0 " ) < 0 ) {
$phpversion = phpversion ();
echo " Sorry, Moodle requires PHP 4.3.0 or later (currently using version $phpversion ) " ;
die ;
}
/// Turn off time limits and try to flush everything all the time, sometimes upgrades can be slow.
@ set_time_limit ( 0 );
@ ob_implicit_flush ( true );
while ( @ ob_end_clean ()); // ob_end_flush prevents sending of headers
2006-03-06 13:22:37 +00:00
require_once ( '../config.php' );
2006-09-02 13:14:57 +00:00
require_once ( $CFG -> libdir . '/adminlib.php' ); // Contains various admin-only functions
require_once ( $CFG -> libdir . '/ddllib.php' ); // Install/upgrade related db functions
2006-08-17 16:59:39 +00:00
2006-03-06 13:22:37 +00:00
$id = optional_param ( 'id' , '' , PARAM_ALPHANUM );
$confirmupgrade = optional_param ( 'confirmupgrade' , 0 , PARAM_BOOL );
2006-04-10 06:35:10 +00:00
$agreelicence = optional_param ( 'agreelicence' , 0 , PARAM_BOOL );
2006-08-28 18:07:15 +00:00
$ignoreupgradewarning = optional_param ( 'ignoreupgradewarning' , 0 , PARAM_BOOL );
2002-09-19 12:01:55 +00:00
2006-08-20 11:20:40 +00:00
/// Interim solution to keep the XMLDB installation disabled
/// can be enabled by hand in the config.php, of course
if ( ! isset ( $CFG -> xmldb_enabled )) {
$CFG -> xmldb_enabled = false ;
}
2006-08-01 07:46:19 +00:00
/// check upgrade status first
2006-08-28 18:07:15 +00:00
if ( $ignoreupgradewarning and ! empty ( $_SESSION [ 'upgraderunning' ])) {
$_SESSION [ 'upgraderunning' ] = 0 ;
}
upgrade_check_running ( " Upgrade already running in this session, please wait!<br />Click on the exclamation marks to ignore this warning (<a href= \" index.php?ignoreupgradewarning=1 \" >!!!</a>). " , 10 );
2006-08-01 07:46:19 +00:00
2003-01-28 02:52:13 +00:00
/// Check some PHP server settings
2004-09-16 17:13:57 +00:00
$documentationlink = " please read the <a href= \" ../doc/?frame=install.html&sub=webserver \" >install documentation</a> " ;
2003-01-28 02:52:13 +00:00
2003-05-17 02:05:10 +00:00
if ( ini_get_bool ( 'session.auto_start' )) {
error ( " The PHP server variable 'session.auto_start' should be Off - $documentationlink " );
2003-01-28 02:52:13 +00:00
}
2003-05-17 02:05:10 +00:00
if ( ini_get_bool ( 'magic_quotes_runtime' )) {
2003-01-28 02:52:13 +00:00
error ( " The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink " );
}
2003-05-17 02:05:10 +00:00
if ( ! ini_get_bool ( 'file_uploads' )) {
error ( " The PHP server variable 'file_uploads' is not turned On - $documentationlink " );
2003-01-28 02:52:13 +00:00
}
2003-05-17 02:05:10 +00:00
2002-09-19 12:01:55 +00:00
/// Check that config.php has been edited
2002-05-27 13:02:48 +00:00
if ( $CFG -> wwwroot == " http://example.com/moodle " ) {
2005-02-13 21:29:20 +00:00
error ( " Moodle has not been configured yet. You need to edit config.php first. " );
2001-11-22 06:23:56 +00:00
}
2003-01-13 14:05:29 +00:00
/// Check settings in config.php
2003-12-05 03:10:45 +00:00
$dirroot = dirname ( realpath ( " ../index.php " ));
2003-06-03 03:00:37 +00:00
if ( ! empty ( $dirroot ) and $dirroot != $CFG -> dirroot ) {
2003-01-13 14:05:29 +00:00
error ( " Please fix your settings in config.php:
2004-09-12 00:21:21 +00:00
< p > You have :
< p > \ $CFG -> dirroot = \ " " . addslashes ( $CFG -> dirroot ) . " \" ;
< p > but it should be :
< p > \ $CFG -> dirroot = \ " " . addslashes ( $dirroot ) . " \" ; " ,
2003-01-18 14:24:40 +00:00
" ./ " );
2003-01-13 14:05:29 +00:00
}
2003-05-26 14:38:41 +00:00
/// 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 = " " ;
}
2002-12-24 05:39:45 +00:00
/// 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 ;
2005-02-13 21:29:20 +00:00
$mtables = array ( " config " , " course " , " course_categories " , " course_modules " ,
" course_sections " , " log " , " log_display " , " modules " ,
2002-12-24 05:39:45 +00:00
" user " , " user_admins " , " user_students " , " user_teachers " );
foreach ( $mtables as $mtable ) {
2005-02-13 21:29:20 +00:00
if ( ! in_array ( $CFG -> prefix . $mtable , $tables )) {
2002-12-24 05:39:45 +00:00
$maintables = false ;
break ;
}
}
}
2002-08-17 08:38:43 +00:00
2006-07-13 09:48:56 +00:00
$linktoscrolltoerrors = '<script type="text/javascript" src="' . $CFG -> wwwroot . '/lib/scroll_to_errors.js"></script>' ;
2002-12-24 05:39:45 +00:00
if ( ! $maintables ) {
2006-09-10 21:10:48 +00:00
/// hide errors from headers in case debug enabled in config.php
$origdebug = $CFG -> debug ;
$CFG -> debug = 5 ;
error_reporting ( $CFG -> debug );
2003-05-26 14:38:41 +00:00
if ( empty ( $agreelicence )) {
2002-08-17 08:38:43 +00:00
$strlicense = get_string ( " license " );
2003-05-19 13:12:27 +00:00
print_header ( $strlicense , $strlicense , $strlicense , " " , " " , false , " " , " " );
2004-09-12 00:21:21 +00:00
print_heading ( " <a href= \" http://moodle.org \" >Moodle</a> - Modular Object-Oriented Dynamic Learning Environment " );
2002-08-17 08:38:43 +00:00
print_heading ( get_string ( " copyrightnotice " ));
2006-04-14 06:38:52 +00:00
print_simple_box_start ( 'center' );
2002-08-17 08:38:43 +00:00
echo text_to_html ( get_string ( " gpl " ));
print_simple_box_end ();
2003-05-26 14:38:41 +00:00
echo " <br /> " ;
2005-02-13 21:29:20 +00:00
notice_yesno ( get_string ( " doyouagree " ), " index.php?agreelicence=true " ,
2006-04-16 16:09:12 +00:00
" http://docs.moodle.org/en/License " );
2002-08-17 08:38:43 +00:00
exit ;
}
2002-08-15 05:44:37 +00:00
$strdatabasesetup = get_string ( " databasesetup " );
$strdatabasesuccess = get_string ( " databasesuccess " );
2006-07-13 09:48:56 +00:00
print_header ( $strdatabasesetup , $strdatabasesetup , $strdatabasesetup ,
" " , $linktoscrolltoerrors , false , " " , " " );
2006-09-10 21:10:48 +00:00
/// return to original debugging level
$CFG -> debug = $origdebug ;
error_reporting ( $CFG -> debug );
2006-08-30 23:13:43 +00:00
upgrade_log_start ();
$db -> debug = true ;
/// Both old .sql files and new install.xml are supported
/// But we priorize install.xml (XMLDB) if present
$status = false ;
if ( file_exists ( " $CFG->libdir /db/install.xml " ) && $CFG -> xmldb_enabled ) {
$status = install_from_xmldb_file ( " $CFG->libdir /db/install.xml " ); //New method
} else if ( file_exists ( " $CFG->libdir /db/ $CFG->dbtype .sql " )) {
$status = modify_database ( " $CFG->libdir /db/ $CFG->dbtype .sql " ); //Old method
} else {
error ( " Error: Your database ( $CFG->dbtype ) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory. " );
}
2006-08-28 06:02:00 +00:00
2006-08-30 23:13:43 +00:00
/// Continue with the instalation
$db -> debug = false ;
if ( $status ) {
// Install the roles system.
moodle_install_roles ();
if ( ! update_capabilities ()) {
error ( 'Had trouble installing the core capabilities for the Roles System' );
2002-05-27 13:02:48 +00:00
}
2006-08-30 23:13:43 +00:00
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
// (this should only have any effect during initial install).
2006-09-02 13:14:57 +00:00
$adminroot = admin_get_root ();
2006-09-02 19:30:54 +00:00
$adminroot -> prune ( 'backups' ); // backup settings table not created yet
2006-09-02 13:14:57 +00:00
apply_default_settings ( $adminroot );
2006-08-30 23:13:43 +00:00
/// This is used to handle any settings that must exist in $CFG but which do not exist in
2006-09-02 13:14:57 +00:00
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
2006-08-30 23:13:43 +00:00
apply_default_exception_settings ( array ( 'alternateloginurl' => '' ,
'auth' => 'email' ,
'auth_pop3mailbox' => 'INBOX' ,
'changepassword' => '' ,
2006-08-31 21:50:22 +00:00
'enrol' => 'manual' ,
'enrol_plugins_enabled' => 'manual' ,
2006-08-30 23:13:43 +00:00
'guestloginbutton' => 1 ,
'style' => 'default' ,
'template' => 'default' ,
'theme' => 'standardwhite' ));
notify ( $strdatabasesuccess , " green " );
2001-11-22 06:23:56 +00:00
} else {
2006-08-30 23:13:43 +00:00
error ( " Error: Main databases NOT set up successfully " );
2001-11-22 06:23:56 +00:00
}
2006-08-28 06:02:00 +00:00
print_continue ( 'index.php' );
2001-11-22 06:23:56 +00:00
die ;
}
2004-07-29 18:44:57 +00:00
2002-09-19 12:01:55 +00:00
/// Check version of Moodle code on disk compared with database
/// and upgrade if possible.
2002-07-27 13:09:08 +00:00
2006-08-30 23:13:43 +00:00
if ( is_readable ( " $CFG->dirroot /version.php " )) {
include_once ( " $CFG->dirroot /version.php " ); # defines $version
}
if ( ! $version ) {
error ( 'Main version.php was not readable or specified' ); # without version, stop
}
2006-08-20 11:20:40 +00:00
if ( file_exists ( " $CFG->dirroot /lib/db/ $CFG->dbtype .php " )) {
include_once ( " $CFG->dirroot /lib/db/ $CFG->dbtype .php " ); # defines old upgrades
}
if ( file_exists ( " $CFG->dirroot /lib/db/upgrade.php " ) && $CFG -> xmldb_enabled ) {
2006-08-24 22:27:11 +00:00
include_once ( " $CFG->dirroot /lib/db/upgrade.php " ); # defines new upgrades
2006-08-20 11:20:40 +00:00
}
2002-07-27 13:09:08 +00:00
2004-09-04 15:47:30 +00:00
$stradministration = get_string ( " administration " );
2005-02-13 21:29:20 +00:00
if ( $CFG -> version ) {
2002-09-19 12:01:55 +00:00
if ( $version > $CFG -> version ) { // upgrade
2004-09-04 15:47:30 +00:00
$a -> oldversion = " $CFG->release ( $CFG->version ) " ;
$a -> newversion = " $release ( $version ) " ;
2002-08-15 05:44:37 +00:00
$strdatabasechecking = get_string ( " databasechecking " , " " , $a );
2004-09-04 15:47:30 +00:00
2006-09-10 21:10:48 +00:00
// hide errors from headers in case debug is enabled
$origdebug = $CFG -> debug ;
$CFG -> debug = 5 ;
error_reporting ( $CFG -> debug );
// logout in case we are upgrading from pre 1.7 version - prevention of weird session problems
if ( $CFG -> version < 2006050600 ) {
require_logout ();
}
2005-06-15 12:31:09 +00:00
if ( empty ( $confirmupgrade )) {
2005-02-13 21:29:20 +00:00
print_header ( $strdatabasechecking , $stradministration , $strdatabasechecking ,
2004-09-04 15:47:30 +00:00
" " , " " , false , " " , " " );
2005-06-04 09:44:09 +00:00
notice_yesno ( get_string ( 'upgradesure' , 'admin' , $a -> newversion ), 'index.php?confirmupgrade=yes' , 'index.php' );
2004-09-04 15:47:30 +00:00
exit ;
2005-02-13 21:29:20 +00:00
2004-09-04 15:47:30 +00:00
} else {
$strdatabasesuccess = get_string ( " databasesuccess " );
2005-02-13 21:29:20 +00:00
print_header ( $strdatabasechecking , $stradministration , $strdatabasechecking ,
2006-07-13 09:48:56 +00:00
" " , $linktoscrolltoerrors , false , " " , " " );
2006-09-10 21:10:48 +00:00
/// return to original debugging level
$CFG -> debug = $origdebug ;
error_reporting ( $CFG -> debug );
2006-08-01 07:46:19 +00:00
upgrade_log_start ();
2004-09-04 15:47:30 +00:00
print_heading ( $strdatabasechecking );
$db -> debug = true ;
2006-09-02 23:40:13 +00:00
/// Launch the old main upgrade (if exists)
$status = true ;
if ( function_exists ( 'main_upgrade' )) {
$status = main_upgrade ( $CFG -> version );
}
2006-08-24 22:27:11 +00:00
/// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
2006-08-27 08:58:09 +00:00
if ( $status && function_exists ( 'xmldb_main_upgrade' )) {
2006-08-24 22:27:11 +00:00
$status = xmldb_main_upgrade ( $CFG -> version );
}
2006-08-30 23:13:43 +00:00
$db -> debug = false ;
2006-08-24 22:27:11 +00:00
/// If successful, continue upgrading roles and setting everything properly
if ( $status ) {
2006-08-09 13:18:33 +00:00
if ( empty ( $CFG -> rolesactive )) {
2006-08-11 02:44:42 +00:00
// Upgrade to the roles system.
moodle_install_roles ();
2006-08-09 13:18:33 +00:00
}
2006-08-08 05:13:06 +00:00
if ( ! update_capabilities ()) {
2006-08-11 02:44:42 +00:00
error ( 'Had trouble upgrading the core capabilities for the Roles System' );
} else {
set_config ( 'rolesactive' , 1 );
2006-08-08 05:13:06 +00:00
}
2004-09-04 15:47:30 +00:00
if ( set_config ( " version " , $version )) {
2005-04-20 07:29:28 +00:00
remove_dir ( $CFG -> dataroot . '/cache' , true ); // flush cache
2004-09-04 15:47:30 +00:00
notify ( $strdatabasesuccess , " green " );
2006-08-28 06:02:00 +00:00
print_continue ( " upgradesettings.php " );
2004-09-04 15:47:30 +00:00
exit ;
} else {
notify ( " Upgrade failed! (Could not update version in config table) " );
}
2006-08-24 22:27:11 +00:00
/// Main upgrade not success
2002-07-27 13:09:08 +00:00
} else {
2004-09-04 15:47:30 +00:00
notify ( " Upgrade failed! See /version.php " );
2002-07-27 13:09:08 +00:00
}
2006-08-01 07:46:19 +00:00
upgrade_log_finish ();
2002-07-27 13:09:08 +00:00
}
2002-09-19 12:01:55 +00:00
} else if ( $version < $CFG -> version ) {
2006-08-17 22:37:34 +00:00
upgrade_log_start ();
2002-07-27 13:09:08 +00:00
notify ( " WARNING!!! The code you are using is OLDER than the version that made these databases! " );
2006-08-17 22:37:34 +00:00
upgrade_log_finish ();
2002-07-27 13:09:08 +00:00
}
} else {
2006-04-16 16:50:55 +00:00
if ( ! set_config ( " version " , $version )) {
2006-08-30 23:13:43 +00:00
error ( " A problem occurred inserting current version into databases " );
2002-07-27 13:09:08 +00:00
}
}
2002-09-19 12:01:55 +00:00
/// Updated human-readable release version if necessary
2002-09-06 14:06:48 +00:00
2002-09-27 06:13:59 +00:00
if ( $release <> $CFG -> release ) { // Update the release version
2003-05-06 15:58:20 +00:00
$strcurrentrelease = get_string ( " currentrelease " );
2003-05-19 13:12:27 +00:00
print_header ( $strcurrentrelease , $strcurrentrelease , $strcurrentrelease , " " , " " , false , " " , " " );
2003-05-29 03:24:50 +00:00
print_heading ( " Moodle $release " );
2002-09-27 06:13:59 +00:00
if ( ! set_config ( " release " , $release )) {
notify ( " ERROR: Could not update release version in database!! " );
2002-09-06 14:06:48 +00:00
}
2006-04-05 02:46:05 +00:00
notice ( get_string ( 'releasenoteslink' , 'admin' , 'http://docs.moodle.org/en/Release_Notes' ), 'index.php' );
2002-09-27 06:13:59 +00:00
exit ;
2002-09-06 14:06:48 +00:00
}
2004-07-29 18:01:32 +00:00
2006-03-27 12:32:51 +00:00
/// Send $CFG->unicodedb to DB to have it available for next requests
set_config ( 'unicodedb' , $CFG -> unicodedb );
2004-09-04 15:47:30 +00:00
2006-08-08 05:13:06 +00:00
2005-02-24 09:03:24 +00:00
/// Find and check all main modules and load them up or upgrade them if necessary
2006-08-20 11:20:40 +00:00
/// first old *.php update and then the new upgrade.php script
2005-02-24 09:03:24 +00:00
upgrade_activity_modules ( " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
2006-03-23 13:05:40 +00:00
/// Check all questiontype plugins and upgrade if necessary
2006-08-20 11:20:40 +00:00
/// first old *.php update and then the new upgrade.php script
/// It is important that this is done AFTER the quiz module has been upgraded
2006-03-25 07:55:56 +00:00
upgrade_plugins ( 'qtype' , 'question/type' , " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
2006-03-23 13:05:40 +00:00
2003-08-01 13:59:17 +00:00
/// Upgrade backup/restore system if necessary
2006-08-20 11:20:40 +00:00
/// first old *.php update and then the new upgrade.php script
2003-08-01 13:59:17 +00:00
require_once ( " $CFG->dirroot /backup/lib.php " );
upgrade_backup_db ( " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
2004-04-18 23:20:53 +00:00
/// Upgrade blocks system if necessary
2006-08-20 11:20:40 +00:00
/// first old *.php update and then the new upgrade.php script
2004-04-18 23:20:53 +00:00
require_once ( " $CFG->dirroot /lib/blocklib.php " );
upgrade_blocks_db ( " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
/// Check all blocks and load (or upgrade them if necessary)
2006-08-20 11:20:40 +00:00
/// first old *.php update and then the new upgrade.php script
2004-04-18 23:20:53 +00:00
upgrade_blocks_plugins ( " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
2004-01-28 04:26:58 +00:00
2004-08-19 09:38:20 +00:00
/// Check all enrolment plugins and upgrade if necessary
2006-08-20 11:20:40 +00:00
/// first old *.php update and then the new upgrade.php script
2006-03-22 10:44:54 +00:00
upgrade_plugins ( 'enrol' , 'enrol' , " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
2005-02-13 21:29:20 +00:00
2005-08-15 22:31:22 +00:00
/// Check for local database customisations
2006-08-20 11:20:40 +00:00
/// first old *.php update and then the new upgrade.php script
2005-08-15 22:31:22 +00:00
require_once ( " $CFG->dirroot /lib/locallib.php " );
upgrade_local_db ( " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
2001-12-04 14:02:36 +00:00
2006-08-01 07:46:19 +00:00
/// just make sure upgrade logging is properly terminated
upgrade_log_finish ();
2002-09-19 12:01:55 +00:00
2006-09-02 15:29:52 +00:00
/// Set up the blank site - to be customized later at the end of install.
2002-07-11 05:30:10 +00:00
if ( ! $site = get_site ()) {
2006-09-02 15:29:52 +00:00
// We are about to create the site "course"
2006-09-02 23:55:56 +00:00
require_once ( $CFG -> libdir . '/blocklib.php' );
2006-09-02 15:29:52 +00:00
$newsite = new Object ();
$newsite -> fullname = " " ;
$newsite -> shortname = " " ;
$newsite -> summary = " " ;
$newsite -> newsitems = 3 ;
$newsite -> numsections = 0 ;
$newsite -> category = 0 ;
$newsite -> format = 'site' ; // Only for this course
$newsite -> teacher = get_string ( " defaultcourseteacher " );
$newsite -> teachers = get_string ( " defaultcourseteachers " );
$newsite -> student = get_string ( " defaultcoursestudent " );
$newsite -> students = get_string ( " defaultcoursestudents " );
$newsite -> timemodified = time ();
if ( $newid = insert_record ( 'course' , $newsite )) {
// Site created, add blocks for it
$page = page_create_object ( PAGE_COURSE_VIEW , $newid );
blocks_repopulate_page ( $page ); // Return value not checked because you can always edit later
$cat = new Object ();
$cat -> name = get_string ( 'miscellaneous' );
if ( insert_record ( 'course_categories' , $cat )) {
2006-09-11 21:20:47 +00:00
redirect ( 'index.php' );
2006-09-02 15:29:52 +00:00
} else {
error ( " Serious Error! Could not set up a default course category! " );
}
} else {
error ( " Serious Error! Could not set up the site! " );
}
2001-11-22 06:23:56 +00:00
}
2006-09-03 18:37:41 +00:00
// initialise default blocks on admin and site page if needed
2006-09-02 23:55:56 +00:00
if ( empty ( $CFG -> adminblocks_initialised )) {
require_once ( " $CFG->dirroot / $CFG->admin /pagelib.php " );
require_once ( $CFG -> libdir . '/blocklib.php' );
page_map_class ( PAGE_ADMIN , 'page_admin' );
$page = page_create_object ( PAGE_ADMIN , 0 ); // there must be some id number
blocks_repopulate_page ( $page );
2006-09-03 18:37:41 +00:00
//add admin_tree block to site if not already present
if ( $admintree = get_record ( 'block' , 'name' , 'admin_tree' )) {
$page = page_create_object ( PAGE_COURSE_VIEW , SITEID );
blocks_execute_action ( $page , blocks_get_by_page ( $page ), 'add' , ( int ) $admintree -> id , false , false );
2006-09-10 22:11:46 +00:00
if ( $admintreeinstance = get_record ( 'block_instance' , 'pagetype' , $page -> type , 'pageid' , SITEID , 'blockid' , $admintree -> id )) {
blocks_execute_action ( $page , blocks_get_by_page ( $page ), 'moveleft' , $admintreeinstance , false , false );
}
2006-09-03 18:37:41 +00:00
}
2006-09-03 18:53:07 +00:00
set_config ( 'adminblocks_initialised' , 1 );
2006-09-02 23:55:56 +00:00
}
2005-01-22 03:27:37 +00:00
/// Define the unique site ID code if it isn't already
if ( empty ( $CFG -> siteidentifier )) { // Unique site identification code
set_config ( 'siteidentifier' , random_string ( 32 ));
}
2005-05-06 06:24:04 +00:00
2005-03-03 14:56:19 +00:00
/// Check if the guest user exists. If not, create one.
if ( ! record_exists ( " user " , " username " , " guest " )) {
2005-05-06 06:24:04 +00:00
$guest -> auth = " manual " ;
$guest -> username = " guest " ;
2005-03-03 14:56:19 +00:00
$guest -> password = md5 ( " guest " );
$guest -> firstname = addslashes ( get_string ( " guestuser " ));
$guest -> lastname = " " ;
$guest -> email = " root@localhost " ;
$guest -> description = addslashes ( get_string ( " guestuserinfo " ));
$guest -> confirmed = 1 ;
$guest -> lang = $CFG -> lang ;
$guest -> timemodified = time ();
if ( ! $guest -> id = insert_record ( " user " , $guest )) {
notify ( " Could not create guest user record !!! " );
}
}
2005-01-22 03:27:37 +00:00
2006-08-11 02:44:42 +00:00
2002-09-19 12:01:55 +00:00
/// Set up the admin user
2006-09-02 15:29:52 +00:00
if ( empty ( $CFG -> rolesactive )) {
2006-09-11 21:20:47 +00:00
redirect ( 'user.php' );
2002-10-25 02:02:02 +00:00
}
/// Check for valid admin user
2004-03-22 01:58:40 +00:00
require_login ();
2006-08-09 13:18:33 +00:00
$context = get_context_instance ( CONTEXT_SYSTEM , SITEID );
2006-08-08 05:13:06 +00:00
2006-08-14 06:03:30 +00:00
require_capability ( 'moodle/site:config' , $context );
2006-09-02 15:29:52 +00:00
/// check that site is properly customized
if ( empty ( $site -> shortname ) or empty ( $site -> shortname )) {
2006-09-11 18:56:41 +00:00
redirect ( 'settings.php?section=frontpage&return=site' );
2006-09-02 15:29:52 +00:00
}
2001-11-22 06:23:56 +00:00
2005-05-26 14:46:28 +00:00
/// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
2005-06-15 12:31:09 +00:00
if ( ! empty ( $id )) {
if ( $id == $CFG -> siteidentifier ) {
2005-05-26 14:46:28 +00:00
set_config ( 'registered' , time ());
}
}
2006-08-19 02:46:46 +00:00
/// Everything should now be set up, and the user is an admin
2001-11-22 06:23:56 +00:00
2006-08-19 02:46:46 +00:00
/// Print default admin page with notifications.
2006-08-18 07:25:17 +00:00
2006-09-02 13:14:57 +00:00
$adminroot = admin_get_root ();
admin_externalpage_setup ( 'adminnotifications' , $adminroot );
admin_externalpage_print_header ( $adminroot );
2006-08-19 02:46:46 +00:00
2006-03-10 03:43:33 +00:00
/// Deprecated database! Warning!!
if ( ! empty ( $CFG -> migrated_to_new_db )) {
2006-03-29 14:52:14 +00:00
print_simple_box_start ( 'center' , '60%' );
2006-03-10 03:43:33 +00:00
print_string ( 'dbmigrationdeprecateddb' , 'admin' );
print_simple_box_end ();
}
2006-08-19 02:46:46 +00:00
/// Check for any special upgrades that might need to be run
if ( ! empty ( $CFG -> upgrade )) {
2005-02-13 21:29:20 +00:00
print_simple_box ( get_string ( " upgrade $CFG->upgrade " , " admin " ,
2006-04-06 01:38:52 +00:00
" $CFG->wwwroot / $CFG->admin /upgrade $CFG->upgrade .php " ), " center " , '60%' );
2004-02-05 09:55:50 +00:00
print_spacer ( 10 , 10 );
}
2006-01-05 06:28:57 +00:00
if ( ini_get_bool ( 'register_globals' ) && ! ini_get_bool ( 'magic_quotes_gpc' )) {
2006-04-06 01:38:52 +00:00
print_simple_box ( get_string ( 'globalsquoteswarning' , 'admin' ), 'center' , '60%' );
2006-01-05 06:28:57 +00:00
}
2006-08-28 20:11:24 +00:00
if ( is_dataroot_insecure ()) {
print_simple_box ( get_string ( 'datarootsecuritywarning' , 'admin' , $CFG -> dataroot ), 'center' , '60%' );
}
2005-01-17 20:59:17 +00:00
/// If no recently cron run
$lastcron = get_field_sql ( 'SELECT max(lastcron) FROM ' . $CFG -> prefix . 'modules' );
if ( time () - $lastcron > 3600 * 24 ) {
2006-03-12 07:51:53 +00:00
$strinstallation = get_string ( 'installation' , 'install' );
$helpbutton = helpbutton ( 'install' , $strinstallation , 'moodle' , true , false , '' , true );
2006-04-06 01:38:52 +00:00
print_simple_box ( get_string ( 'cronwarning' , 'admin' ) . " " . $helpbutton , 'center' , '60%' );
2005-01-17 20:59:17 +00:00
}
2005-02-10 05:11:34 +00:00
/// Alert if we are currently in maintenance mode
if ( file_exists ( $CFG -> dataroot . '/1/maintenance.html' )) {
2006-04-06 01:38:52 +00:00
print_simple_box ( get_string ( 'sitemaintenancewarning' , 'admin' ) , 'center' , '60%' );
2006-01-31 08:21:04 +00:00
}
2006-09-01 18:41:30 +00:00
/// Alert to display the utf-8 migration button (if !unicode yet and DB is MySQL or PG)
if ( empty ( $CFG -> unicodedb ) && in_array ( $CFG -> dbtype , array ( 'mysql' , 'postgres7' ))) {
2006-04-06 01:38:52 +00:00
print_simple_box ( get_string ( 'unicodeupgradenotice' , 'admin' ) , 'center' , '60%' );
2005-02-10 05:11:34 +00:00
}
2005-05-26 14:46:28 +00:00
/// Print slightly annoying registration button every six months ;-)
/// You can set the "registered" variable to something far in the future
/// if you really want to prevent this. eg 9999999999
if ( ! isset ( $CFG -> registered ) || $CFG -> registered < ( time () - 3600 * 24 * 30 * 6 )) {
$options = array ();
$options [ 'sesskey' ] = $USER -> sesskey ;
2006-03-29 14:52:14 +00:00
print_simple_box_start ( 'center' , '60%' );
2005-05-26 14:46:28 +00:00
echo '<div align="center">' ;
print_string ( 'pleaseregister' , 'admin' );
print_single_button ( 'register.php' , $options , get_string ( 'registration' ));
echo '</div>' ;
print_simple_box_end ();
2006-08-19 02:46:46 +00:00
$registrationbuttonshown = true ;
2005-05-26 14:46:28 +00:00
}
2006-08-19 02:46:46 +00:00
/// The old admin menu
if ( optional_param ( 'oldmenu' , 0 )) {
$table -> tablealign = " center " ;
$table -> align = array ( " right " , " left " );
$table -> wrap = array ( " nowrap " , " nowrap " );
$table -> cellpadding = 5 ;
$table -> cellspacing = 0 ;
$table -> width = '40%' ;
$configdata = '<div class="adminlink"><a href="config.php">' . get_string ( 'configvariables' , 'admin' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpconfigvariables' ) . '</span></div>' ;
$configdata .= '<div class="adminlink"><a href="site.php">' . get_string ( 'sitesettings' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpsitesettings' ) . '</span></div>' ;
$configdata .= '<div class="adminlink"><a href="../theme/index.php">' . get_string ( 'themes' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpthemes' ) . '</span></div>' ;
$configdata .= '<div class="adminlink"><a href="lang.php">' . get_string ( 'language' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelplanguage' ) . '</span></div>' ;
$configdata .= '<div class="adminlink"><a href="modules.php">' . get_string ( 'managemodules' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpmanagemodules' ) . '</span></div>' ;
$configdata .= '<div class="adminlink"><a href="blocks.php">' . get_string ( 'manageblocks' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpmanageblocks' ) . '</span></div>' ;
$configdata .= '<div class="adminlink"><a href="filters.php">' . get_string ( 'managefilters' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpmanagefilters' ) . '</span></div>' ;
2006-09-03 13:10:56 +00:00
if ( empty ( $CFG -> disablescheduledbackups )) {
2006-08-19 02:46:46 +00:00
$configdata .= '<div class="adminlink"><a href="backup.php">' . get_string ( 'backup' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpbackup' ) . '</span></div>' ;
}
$configdata .= '<div class="adminlink"><a href="editor.php">' . get_string ( 'editorsettings' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpeditorsettings' ) . '</span></div>' ;
$configdata .= '<div class="adminlink"><a href="calendar.php">' . get_string ( 'calendarsettings' , 'admin' ) .
'</a> - <span class="explanation">' . get_string ( 'helpcalendarsettings' , 'admin' ) . '</span></div>' ;
$configdata .= '<div class="adminlink"><a href="maintenance.php">' . get_string ( 'sitemaintenancemode' , 'admin' ) .
'</a> - <span class="explanation">' . get_string ( 'helpsitemaintenance' , 'admin' ) . '</span></div>' ;
2006-09-03 13:10:56 +00:00
$table -> data [] = array ( '<strong>' . get_string ( 'configuration' ) . '</strong>' , $configdata );
2006-08-19 02:46:46 +00:00
$userdata = '<div class="adminlink"><a href="auth.php?sesskey=' . $USER -> sesskey . '">' . get_string ( " authentication " ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpauthentication' ) . '</span></div>' ;
$userdata .= '<div class="adminlink"><a href="user.php">' . get_string ( 'edituser' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpedituser' ) . '</span></div>' ;
$userdata .= '<div class="adminlink"><a href="' . $CFG -> wwwroot . '/' . $CFG -> admin . '/user.php?newuser=true&sesskey=' . $USER -> sesskey . '">' .
get_string ( 'addnewuser' ) . '</a> - <span class="explanation">' . get_string ( 'adminhelpaddnewuser' ) . '</span></div>' ;
$userdata .= '<div class="adminlink"><a href="' . $CFG -> wwwroot . '/' . $CFG -> admin . '/uploaduser.php?sesskey=' . $USER -> sesskey . '">' .
get_string ( 'uploadusers' ) . '</a> - <span class="explanation">' . get_string ( 'adminhelpuploadusers' ) . '</span></div>' ;
$userdata .= '<div class="adminlink"><a href="roles/manage.php">' .
get_string ( 'manageroles' ) . '</a> - <span class="explanation">' . get_string ( 'adminhelpmanageroles' ) .
'</span></div>' ;
$userdata .= '<div class="adminlink"><a href="roles/assign.php?contextid=' . $context -> id . '">' .
get_string ( 'assignsiteroles' ) . '</a> - <span class="explanation">' . get_string ( 'adminhelpassignsiteroles' ) .
'</span></div>' ;
2006-09-03 13:10:56 +00:00
$table -> data [] = array ( '<strong>' . get_string ( 'users' ) . '</strong>' , $userdata );
2006-08-19 02:46:46 +00:00
$coursedata = '<div class="adminlink"><a href="../course/index.php?edit=on&sesskey=' . $USER -> sesskey . '">' . get_string ( 'managecourses' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpcourses' ) . '</span></div>' ;
$coursedata .= '<div class="adminlink"><a href="enrol.php?sesskey=' . $USER -> sesskey . '">' . get_string ( 'enrolmentplugins' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpenrolments' ) . '</span></div>' ;
2006-09-03 13:10:56 +00:00
$table -> data [] = array ( '<strong>' . get_string ( 'courses' ) . '</strong>' , $coursedata );
2006-08-19 02:46:46 +00:00
$miscdata = '<div class="adminlink"><a href="../files/index.php?id=' . $site -> id . '">' . get_string ( 'sitefiles' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpsitefiles' ) . '</span></div>' ;
$miscdata .= '<div class="adminlink"><a href="stickyblocks.php">' . get_string ( 'stickyblocks' , 'admin' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpstickyblocks' ) . '</span></div>' ;
$miscdata .= '<div class="adminlink"><a href="report.php">' . get_string ( 'reports' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpreports' ) . '</span></div>' ;
//to be enabled later
/* $miscdata .= '<div class="adminlink"><a href="health.php">' . get_string ( 'healthcenter' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelphealthcenter' ) . '</span></div>' ; */
$miscdata .= '<div class="adminlink"><a href="environment.php">' . get_string ( 'environment' , 'admin' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpenvironment' ) . '</span></div>' ;
/// Optional stuff
if ( file_exists ( " $CFG->dirroot / $CFG->admin / $CFG->dbtype " )) {
$miscdata .= '<div class="adminlink"><a href="' . $CFG -> dbtype . '/frame.php">' . get_string ( 'managedatabase' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpmanagedatabase' ) . '</span></div>' ;
}
/// Hack to show the XMLDB editor
if ( file_exists ( " $CFG->dirroot / $CFG->admin /xmldb " )) {
$miscdata .= '<div class="adminlink"><a href="xmldb/index.php">' . get_string ( 'xmldbeditor' ) .
'</a> - <span class="explanation">' . get_string ( 'adminhelpxmldbeditor' ) . '</span></div>' ;
}
2006-09-03 13:10:56 +00:00
$table -> data [] = array ( '<strong>' . get_string ( 'miscellaneous' ) . '</strong>' , $miscdata );
2006-08-19 02:46:46 +00:00
2006-09-03 13:10:56 +00:00
/*
2006-08-19 02:46:46 +00:00
/// Hooks for Matt Oquists contrib code for repositories and portfolio.
/// The eventual official versions may not look like this
if ( isset ( $CFG -> portfolio ) && file_exists ( " $CFG->dirroot / $CFG->portfolio " )) {
$table -> data [] = array ( " <strong><a href= \" ../portfolio/ \" > " . get_string ( 'portfolio' , 'portfolio' ) . ' </ a ></
strong > ' ,
'<div class="explanation">' . get_string ( 'adminhelpportfolio' , 'portfolio' ) . '</div>' );
}
if ( isset ( $CFG -> repo ) && file_exists ( " $CFG->dirroot / $CFG->repo " )) {
2006-04-06 01:38:52 +00:00
$table -> data [] = array ( " <strong><a href= \" ../repository/?repoid=1&action=list \" > " . get_string ( 'repository' , '
2006-08-19 02:46:46 +00:00
repository ').' </ a ></ strong > ' ,
'<div class="explanation">' . get_string ( 'adminhelprepository' , 'repository' ) . '</div>' );
}
2006-09-03 13:10:56 +00:00
*/
2006-08-19 02:46:46 +00:00
print_table ( $table );
} else {
print_simple_box ( 'The old admin menu has been replaced by a new system, make sure the administration block is showing on this page. If you want to, you can can also <a href="index.php?oldmenu=true">temporarily display the old menu</a>' , 'center' , '60%' );
2006-04-06 01:38:52 +00:00
}
2003-08-10 09:12:17 +00:00
//////////////////////////////////////////////////////////////////////////////////////////////////
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO REMOVE OR MODIFY THE COPYRIGHT NOTICE BELOW ////
2006-01-13 15:30:24 +00:00
$copyrighttext = '<a href="http://moodle.org/">Moodle</a> ' .
2006-03-10 08:28:59 +00:00
'<a href="http://docs.moodle.org/en/Release">' . $CFG -> release . '</a> (' . $CFG -> version . ')<br />' .
'Copyright © 1999 onwards, Martin Dougiamas<br />' .
'<a href="http://docs.moodle.org/en/License">GNU Public License</a>' ;
2006-01-13 15:30:24 +00:00
echo '<p class="copyright">' . $copyrighttext . '</p>' ;
2003-08-10 09:12:17 +00:00
//////////////////////////////////////////////////////////////////////////////////////////////////
2003-08-10 08:01:14 +00:00
2003-05-12 11:30:19 +00:00
2006-08-19 02:46:46 +00:00
if ( empty ( $registrationbuttonshown )) {
echo '<div align="center">' ;
$options = array ();
$options [ 'sesskey' ] = $USER -> sesskey ;
print_single_button ( 'register.php' , $options , get_string ( 'registration' ));
echo '</div>' ;
}
2003-05-12 11:30:19 +00:00
2003-08-10 08:01:14 +00:00
print_simple_box_end ();
2002-09-27 06:19:18 +00:00
2006-01-31 08:21:04 +00:00
2006-03-29 14:52:14 +00:00
if ( optional_param ( 'dbmigrate' )) { // ??? Is this actually used?
print_simple_box_start ( 'center' , '60%' );
2006-01-31 08:21:04 +00:00
require_once ( $CFG -> dirroot . '/admin/utfdbmigrate.php' );
db_migrate2utf8 ();
2006-03-29 14:52:14 +00:00
print_simple_box_end ();
2006-01-31 08:21:04 +00:00
}
2006-09-02 13:14:57 +00:00
admin_externalpage_print_footer ( $adminroot );
2002-09-19 12:01:55 +00:00
2006-08-28 06:02:00 +00:00
2006-09-02 23:55:56 +00:00
?>