Use Persistent Connection:';
$line .= ' ');
send(" ");
send(' ');
send(' ');
send(' ');
send('');
} elseif (isset($_REQUEST["14"])) { // 14 - Database - creation + test
$type = $_REQUEST["db_type"];
sendHead(" - Database");
send(""._TITLE." ");
send("Database - Creation + Test - ".$type." ");
$paramsOk = true;
if (isset($_REQUEST["db_host"]))
$host = $_REQUEST["db_host"];
else
$paramsOk = false;
if (isset($_REQUEST["db_create"]))
$create = true;
else
$create = false;
if (isset($_REQUEST["db_pcon"]))
$pcon = "true";
else
$pcon = "false";
switch (strtolower($type)) {
case "sqlite":
$name = "";
$user = "";
$pass = "";
break;
case "mysql":
case "postgres":
default:
if (!empty($_REQUEST["db_name"]))
$name = stripslashes($_REQUEST["db_name"]);
else
$paramsOk = false;
if (!empty($_REQUEST["db_user"]))
$user = $_REQUEST["db_user"];
else
$paramsOk = false;
if (!empty($_REQUEST["db_pass"]))
$pass = $_REQUEST["db_pass"];
else
$paramsOk = false;
}
$databaseTestOk = false;
$databaseError = "";
// create + test
if ($paramsOk) {
send("The installation will now try to connect to the database server, create a new database if applicable and run some tests to check we can create tables in the database.
");
$databaseExists = true;
if (($create) && (strtolower($type) != "sqlite")) {
$dbCon = getAdoConnection($type, $host, $user, $pass);
if (!$dbCon) {
$databaseExists = false;
$databaseTestOk = false;
$databaseError = "Cannot connect to database. Check username, hostname and password?";
} else {
$sqlState = "CREATE DATABASE ";
if ($type == "mysql")
$sqlState .= "`".$name."`";
else
$sqlState .= $name;
$dbCon->Execute($sqlState);
send('');
if ($dbCon->ErrorNo() == 0) {
send('Ok: Created database '.$name.' ');
$databaseExists = true;
} else { // damn there was an error
send('Error: Could not create database '.$name.' ');
$databaseExists = false;
$databaseTestOk = false;
$databaseError = "Check the database $name does not exist already to perform this step.";
}
send(' ');
// close ado-connection
$dbCon->Close();
}
unset($dbCon);
}
if ($databaseExists) {
$dbCon = getAdoConnection($type, $host, $user, $pass, $name);
if (!$dbCon) {
$databaseTestOk = false;
$databaseError = "Cannot connect to database to perform query tests.";
} else {
$databaseTestCount = 0;
send('');
foreach ($queries['test'][strtolower($type)] as $databaseTypeName => $databaseQuery) {
send(' ');
$dbCon->Execute($databaseQuery);
if ($dbCon->ErrorNo() == 0) {
send('Query Ok: '.$databaseQuery);
$databaseTestCount++;
} else { // damn there was an error
send('Query Error: '.$databaseQuery);
// close ado-connection
$dbCon->Close();
break;
}
}
if ($databaseTestCount == count($queries['test'][strtolower($type)])) {
// close ado-connection
$dbCon->Close();
$databaseTestOk = true;
} else {
$databaseTestOk = false;
}
send(' ');
}
}
} else {
$databaseTestOk = false;
$databaseError = "Problem found in configuration details supplied - please supply hostname, database name, username and password to continue.";
}
// output
if ($databaseTestOk) {
$msg = "Database creation and tests succeeded";
displaySetupMessage($msg, true);
send(" ");
send("Next: Write Database Configuration File ");
send("Please ensure this script can write to the directory "._DIR."inc/config/ before continuing.");
send('
');
} elseif (isset($_REQUEST["15"])) { // 15 - Database - config-file
sendHead(" - Database");
send(""._TITLE." ");
send("Database - Config-File ");
send("The installation will now attempt to write the database configuration file to "._DIR._FILE_DBCONF.".
");
$type = $_REQUEST["db_type"];
$host = $_REQUEST["db_host"];
$name = $_REQUEST["db_name"];
$user = $_REQUEST["db_user"];
$pass = $_REQUEST["db_pass"];
$pcon = $_REQUEST["db_pcon"];
// write file
$databaseConfWriteOk = false;
$databaseConfWriteError = "";
$databaseConfContent = "";
writeDatabaseConfig($type, $host, $user, $pass, $name, $pcon);
// output
if ($databaseConfWriteOk) {
$msg = 'Database configuration file '._DIR._FILE_DBCONF.' written.';
displaySetupMessage($msg, true);
} else {
displaySetupMessage($databaseConfWriteError, false);
send(" ");
send('To perform this step manually please paste the following content to the database configuration file '._DIR._FILE_DBCONF.' and ensure the file is readable by the user the webserver runs as:
');
send('');
send("Note: You must write this file before you can continue!
");
}
send(" ");
send("Next : Create Tables ");
sendButton(16);
} elseif (isset($_REQUEST["16"])) { // 16 - Database - table-creation
sendHead(" - Database");
send(""._TITLE." ");
send("Database - Create Tables ");
send("The installation will now attempt to create the database tables required for running "._NAME.".
");
if (is_file(_FILE_DBCONF)) {
require_once(_FILE_DBCONF);
$databaseTableCreationCount = 0;
$databaseTableCreation = false;
$databaseError = "";
$dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
if (!$dbCon) {
$databaseTableCreation = false;
$databaseError = "Cannot connect to database.";
} else {
send('');
foreach ($queries['create'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) {
send(' ');
$dbCon->Execute($databaseQuery);
if ($dbCon->ErrorNo() == 0) {
send('Query Ok: '.$databaseQuery.' ');
$databaseTableCreationCount++;
} else { // damn there was an error
send('Query Error: '.$databaseQuery.' ');
$databaseError = "Could not create tables. Note that the database must be empty to perform this step.";
// close ado-connection
$dbCon->Close();
break;
}
}
if ($databaseTableCreationCount == count($queries['create'][$cfg["db_type"]])) {
// close ado-connection
$dbCon->Close();
$databaseTableCreation = true;
} else {
$databaseTableCreation = false;
}
send(' ');
}
if ($databaseTableCreation) {
$msg = $databaseTableCreationCount.' tables created';
displaySetupMessage($msg, true);
send(" ");
send("Next: Insert Data Into Database ");
sendButton(17);
} else {
displaySetupMessage($databaseError, false);
}
} else {
displaySetupMessage($msgDbConfigMissing, false);
}
} elseif (isset($_REQUEST["17"])) { // 17 - Database - data
sendHead(" - Database");
send(""._TITLE." ");
send("Database - Insert Data Into Database ");
send("The installation will now attempt to insert all the data required for the system into the database.
");
if (is_file(_FILE_DBCONF)) {
require_once(_FILE_DBCONF);
$databaseDataCount = 0;
$databaseData = false;
$databaseError = "";
$dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
if (!$dbCon) {
$databaseData = false;
$databaseError = "cannot connect to database.";
} else {
send('');
foreach ($queries['data'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) {
send(' ');
$dbCon->Execute($databaseQuery);
if ($dbCon->ErrorNo() == 0) {
send('Query Ok: '.$databaseQuery);
$databaseDataCount++;
} else { // damn there was an error
send('Query Error: '.$databaseQuery);
$databaseError = "Could not import data into database. Database tables must be empty before performing this step.";
// close ado-connection
$dbCon->Close();
break;
}
}
if ($databaseDataCount == count($queries['data'][$cfg["db_type"]])) {
// close ado-connection
$dbCon->Close();
$databaseData = true;
} else {
$databaseData = false;
}
send(' ');
}
if ($databaseData) {
$msg = $databaseDataCount.' queries executed.';
displaySetupMessage($msg, true);
send(" ");
send("Next: Server Configuration ");
sendButton(2);
} else {
displaySetupMessage($databaseError, false);
}
} else {
displaySetupMessage($err, false);
}
} elseif (isset($_REQUEST["2"])) { // 2 - Configuration
sendHead(" - Configuration");
send(""._TITLE." ");
send("Server Configuration ");
send("The installation will now continue to prompt you for some basic settings required to get "._NAME." running.
");
send(" ");
send("Next : Server Settings ");
sendButton(21);
} elseif (isset($_REQUEST["21"])) { // 21 - Configuration - Server Settings input
sendHead(" - Configuration");
send(""._TITLE." ");
send("Configuration - Server Settings ");
if (is_file(_FILE_DBCONF)) {
require_once(_FILE_DBCONF);
$dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
if (!$dbCon) {
$err = "cannot connect to database.";
} else {
$tf_settings = loadSettings("tf_settings");
// close ado-connection
$dbCon->Close();
if ($tf_settings !== false) {
send("Please enter the path to the directory you want "._NAME." to save your user downloads into below.
");
send("Important: this path must be writable by the webserver user
");
send('