$value) { if ($gpc) { $value = stripslashes($value); } $INSTALL[$setting] = $value; } if ( $goforward = (! empty( $_POST['next'] )) ) { $nextstage = $_POST['stage'] + 1; } else if (! empty( $_POST['prev'])) { $nextstage = $_POST['stage'] - 1; $INSTALL['stage'] = $_POST['stage'] - 1; } else if (! empty( $_POST['same'] )) { $nextstage = $_POST['stage']; } $nextstage = (int)$nextstage; if ($nextstage < 0) { $nextstage = WELCOME; } } else { $goforward = true; $nextstage = WELCOME; } //==========================================================================// /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php $SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language']; $CFG->dirroot = $INSTALL['dirroot']; $CFG->libdir = $INSTALL['dirroot'].'/lib'; $CFG->dataroot = $INSTALL['dataroot']; $CFG->admin = $INSTALL['admindirname']; $CFG->directorypermissions = 00777; $CFG->running_installer = true; $CFG->docroot = 'http://docs.moodle.org'; $CFG->httpswwwroot = $INSTALL['wwwrootform']; // Needed by doc_link() in Server Checks page. $COURSE->id = 0; /// Include some moodle libraries require_once($CFG->libdir.'/setuplib.php'); require_once($CFG->libdir.'/installlib.php'); require_once($CFG->libdir.'/weblib.php'); require_once($CFG->libdir.'/deprecatedlib.php'); require_once($CFG->libdir.'/moodlelib.php'); require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/environmentlib.php'); require_once($CFG->libdir.'/xmlize.php'); require_once($CFG->libdir.'/componentlib.class.php'); require_once($CFG->dirroot.'/version.php'); /// Set version and release $INSTALL['version'] = $version; $INSTALL['release'] = $release; /// list all supported drivers - unsupported must be installed manually ;-) $supported = array ( 'mysqli_adodb', 'mysql_adodb', 'postgres7_adodb', 'mssql_n_adodb', 'mssql_adodb', 'odbc_mssql_adodb', 'oci8po_adodb', 'sqlite3_pdo', ); $databases = array (); foreach($supported as $driver) { $classname = $driver.'_moodle_database'; require_once ("$CFG->libdir/dml/$classname.php"); $databases[$driver] = new $classname (); } /// guess the www root if ($INSTALL['wwwroot'] == '') { $INSTALL['wwwroot'] = install_guess_wwwroot(); $INSTALL['wwwrootform'] = $INSTALL['wwwroot']; // now try to guess the correct dataroot not accessible via web $CFG->wwwroot = $INSTALL['wwwroot']; $i = 0; //safety check - dirname might return some unexpected results while(is_dataroot_insecure()) { $parrent = dirname($CFG->dataroot); $i++; if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) { $CFG->dataroot = ''; //can not find secure location for dataroot break; } $CFG->dataroot = dirname($parrent).'/moodledata'; } $INSTALL['dataroot'] = $CFG->dataroot; } $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'), COMPATIBILITY => get_string('compatibilitysettingshead', 'install'), DIRECTORY => get_string('directorysettingshead', 'install'), DATABASE => get_string('databasesettingshead', 'install'), ADMIN => get_string('admindirsettinghead', 'install'), ENVIRONMENT => get_string('environmenthead', 'install'), DOWNLOADLANG => get_string('downloadlanguagehead', 'install'), SAVE => get_string('configurationcompletehead', 'install') ); $substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'), COMPATIBILITY => get_string('compatibilitysettingssub', 'install'), DIRECTORY => get_string('directorysettingssub', 'install'), DATABASE => get_string('databasesettingssub', 'install'), ADMIN => get_string('admindirsettingsub', 'install'), ENVIRONMENT => get_string('environmentsub', 'install'), DOWNLOADLANG => get_string('downloadlanguagesub', 'install'), SAVE => get_string('configurationcompletesub', 'install') ); //==========================================================================// /// Are we in help mode? if (isset($_GET['help'])) { $nextstage = -1; } //==========================================================================// /// Are we in config download mode? if (isset($_GET['download'])) { header("Content-Type: application/x-forcedownload\n"); header("Content-Disposition: attachment; filename=\"config.php\""); echo $INSTALL['config']; exit; } //==========================================================================// /// Check the directory settings if ($INSTALL['stage'] == DIRECTORY) { error_reporting(0); /// check wwwroot if (ini_get('allow_url_fopen') && false) { /// This was not reliable if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) { $errormsg .= get_string('wwwrooterror', 'install').'
'; $INSTALL['wwwrootform'] = $INSTALL['wwwroot']; fclose($fh); } } /// check dirroot if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false) { $errormsg .= get_string('dirrooterror', 'install').'
'; $INSTALL['dirrootform'] = $INSTALL['dirroot']; fclose($fh); } /// check dataroot $CFG->dataroot = $INSTALL['dataroot']; $CFG->wwwroot = $INSTALL['wwwroot']; if (make_upload_directory('sessions', false) === false) { $errormsg .= get_string('datarooterror', 'install').'
'; } else if (is_dataroot_insecure(true) == INSECURE_DATAROOT_ERROR) { $errormsg .= get_string('datarootpublicerror', 'install').'
'; } if (!empty($errormsg)) { $nextstage = DIRECTORY; } error_reporting(38911); } //==========================================================================// /// Check database settings if stage 3 data submitted /// Try to connect to the database. If that fails then try to create the database if ($INSTALL['stage'] == DATABASE) { $DB = $databases[$INSTALL['dbtype']]; $dbfamily = $DB->get_dbfamily(); $errormsg = $DB->driver_installed(); if ($errormsg === true) { $errormsg = ''; } else { $nextstage = DATABASE; } if (empty($INSTALL['prefix']) and $dbfamily != 'mysql') { // All DBs but MySQL require prefix (reserv. words) $errormsg = get_string('dbwrongprefix', 'install'); $nextstage = DATABASE; } if ($dbfamily == 'oracle' and strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit) $errormsg = get_string('dbwrongprefix', 'install'); $nextstage = DATABASE; } if ($dbfamily == 'oracle' and !empty ($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it) $errormsg = get_string('dbwronghostserver', 'install'); $nextstage = DATABASE; } if (empty($errormsg)) { error_reporting(0); // Hide errors if (! $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], $INSTALL['prefix'])) { if (!$DB->create_database($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'])) { $errormsg = get_string('dbcreationerror', 'install'); $nextstage = DATABASE; } else { $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], $INSTALL['prefix']); } } else { // TODO: db encoding checks ?? } } error_reporting(38911); /// Output db connection error if ((empty($errormsg) and ($dbconnected === false)) ) { $errormsg = get_string('dbconnectionerror', 'install'); $nextstage = DATABASE; } } //==========================================================================// /// If the next stage is admin directory settings OR we have just come from there then /// check the admin directory. /// If we can open a file then we know that the admin name is correct. if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) { if (!ini_get('allow_url_fopen')) { $nextstage = ($goforward) ? ENVIRONMENT : DATABASE; } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) { $nextstage = ($goforward) ? ENVIRONMENT : DATABASE; fclose($fh); } else { $nextstage = ($goforward) ? ENVIRONMENT : DATABASE; //if ($nextstage != ADMIN) { // $errormsg = get_string('admindirerror', 'install'); // $nextstage = ADMIN; // } } } //==========================================================================// // Check if we can navigate from the environemt page (because it's ok) if ($INSTALL['stage'] == ENVIRONMENT) { $DB = $databases[$INSTALL['dbtype']]; error_reporting(0); // Hide errors $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], $INSTALL['prefix']); error_reporting(38911); // Show errors if ($dbconnected) { /// Execute environment check, printing results if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) { $nextstage = ENVIRONMENT; } } else { /// We never should reach this because DB has been tested before arriving here $errormsg = get_string('dbconnectionerror', 'install'); $nextstage = DATABASE; } } //==========================================================================// // Try to download the lang pack if it has been selected if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) { $downloadsuccess = false; $downloaderror = ''; error_reporting(0); // Hide errors /// Create necessary lang dir if (!make_upload_directory('lang', false)) { $downloaderror = get_string('cannotcreatelangdir', 'error'); } /// Download and install component if (($cd = new component_installer('http://download.moodle.org', 'lang16', $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) { $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED) switch ($status) { case COMPONENT_ERROR: if ($cd->get_error() == 'remotedownloaderror') { $a = new stdClass(); $a->url = 'http://download.moodle.org/lang16/'.$INSTALL['language'].'.zip'; $a->dest= $CFG->dataroot.'/lang'; $downloaderror = get_string($cd->get_error(), 'error', $a); } else { $downloaderror = get_string($cd->get_error(), 'error'); } break; case COMPONENT_UPTODATE: case COMPONENT_INSTALLED: $downloadsuccess = true; break; default: //We shouldn't reach this point } } else { //We shouldn't reach this point } error_reporting(38911); // Show errors if ($downloadsuccess) { $INSTALL['downloadlangpack'] = false; $INSTALL['showdownloadlangpack'] = false; $INSTALL['downloadlangpackerror'] = $downloaderror; } else { $INSTALL['downloadlangpack'] = false; $INSTALL['showdownloadlangpack'] = false; $INSTALL['downloadlangpackerror'] = $downloaderror; } } //==========================================================================// /// Display or print the data /// Put the data into a string /// Try to open config file for writing. if ($nextstage == SAVE) { $str = 'export_dbconfig($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], $INSTALL['prefix']); foreach ($dbconfig as $key=>$value) { $key = str_pad($key, 9); $str .= '$CFG->'.$key.' = '.var_export($value, true).";\r\n"; } $str .= "\r\n"; $str .= '$CFG->wwwroot = '.var_export($INSTALL['wwwrootform'], true).";\r\n"; $str .= '$CFG->dirroot = '.var_export($INSTALL['dirrootform'], true).";\r\n"; $str .= '$CFG->dataroot = '.var_export($INSTALL['dataroot'], true).";\r\n"; $str .= '$CFG->admin = '.var_export($INSTALL['admindirname'], true).";\r\n"; $str .= "\r\n"; $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n"; $str .= "\r\n"; $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n"; $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n"; $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n"; $str .= '?>'; umask(0137); if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) { fwrite($fh, $str); fclose($fh); } $INSTALL['config'] = $str; } //==========================================================================// ?> Moodle Install

$database) { echo ''; echo '
' . $database->get_configuration_hints(); echo '

' . get_string('databasesettingswillbecreated', 'install') . '

'; echo '
'; } } else { if (!empty($substagetext[$nextstage])) { echo '

' . $substagetext[$nextstage] . '

'; } } ?>
$errormsg

\n"; if ($nextstage == SAVE) { $INSTALL['stage'] = WELCOME; $options = array(); $options['lang'] = $INSTALL['language']; if ($configsuccess) { echo "

".get_string('configfilewritten', 'install')."

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
  \n"; print_single_button("index.php", $options, get_string('continue')); echo "
\n"; } else { echo "

".get_string('configfilenotwritten', 'install')."

"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
 \n"; $installoptions = array(); $installoptions['download'] = 1; print_single_button("install.php", $installoptions, get_string('download', 'install')); echo "\n"; print_single_button("index.php", $options, get_string('continue')); echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n";
        p($INSTALL['config']);
        echo "
\n"; echo "
\n"; } } else { $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php"; form_table($nextstage, $formaction, $databases); } ?>

