$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.'/adminlib.php');
require_once($CFG->libdir.'/setuplib.php');
require_once($CFG->libdir.'/moodlelib.php');
require_once($CFG->libdir.'/weblib.php');
require_once($CFG->libdir.'/deprecatedlib.php');
require_once($CFG->libdir.'/dmllib.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'
);
$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'] == '') {
list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
$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'];
if (make_upload_directory('sessions', false) === false) {
$errormsg .= get_string('datarooterror', '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'], false, $INSTALL['prefix'])) {
$db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
switch ($INSTALL['dbtype']) { /// Try to create a database
case 'mysql':
case 'mysqli':
if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) {
$dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
} else {
$errormsg = get_string('dbcreationerror', 'install');
$nextstage = DATABASE;
}
break;
}
}
} 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'], false, $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 = 'connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix']);
$dbconfig = $database->export_dbconfig();
$dbconfig->persistent = false;
foreach ($dbconfig as $key=>$value) {
$key = str_pad($key, 9);
if (is_bool($value)) {
if ($value) {
$str .= '$CFG->'.$key.' = true;'."\r\n";
} else {
$str .= '$CFG->'.$key.' = false;'."\r\n";
}
} else {
$str .= '$CFG->'.$key.' = \''.addsingleslashes($value)."';\r\n";
}
}
$str .= "\r\n";
$str .= '$CFG->wwwroot = \''.addsingleslashes($INSTALL['wwwrootform'])."';\r\n";
$str .= '$CFG->dirroot = \''.addsingleslashes($INSTALL['dirrootform'])."';\r\n";
$str .= '$CFG->dataroot = \''.addsingleslashes($INSTALL['dataroot'])."';\r\n";
$str .= '$CFG->admin = \''.addsingleslashes($INSTALL['admindirname'])."';\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;
}
//==========================================================================//
?>
$database) {
echo '';
echo ' ' . $database->get_configuration_hints();
echo ' ';
}
} else {
if (!empty($substagetext[$nextstage])) {
echo '' . get_string('databasesettingswillbecreated', 'install') . ' '; 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 "
".get_string('configfilenotwritten', 'install')." "; echo "
\n"; echo " \n";
echo " \n";
}
} else {
$formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
form_table($nextstage, $formaction, $databases);
}
?>
\n"; p($INSTALL['config']); echo "\n"; echo " |
$testtext
".get_string('pass', 'install')."
".get_string('caution', 'install') : "
".get_string('fail', 'install'); echo "
$errormessage "; install_helpbutton("install.php?help=$helpfield"); echo "