<?
//----------------------------------------------------------------------------
// DATE: 27/02/2001
// File config.php
// Utility : configure with ease the eaysite ditribution
//---------------------------------------------------------------------------
include "../include/class.FastTemplate.php";
//configuration variable, you normally don't have to modify them
$database_name = 'easysite';
$database_user = 'easysite';
$database_password = 'easysite';
//------------------------------------------------------------------------------
if (strcmp($DATABASE,'on') == 0 || strcmp($DATABASE,'true') == 0)
$DATABASE = "true";
else
$DATABASE = "false";
$next_step=0;
//determination of the next configuration step
if ($submited == 1)
{
//logo image storing
copy ($LOGO,$EASYSITE_BASE . '/images/logo.jpg');
$LOGO = 'logo.jpg';
//if the user wants to use a database
if (strcmp($DATABASE,"true") == 0)
$next_step=1;
else
$next_step=2;
}
elseif ($submited == 2)
{
include "../include/database_specific_config/connexion_$DATABASE_TYPE.inc";
$connection_id = connection('mysql','root',$ADMINISTRATOR_PASSWORD,$DATABASE_HOST);
//connection to database failed, we must display the database configuration page
if ($connection_id == 0)
{
$error = "database connection failed, pleased provide us with the correct
database type, host and database administrator password";
$next_step=1;
}
else
$next_step=2;
}
//---------------------------------------------------------------------------
$tpl = new FastTemplate("../installation/templates");
$tpl->define(
array
(
config1 => "configuration.html", //page 1
config2 => "configuration2.html", //page 2
config3 => "configuration3.html", //congratulation page
config => "config.tpl" //generated config file
)
);
//we display the database configuration page number1
if ($next_step == 0)
{
$tpl->assign(
array
(
EASYSITE_BASE => $DOCUMENT_ROOT
)
);
$tpl->parse(MAIN,"config1");
$tpl->FastPrint("MAIN");
}
$RELATIVE_PATH = ereg_replace($DOCUMENT_ROOT,"",$EASYSITE_BASE);
$RELATIVE_PATH = '/' . ereg_replace("^/{1,2}","",$RELATIVE_PATH);
//we display the database configuration page number2
if ($next_step == 1)
{
$tpl->assign(
array
(
WEBMASTER_EMAIL => $WEBMASTER_EMAIL,
ADRESS => $ADRESS,
URL => $URL,
PHONE => $PHONE,
EASYSITE_BASE => $EASYSITE_BASE,
DATABASE => $DATABASE,
LOGO => $LOGO,
RELATIVE_PATH => $RELATIVE_PATH
)
);
$tpl->parse(MAIN,"config2");
$tpl->FastPrint("MAIN");
}
//we write the configuration file
if ($next_step == 2)
{
$error = '';
// echo "DATABASE : $DATABASE<BR>";
if (strcmp($DATABASE,"true") == 0)
{
// include "../include/database_specific_config/connexion_$DATABASE_TYPE.inc";
//database creation
$sql = "CREATE DATABASE easysite";
if (mysql_create_db($database_name,$connection_id) == 0)
$error .= mysql_error($connection_id) . "<BR>";
//database user creation
$sql = "GRANT ALL PRIVILEGES ON $database_name.* TO
$database_user@$DATABASE_HOST IDENTIFIED BY '$database_password'
WITH GRANT OPTION";
if (requette('',$connection_id, $sql) == 0)
$error .= mysql_error($connection_id) . "<BR>";
//traffic information table creation
$sql = "CREATE TABLE hit (
redirect_status smallint(3),
http_user_agent varchar(255),
http_via varchar(255),
remote_host varchar(200),
redirect_url varchar(255),
server_protocol varchar(50),
request_method varchar(10),
query_string varchar(100),
date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
http_referer varchar(250)
)";
if (requette($database_name,$connection_id, $sql) == 0)
$error .= mysql_error($connection_id) . "<BR>";
}
if (strcmp($error,'') != 0)
$error .= "<BR> An error occured during the database initialisation
process. Please use the back button of your navigator to retry the precedent
step. <BR>
Important note: This database installation won't work without mysql<BR>";
//configuration file writing
$tpl->assign(
array
(
DOCUMENT_ROOT => $DOCUMENT_ROOT,
WEBMASTER_EMAIL => $WEBMASTER_EMAIL,
ADRESS => $ADRESS,
PHONE => $PHONE,
URL => $URL,
DATABASE_TYPE => $DATABASE_TYPE,
DATABASE_HOST => $DATABASE_HOST,
DATABASE_NAME => $database_name,
DATABASE_USER => $database_user,
DATABASE_USER_PASSWORD => $database_password,
EASYSITE_BASE => $EASYSITE_BASE,
LOGO => $LOGO,
RELATIVE_PATH => $RELATIVE_PATH
)
);
$tpl->parse(RESULT,"config");
$RESULT = $tpl->fetch("RESULT");
$dest_directory = "../temp";
$file = fopen("$dest_directory/config.inc","w");
fwrite($file,$RESULT);
fclose ($file);
$tpl->assign(
array
(
DOCUMENT_ROOT => $DOCUMENT_ROOT,
RELATIVE_PATH => $RELATIVE_PATH,
ERROR => $error
)
);
$tpl->parse(MAIN,"config3");
$tpl->FastPrint("MAIN");
}
?>