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 );
2007-01-22 20:15:12 +00:00
$confirmrelease = optional_param ( 'confirmrelease' , 0 , PARAM_BOOL );
$agreelicense = optional_param ( 'agreelicense' , 0 , PARAM_BOOL );
$autopilot = optional_param ( 'autopilot' , 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-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
2007-01-22 20:15:12 +00:00
/// set install/upgrade autocontinue session flag
if ( $autopilot ) {
$_SESSION [ 'installautopilot' ] = $autopilot ;
}
2003-01-28 02:52:13 +00:00
/// Check some PHP server settings
2006-10-06 06:26:06 +00:00
$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</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
}
2007-01-16 17:41:58 +00:00
if ( empty ( $CFG -> prefix ) && $CFG -> dbfamily != 'mysql' ) { //Enforce prefixes for everybody but mysql
2006-10-13 23:49:48 +00:00
error ( '$CFG->prefix can\'t be empty for your target DB (' . $CFG -> dbtype . ')' );
}
2007-01-12 00:06:08 +00:00
if ( $CFG -> dbfamily == 'oracle' && strlen ( $CFG -> prefix ) > 2 ) { //Max prefix length for Oracle is 2cc
2006-10-13 23:49:48 +00:00
error ( '$CFG->prefix maximum allowed length for Oracle DBs is 2cc.' );
}
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 = " " ;
}
2007-01-22 22:32:00 +00:00
if ( is_readable ( " $CFG->dirroot /version.php " )) {
include_once ( " $CFG->dirroot /version.php " ); # defines $version
}
if ( ! $version or ! $release ) {
error ( 'Main version.php was not readable or specified' ); # without version, stop
}
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 " ,
2006-09-19 01:44:33 +00:00
" user " );
2002-12-24 05:39:45 +00:00
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 ;
}
}
}
if ( ! $maintables ) {
2006-09-10 21:10:48 +00:00
/// hide errors from headers in case debug enabled in config.php
$origdebug = $CFG -> debug ;
2006-09-23 09:38:39 +00:00
$CFG -> debug = DEBUG_MINIMAL ;
2006-09-10 21:10:48 +00:00
error_reporting ( $CFG -> debug );
2007-01-22 20:15:12 +00:00
if ( empty ( $agreelicense )) {
2007-01-09 08:18:34 +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 " );
2007-01-09 08:18:34 +00:00
print_heading ( get_string ( 'copyrightnotice' ));
print_box ( text_to_html ( get_string ( 'gpl' )), 'copyrightnotice' );
2003-05-26 14:38:41 +00:00
echo " <br /> " ;
2007-01-22 20:15:12 +00:00
notice_yesno ( get_string ( 'doyouagree' ), " index.php?agreelicense=1 " ,
2006-04-16 16:09:12 +00:00
" http://docs.moodle.org/en/License " );
2007-03-02 20:46:45 +00:00
print_footer ( 'none' );
2002-08-17 08:38:43 +00:00
exit ;
}
2007-01-22 20:15:12 +00:00
if ( empty ( $confirmrelease )) {
$strcurrentrelease = get_string ( " currentrelease " );
print_header ( $strcurrentrelease , $strcurrentrelease , $strcurrentrelease , " " , " " , false , " " , " " );
print_heading ( " Moodle $release " );
2007-03-02 20:46:45 +00:00
print_box ( get_string ( 'releasenoteslink' , 'admin' , 'http://docs.moodle.org/en/Release_Notes' ), 'generalbox boxaligncenter boxwidthwide' );
2007-03-01 04:06:08 +00:00
echo '<form action="index.php"><div>' ;
2007-01-22 20:15:12 +00:00
echo '<input type="hidden" name="agreelicense" value="1" />' ;
echo '<input type="hidden" name="confirmrelease" value="1" />' ;
2007-03-01 04:06:08 +00:00
echo '</div>' ;
2007-01-22 20:15:12 +00:00
echo '<div class="continuebutton"><input name="autopilot" id="autopilot" type="checkbox" value="1" /><label for="autopilot">' . get_string ( 'unattendedoperation' , 'admin' ) . '</label>' ;
echo '<br /><br /><input type="submit" value="' . get_string ( 'continue' ) . '" /></div>' ;
echo '</form>' ;
print_footer ( 'none' );
die ;
}
2002-08-17 08:38:43 +00:00
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 ,
2007-01-22 20:15:12 +00:00
" " , upgrade_get_javascript (), 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
2006-10-01 05:49:41 +00:00
/// But we prioritise install.xml (XMLDB) if present
2006-10-18 07:26:04 +00:00
change_db_encoding (); // first try to change db encoding to utf8
2006-11-10 02:42:13 +00:00
if ( ! setup_is_unicodedb ()) {
// If could not convert successfully, throw error, and prevent installation
print_error ( 'unicoderequired' , 'admin' );
2006-11-11 17:23:20 +00:00
}
2006-11-10 02:42:13 +00:00
2006-08-30 23:13:43 +00:00
$status = false ;
2006-09-20 22:36:21 +00:00
if ( file_exists ( " $CFG->libdir /db/install.xml " )) {
2006-08-30 23:13:43 +00:00
$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-11-20 15:25:38 +00:00
// all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
set_config ( 'unicodedb' , 1 );
2006-08-30 23:13:43 +00:00
/// Continue with the instalation
$db -> debug = false ;
if ( $status ) {
2007-04-29 11:40:26 +00:00
//ugly hack - install new groups: MDL-9217
require_once ( " $CFG->dirroot /group/db/upgrade.php " );
install_group_db ();
2006-08-30 23:13:43 +00:00
// Install the roles system.
moodle_install_roles ();
2006-09-22 11:09:15 +00:00
set_config ( 'statsrolesupgraded' , time ());
2006-08-30 23:13:43 +00:00
2007-05-17 14:04:22 +00:00
// install core event handlers
events_update_definition ();
2007-04-29 11:40:26 +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 ,
2007-02-24 09:48:10 +00:00
'registerauth' => 'email' ,
2006-08-30 23:13:43 +00:00
'style' => 'default' ,
'template' => 'default' ,
2006-12-12 10:39:17 +00:00
'theme' => 'standardwhite' ,
'filter_multilang_converted' => 1 ));
2006-08-30 23:13:43 +00:00
notify ( $strdatabasesuccess , " green " );
2007-01-04 03:19:49 +00:00
require_once $CFG -> dirroot . '/mnet/lib.php' ;
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' );
2007-01-15 19:16:29 +00:00
print_footer ( 'none' );
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-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
}
2006-09-20 22:36:21 +00:00
if ( file_exists ( " $CFG->dirroot /lib/db/upgrade.php " )) {
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
2006-10-16 07:32:05 +00:00
/// If the database is not already Unicode then we do not allow upgrading!
/// Instead, we print an error telling them to upgrade to 1.7 first. MDL-6857
if ( empty ( $CFG -> unicodedb )) {
print_error ( 'unicodeupgradeerror' , 'error' , '' , $version );
}
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 ;
2006-09-23 09:38:39 +00:00
$CFG -> debug = DEBUG_MINIMAL ;
2006-09-10 21:10:48 +00:00
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 , " " , " " );
2006-11-06 12:51:27 +00:00
2007-01-22 20:15:12 +00:00
notice_yesno ( get_string ( 'upgradesure' , 'admin' , $a -> newversion ), 'index.php?confirmupgrade=1' , 'index.php' );
2004-09-04 15:47:30 +00:00
exit ;
2005-02-13 21:29:20 +00:00
2007-01-22 20:15:12 +00:00
} else if ( empty ( $confirmrelease )){
$strcurrentrelease = get_string ( " currentrelease " );
print_header ( $strcurrentrelease , $strcurrentrelease , $strcurrentrelease , " " , " " , false , " " , " " );
print_heading ( " Moodle $release " );
print_box ( get_string ( 'releasenoteslink' , 'admin' , 'http://docs.moodle.org/en/Release_Notes' ));
2007-02-15 06:30:35 +00:00
require_once ( $CFG -> libdir . '/environmentlib.php' );
print_heading ( get_string ( 'environment' , 'admin' ));
if ( ! check_moodle_environment ( $release , $environment_results , true )) {
notice_yesno ( get_string ( 'environmenterrorupgrade' , 'admin' ),
'index.php?confirmupgrade=1&confirmrelease=1' , 'index.php' );
} else {
notify ( get_string ( 'environmentok' , 'admin' ), 'notifysuccess' );
2007-03-01 04:06:08 +00:00
echo '<form action="index.php"><div>' ;
2007-02-15 06:30:35 +00:00
echo '<input type="hidden" name="confirmupgrade" value="1" />' ;
echo '<input type="hidden" name="confirmrelease" value="1" />' ;
2007-03-01 04:06:08 +00:00
echo '</div>' ;
2007-04-15 12:50:55 +00:00
echo '<div class="continuebutton"><input name="autopilot" id="autopilot" type="checkbox" value="1" /><label for="autopilot">' . get_string ( 'unattendedoperation' , 'admin' ) . '</label>' ;
2007-02-15 06:30:35 +00:00
echo '<br /><br /><input type="submit" value="' . get_string ( 'continue' ) . '" /></div>' ;
echo '</form>' ;
}
2007-01-22 20:15:12 +00:00
print_footer ( 'none' );
die ;
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 ,
2007-01-22 20:15:12 +00:00
" " , upgrade_get_javascript (), false , " " , " " );
2006-11-06 12:51:27 +00:00
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 ();
2006-11-06 12:51:27 +00:00
/// Upgrade current language pack if we can
upgrade_language_pack ();
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 )) {
2007-04-29 11:40:26 +00:00
//ugly hack - upgrade to new groups (from 1.6) : MDL-9217
require_once ( " $CFG->dirroot /group/db/upgrade.php " );
install_group_db ();
2006-08-11 02:44:42 +00:00
// Upgrade to the roles system.
moodle_install_roles ();
set_config ( 'rolesactive' , 1 );
2006-09-27 22:59:37 +00:00
} else if ( ! update_capabilities ()) {
error ( 'Had trouble upgrading the core capabilities for the Roles System' );
2006-08-08 05:13:06 +00:00
}
2007-04-20 05:43:11 +00:00
// update core events
events_update_definition ();
2006-09-22 10:00:34 +00:00
require_once ( $CFG -> libdir . '/statslib.php' );
if ( ! stats_upgrade_for_roles_wrapper ()) {
notify ( 'Couldn\'t upgrade the stats tables to use the new roles system' );
}
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 " );
2007-01-15 19:16:29 +00:00
print_footer ( 'none' );
2004-09-04 15:47:30 +00:00
exit ;
} else {
2007-01-22 22:32:00 +00:00
error ( 'Upgrade failed! (Could not update version in config table)' );
2004-09-04 15:47:30 +00:00
}
2006-08-24 22:27:11 +00:00
/// Main upgrade not success
2002-07-27 13:09:08 +00:00
} else {
2007-01-22 22:32:00 +00:00
notify ( 'Main Upgrade failed! See lib/db/upgrade.php' );
print_continue ( 'index.php?confirmupgrade=1&confirmrelease=1' );
print_footer ( 'none' );
die ;
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
if ( ! set_config ( " release " , $release )) {
2007-01-22 22:32:00 +00:00
error ( " ERROR: Could not update release version in database!! " );
2002-09-06 14:06:48 +00:00
}
}
2004-07-29 18:01:32 +00:00
2007-04-29 11:40:26 +00:00
/// ugly hack - convert to new groups if upgrading from 1.7; must be reworked
require_once ( " $CFG->dirroot /group/db/upgrade.php " );
upgrade_group_db ( " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
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
2006-12-11 15:47:23 +00:00
/// Check all course formats and upgrade if necessary
upgrade_plugins ( 'format' , 'course/format' , " $CFG->wwwroot / $CFG->admin /index.php " );
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
2007-01-04 03:19:49 +00:00
/// Check for changes to RPC functions
require_once ( $CFG -> dirroot . '/admin/mnet/adminlib.php' );
upgrade_RPC_functions ( " $CFG->wwwroot / $CFG->admin /index.php " ); // Return here afterwards
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
2007-01-22 20:15:12 +00:00
unset ( $_SESSION [ 'installautopilot' ]);
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-20 21:00:45 +00:00
}
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
2007-01-23 04:58:50 +00:00
set_config ( 'siteidentifier' , random_string ( 32 ) . $_SERVER [ 'HTTP_HOST' ]);
2005-01-22 03:27:37 +00:00
}
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 " ));
2007-01-04 03:32:55 +00:00
$guest -> mnethostid = $CFG -> mnet_localhost_id ;
2005-03-03 14:56:19 +00:00
$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 )) {
2007-01-25 00:04:02 +00:00
create_admin_user ();
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 )) {
2007-01-30 09:33:11 +00:00
redirect ( 'settings.php?section=frontpagesettings&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 ());
}
}
2007-04-18 09:39:49 +00:00
$adminroot = admin_get_root ();
/// Check if there are any new admin settings which have still yet to be set
if ( any_new_admin_settings ( $adminroot ) ){
redirect ( 'upgradesettings.php' );
}
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
2007-04-30 17:08:34 +00:00
admin_externalpage_setup ( 'adminnotifications' );
admin_externalpage_print_header ();
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 )) {
2007-03-02 20:46:45 +00:00
print_box ( print_string ( 'dbmigrationdeprecateddb' , 'admin' ), 'generalbox adminwarning' );
2006-03-10 03:43:33 +00:00
}
2006-08-19 02:46:46 +00:00
/// Check for any special upgrades that might need to be run
2006-09-20 21:00:45 +00:00
if ( ! empty ( $CFG -> upgrade )) {
2007-01-09 12:32:12 +00:00
print_box ( get_string ( " upgrade $CFG->upgrade " , " admin " , " $CFG->wwwroot / $CFG->admin /upgrade $CFG->upgrade .php " ));
2004-02-05 09:55:50 +00:00
}
2006-01-05 06:28:57 +00:00
if ( ini_get_bool ( 'register_globals' ) && ! ini_get_bool ( 'magic_quotes_gpc' )) {
2007-03-02 20:46:45 +00:00
print_box ( get_string ( 'globalsquoteswarning' , 'admin' ), 'generalbox adminwarning' );
2006-01-05 06:28:57 +00:00
}
2006-08-28 20:11:24 +00:00
if ( is_dataroot_insecure ()) {
2007-03-02 20:46:45 +00:00
print_box ( get_string ( 'datarootsecuritywarning' , 'admin' , $CFG -> dataroot ), 'generalbox adminwarning' );
2006-08-28 20:11:24 +00:00
}
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 );
2007-03-02 20:46:45 +00:00
print_box ( get_string ( 'cronwarning' , 'admin' ) . " " . $helpbutton , 'generalbox adminwarning' );
2005-01-17 20:59:17 +00:00
}
2006-12-12 10:39:17 +00:00
/// Print multilang upgrade notice if needed
if ( empty ( $CFG -> filter_multilang_converted )) {
2007-03-02 20:46:45 +00:00
print_box ( get_string ( 'multilangupgradenotice' , 'admin' ), 'generalbox adminwarning' );
2006-12-12 10:39: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' )) {
2007-03-02 20:46:45 +00:00
print_box ( get_string ( 'sitemaintenancewarning' , 'admin' ), 'generalbox adminwarning' );
2006-01-31 08:21:04 +00:00
}
2005-02-10 05:11:34 +00:00
2005-05-26 14:46:28 +00:00
/// Print slightly annoying registration button every six months ;-)
2006-09-20 21:00:45 +00:00
/// You can set the "registered" variable to something far in the future
2005-05-26 14:46:28 +00:00
/// 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 ;
2007-03-02 20:46:45 +00:00
print_box_start ( 'generalbox adminwarning' );
2005-05-26 14:46:28 +00:00
print_string ( 'pleaseregister' , 'admin' );
print_single_button ( 'register.php' , $options , get_string ( 'registration' ));
2007-01-09 12:32:12 +00:00
print_box_end ();
2006-08-19 02:46:46 +00:00
$registrationbuttonshown = true ;
2005-05-26 14:46:28 +00:00
}
2003-08-10 09:12:17 +00:00
//////////////////////////////////////////////////////////////////////////////////////////////////
2006-09-12 09:30:05 +00:00
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
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 />' .
2006-09-12 09:30:05 +00:00
'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />' .
2006-03-10 08:28:59 +00:00
'<a href="http://docs.moodle.org/en/License">GNU Public License</a>' ;
2007-01-09 12:32:12 +00:00
print_box ( $copyrighttext , 'copyright' );
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 )) {
$options = array ();
$options [ 'sesskey' ] = $USER -> sesskey ;
print_single_button ( 'register.php' , $options , get_string ( 'registration' ));
}
2003-05-12 11:30:19 +00:00
2006-09-20 21:00:45 +00:00
2006-03-29 14:52:14 +00:00
if ( optional_param ( 'dbmigrate' )) { // ??? Is this actually used?
2007-01-09 12:32:12 +00:00
print_box_start ();
2006-09-26 21:10:14 +00:00
require_once ( $CFG -> dirroot . '/' . $CFG -> admin . '/utfdbmigrate.php' );
2006-01-31 08:21:04 +00:00
db_migrate2utf8 ();
2007-01-09 12:32:12 +00:00
print_box_end ();
2006-01-31 08:21:04 +00:00
}
2007-04-30 17:08:34 +00:00
admin_externalpage_print_footer ();
2002-09-19 12:01:55 +00:00
2006-08-28 06:02:00 +00:00
2006-09-12 09:22:27 +00:00
?>