' . mysql_error();
} else {
// Specify UTF-8 use for connection
mysql_query("SET NAMES 'utf8'");
// Create DB?
if (isset($_POST['dboptions']) && ($_POST['dboptions'] == 'createNload')) {
$q = "CREATE DATABASE `" . $_POST['dbname'] . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci";
if (!mysql_query($q) && (mysql_errno() != 1007)) { // 1007=exists
$e = 'Unable to create database ' . safeHTMLstr($_POST['dbname']) . ". DB Error:
" . mysql_error() . " (" . mysql_errno() . ")";
}
}
if (empty($e)) {
// Check prefix
if (!empty($_POST['dbprefix']) && (!preg_match("/^[\w-]{0,40}$/",$_POST['dbprefix']))) {
$e = 'Invalid table prefix; use up to 40 letters, numbers, and the underscore.';
}
// Attempt to access DB
elseif (!mysql_select_db($_POST['dbname'])) {
$e = 'Unable to access database ' . safeHTMLstr($_POST['dbname']);
}
else { // Save db info
if (! $fp = fopen(OCC_LIB_DIR . 'config-sample.php', 'r')) {
err('Config template file (lib/config-sample.php) does not exist. Check that you have a full OpenConf distribution and click the Restart Install link above.', $hdr, $hdrfn, false);
}
if (!$optionFile = fread($fp, filesize(OCC_LIB_DIR . 'config-sample.php'))) {
fclose($fp);
err("Unable to read from config file", $hdr, $hdrfn, false);
}
fclose($fp);
replaceConstantValue('OCC_DB_USER', $_POST['dbuser'], $optionFile);
replaceConstantValue('OCC_DB_PASSWORD', $_POST['dbpw'], $optionFile);
replaceConstantValue('OCC_DB_HOST', $_POST['dbhost'], $optionFile);
replaceConstantValue('OCC_DB_NAME', $_POST['dbname'], $optionFile);
replaceConstantValue('OCC_DB_PREFIX', $_POST['dbprefix'], $optionFile);
if (! $fp = fopen(OCC_CONFIG_FILE,'w')) {
err('Config file (config.php) cannot be created or is not writeable. Try creating a blank config.php file manually and ensure file permissions allow config.php to be written to by the server; then click the Restart Install link above.', $hdr, $hdrfn, false);
}
if (!fwrite($fp, $optionFile)) {
fclose($fp);
err("Unable to write to config file", $hdr, $hdrfn, false);
}
fclose($fp);
// Load schema
if ($dbfile = file_get_contents(OCC_LIB_DIR . "DB.sql")) {
// create tables
if (preg_match_all("/(CREATE [^;]+);/", $dbfile, $matches)) {
foreach ($matches[1] as $m) {
// add table prefix
$m = preg_replace("/(CREATE TABLE `?)/", "$1" . slashQuote(stripslashes($_POST['dbprefix'])), $m);
if (!mysql_query($m)) {
$e = "Error on loading schema -- " . mysql_error() . ".
Database may need to be reset";
break;
}
}
} else {
err("No schema found in DB.sql file", $hdr, $hdrfn, false);
}
// insert data
if (empty($e) && preg_match_all("/(INSERT [^;]+);/", $dbfile, $matches)) {
foreach ($matches[1] as $m) {
// add table prefix
$m = preg_replace("/(INSERT INTO `?)/", "$1" . slashQuote(stripslashes($_POST['dbprefix'])), $m);
if (!mysql_query($m)) {
$e = "Error on loading schema -- " . mysql_error() . ".
Database may need to be reset";
break;
}
}
}
} else {
$e = 'Unable to load schema from DB.sql. Try loading it manually (see INSTALL instructions).';
}
if (empty($e)) {
mysql_close($dbtest);
header("Location: install-account.php");
exit;
}
}
}
mysql_close($dbtest);
}
$dbuser = varValue('dbuser', $_POST);
$dbname = varValue('dbname', $_POST);
$dbhost = varValue('dbhost', $_POST);
$dbprefix = varValue('dbprefix', $_POST);
} else {
$dbuser = (defined('OCC_DB_USER') ? OCC_DB_USER : '');
$dbname = (defined('OCC_DB_NAME') ? OCC_DB_NAME : '');
$dbhost = (defined('OCC_DB_HOST') ? OCC_DB_HOST : '');
$dbprefix = (defined('OCC_DB_PREFIX') ? OCC_DB_PREFIX : '');
}
printHeader($hdr,$hdrfn);
print '
Step 1 of 5: Enter Database Settings
'; if (!empty($e)) { print '' . $e . '
'; } print 'The above information is stored in config.php';
if (defined('OCC_DB_NAME') && (OCC_DB_NAME != '')) {
print '.
If you already configured config.php and loaded the schema, you may skip to the next step.';
}
print '