lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language']; $CFG->dirroot = $INSTALL['dirroot']; $CFG->dataroot = $INSTALL['dataroot']; $CFG->directorypermissions = 00777; /// Include some moodle libraries require_once('./lib/moodlelib.php'); require_once('./lib/weblib.php'); require_once('./lib/adodb/adodb.inc.php'); /// guess the www root if ($INSTALL['wwwroot'] == '') { list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me()); } $stagetext = array(0 => get_string('chooselanguage', 'install'), get_string('compatibilitysettings', 'install'), get_string('directorysettings', 'install'), get_string('databasesettings', 'install'), get_string('admindirsetting', 'install'), get_string('configurationcomplete', '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/download\n"); header("Content-Disposition: attachment; filename=\"config.php\""); echo $INSTALL['config']; exit; } //==========================================================================// /// Was data submitted? if (isset($_POST['stage'])) { /// Get the stage for which the form was set and the next stage we are going to if ( $goforward = (! empty( $_POST['next'] )) ) { $nextstage = $_POST['stage'] + 1; } else { $nextstage = $_POST['stage'] - 1; } if ($nextstage < 0) $nextstage = 0; /// Store any posted data foreach ($_POST as $setting=>$value) { $INSTALL[$setting] = $value; } } else { $goforward = true; $nextstage = 0; } //==========================================================================// /// Check the directory settings if ($INSTALL['stage'] == 2) { error_reporting(0); /// check dirroot if (($fh = @fopen($INSTALL['dirroot'].'/install.php', 'r')) === false ) { $CFG->dirroot = dirname(__FILE__); $INSTALL['dirroot'] = dirname(__FILE__); $errormsg .= get_string('dirrooterror', 'install').'
'; } if ($fh) fclose($fh); $CFG->dirroot = $INSTALL['dirroot']; /// check wwwroot if (ini_get('allow_url_fopen')) { if (($fh = @fopen($INSTALL['wwwroot'].'/install.php', 'r')) === false) { $errormsg .= get_string('wwwrooterror', 'install').'
'; } } if ($fh) fclose($fh); /// check dataroot $CFG->dataroot = $INSTALL['dataroot']; if (make_upload_directory('sessions', false) === false ) { $errormsg = get_string('datarooterror', 'install').'
'; } if ($fh) fclose($fh); if (!empty($errormsg)) $nextstage = 2; error_reporting(7); } //==========================================================================// /// 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'] == 3) { if (empty($INSTALL['dbname'])) { $INSTALL['dbname'] = 'moodle'; } /// different format for postgres7 by socket if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) { $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'"; $INSTALL['dbuser'] = ''; $INSTALL['dbpass'] = ''; $INSTALL['dbname'] = ''; if ($INSTALL['prefix'] == '') { /// must have a prefix $INSTALL['prefix'] = 'mdl_'; } } if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present if (!extension_loaded('mysql')) { $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install'); $nextstage = 3; } } if (empty($errormsg)) { $db = &ADONewConnection($INSTALL['dbtype']); error_reporting(0); // Hide errors if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) { /// The following doesn't seem to work but we're working on it /// If you come up with a solution for creating a database in MySQL /// feel free to put it in and let us know if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { switch ($INSTALL['dbtype']) { /// Try to create a database case 'mysql': if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) { $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']); } else { $errormsg = get_string('dbcreationerror', 'install'); $nextstage = 3; } break; } } } } error_reporting(7); if (($dbconnected === false) and (empty($errormsg)) ) { $errormsg = get_string('dbconnectionerror', 'install'); $nextstage = 3; } } //==========================================================================// /// 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 == 4 or $INSTALL['stage'] == 4) { if (!ini_get('allow_url_fopen')) { $nextstage = ($goforward) ? 5 : 3; } else if (($fh = @fopen($INSTALL['wwwroot'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) { $nextstage = ($goforward) ? 5 : 3; fclose($fh); } else { if ($nextstage != 4) { $errormsg = get_string('admindirerror', 'install'); $nextstage = 4; } } } //==========================================================================// /// Display or print the data /// Put the data into a string /// Try to open config file for writing. if ($nextstage == 5) { $str = 'dbtype = \''.$INSTALL['dbtype']."';\r\n"; $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n"; if (!empty($INSTALL['dbname'])) { $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n"; $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n"; $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n"; } $str .= '$CFG->dbpersist = false;'."\r\n"; $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n"; $str .= "\r\n"; $str .= '$CFG->wwwroot = \''.$INSTALL['wwwroot']."';\r\n"; $str .= '$CFG->dirroot = \''.$INSTALL['dirroot']."';\r\n"; $str .= '$CFG->dataroot = \''.$INSTALL['dataroot']."';\r\n"; $str .= '$CFG->admin = \''.$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; } //==========================================================================// ?> Moodle Install

$errormsg

\n"; if ($nextstage == 5) { $INSTALL['stage'] = 0; $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"; print_object(htmlentities($str,ENT_COMPAT,$SESSION->encoding)); echo "
\n"; } } else { $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php"; form_table($nextstage, $formaction); } ?>
\n"; print_r($object); echo "\n"; } //==========================================================================// function form_table($nextstage = 0, $formaction = "install.php") { global $INSTALL; /// standard lines for all forms ?>

"mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?>

\n" : " \n" ?> 0) ? "\n" : " \n" ?>
\n"; echo "

$testtext

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

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

\n"; echo " \n"; } else { echo "".get_string('caution', 'install') : "

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

\n"; echo ""; echo "

$errormessage "; 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 get_memory_limit() { if ($limit = ini_get('memory_limit')) { return $limit; } else { return get_cfg_var('memory_limit'); } } //==========================================================================// function check_memory_limit() { /// if limit is already 16M or more then we don't care if we can change it or not if ((int)str_replace('M', '', get_memory_limit()) >= 16) { return true; } /// Otherwise, see if we can change it ourselves @ini_set('memory_limit', '16M'); return ((int)str_replace('M', '', get_memory_limit()) >= 16); } //==========================================================================// function css_styles() { ?>