$database) { $name = $database->get_name(); if ($database->driver_installed() !== true) { $name = "$name - driver not installed"; // TODO: improve missing driver notification } $options[$type] = $name; } choose_from_menu($options, 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?>

connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'], $INSTALL['prefix']); error_reporting(38911); // Show errors if ($dbconnected) { /// Execute environment check, printing results check_moodle_environment($INSTALL['release'], $environment_results, true); } else { /// We never should reach this because DB has been tested before arriving here $errormsg = get_string('dbconnectionerror', 'install'); $nextstage = DATABASE; echo '

'.get_string('dbconnectionerror', 'install').'

'; } ?>
".$INSTALL['downloadlangpackerror']."

\n"; print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%'); } else { print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%'); } } } ?>
\n" : " \n" ?> WELCOME) ? "
\n" : " \n" ?>
\n"; echo "

$testtext

\n"; if ($success) { echo "

".get_string('pass', 'install')."

\n"; echo " \n"; } else { echo ""; echo ($caution) ? "

".get_string('caution', 'install') : "

".get_string('fail', 'install'); echo "

\n"; echo ""; echo "

$errormessage "; if ($helpfield !== '') { install_helpbutton("install.php?help=$helpfield"); } echo "

\n"; } echo "\n"; return $success; } //==========================================================================// function install_helpbutton($url, $title='') { if ($title == '') { $title = get_string('help'); } echo ""; echo "\"$title\""; echo "\n"; } //==========================================================================// function print_install_help($help) { switch ($help) { case 'phpversionhelp': print_string($help, 'install', phpversion()); break; case 'memorylimithelp': print_string($help, 'install', get_memory_limit()); break; default: print_string($help, 'install'); } } //==========================================================================// function css_styles($databases) { ?>