<?php
require_once "config/config.php";
if($_POST)
{
$db_name=addslashes(trim($_POST['db_name']));
$db_username=addslashes(trim($_POST['db_username']));
$db_password=addslashes(trim($_POST['db_password']));
$db_hostaddress=addslashes(trim($_POST['db_hostaddress']));
$table_prefix=addslashes(trim($_POST['table_prefix']));
$session_prefix=addslashes(trim($_POST['session_prefix']));
$table_field_prefix=addslashes(trim($_POST['table_field_prefix']));
$cookie_prefix=addslashes(trim($_POST['cookie_prefix']));
$myFile = CONFIG_DIR_INSTALLATION."/db.php";
if(!is_writable($myFile))
{
$message="Please apply read/write permission /config/db.php";
$smarty_installation->assign('msg',$message);
$smarty_installation->assign('db_name',$_POST['db_name']);
$smarty_installation->assign('db_username',$_POST['db_username']);
$smarty_installation->assign('db_hostaddress',$_POST['db_hostaddress']);
$smarty_installation->assign('table_prefix',$_POST['table_prefix']);
$smarty_installation->assign('session_prefix',$_POST['session_prefix']);
$smarty_installation->assign('table_field_prefix',$_POST['table_field_prefix']);
$smarty_installation->assign('cookie_prefix',$_POST['cookie_prefix']);
$smarty_installation->display('installation_db_session_setting.tpl');
exit();
}
$file = PHYSICAL_DIR_INSTALLATION."installation/database/membersite_db_setup.sql";
if(!is_readable($file))
{
$message="Please apply read permission to /installation/database/membersite_db_setup.sql";
$smarty_installation->assign('msg',$message);
$smarty_installation->assign('db_name',$_POST['db_name']);
$smarty_installation->assign('db_username',$_POST['db_username']);
$smarty_installation->assign('db_hostaddress',$_POST['db_hostaddress']);
$smarty_installation->assign('table_prefix',$_POST['table_prefix']);
$smarty_installation->assign('session_prefix',$_POST['session_prefix']);
$smarty_installation->assign('table_field_prefix',$_POST['table_field_prefix']);
$smarty_installation->assign('cookie_prefix',$_POST['cookie_prefix']);
$smarty_installation->display('installation_db_session_setting.tpl');
exit();
}
else
{
$file_contents = file_get_contents($file);
$file_contents = str_replace("prefix_",stripcslashes($table_prefix),$file_contents);
if(!($db = @mysql_connect(stripcslashes($db_hostaddress), stripcslashes($db_username), stripcslashes($db_password))))
{
$smarty_installation->assign('msg','Could not connect to the database.<br>Check your database username password and database host address');
$smarty_installation->assign('db_name',$_POST['db_name']);
$smarty_installation->assign('db_username',$_POST['db_username']);
$smarty_installation->assign('db_hostaddress',$_POST['db_hostaddress']);
$smarty_installation->assign('table_prefix',$_POST['table_prefix']);
$smarty_installation->assign('session_prefix',$_POST['session_prefix']);
$smarty_installation->assign('table_field_prefix',$_POST['table_field_prefix']);
$smarty_installation->assign('cookie_prefix',$_POST['cookie_prefix']);
$smarty_installation->display('installation_db_session_setting.tpl');
exit();
}
else
{
$linkid = mysql_connect($_POST['db_hostaddress'],$_POST['db_username'],$_POST['db_password']);
$db_selct=mysql_select_db(stripcslashes($db_name), $linkid);
if($db_selct)
{
$templine = '';
// Read in entire file
$lines = explode("\n", $file_contents);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
// Perform the query
mysql_query($templine,$linkid) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
// Reset temp variable to empty
$templine = '';
}
}
$fh = fopen($myFile, 'w') or die("can't open file "."<b>$myFile</b><br/>Please apply read/write permission /config/db.php.");
$stringData = "<?php \r\n";
$stringData .= "DEFINE('TABLE_PREFIX',stripslashes('$table_prefix')); \r\n";
$stringData .= "DEFINE('SESSION_PREFIX',stripslashes('$session_prefix')); \r\n";
$stringData .= "DEFINE('TABLE_FIELD_PREFIX',stripslashes('$table_field_prefix')); \r\n";
$stringData .= "DEFINE('TABLE_BANLIST',TABLE_PREFIX.'banlist'); \r\n";
$stringData .= "DEFINE('COOKIE_PREFIX',stripslashes('$cookie_prefix')); \r\n";
$stringData .= "DEFINE('MEMBERSGEAR_DB_NAME',stripslashes('$db_name')); \r\n";
$stringData .= "DEFINE('MEMBERSGEAR_DB_USER',stripslashes('$db_username')); \r\n";
$stringData .= "DEFINE('MEMBERSGEAR_DB_PASSWORD',stripslashes('$db_password')); \r\n";
$stringData .= "DEFINE('MEMBERSGEAR_DB_HOST',stripslashes('$db_hostaddress')); \r\n";
$stringData .= "DEFINE('MEMBERSGEAR_DB_TYPE','mysql'); \r\n";
$stringData .= "\$dsn['username']=MEMBERSGEAR_DB_USER; \r\n";
$stringData .= "\$dsn['password'] =MEMBERSGEAR_DB_PASSWORD; \r\n";
$stringData .= "\$dsn['hostspec'] =MEMBERSGEAR_DB_HOST; \r\n";
$stringData .= "\$dsn['phptype'] =MEMBERSGEAR_DB_TYPE; \r\n";
$stringData .= "?>";
fwrite($fh, trim($stringData));
fclose($fh);
$_SESSION['DATABASE_INSTALLATION']='done';
redirect('next_step.php');
}
else
{
$smarty_installation->assign('msg','could not find the given databse on server.Please check the database name.');
$smarty_installation->assign('db_name',$_POST['db_name']);
$smarty_installation->assign('db_username',$_POST['db_username']);
$smarty_installation->assign('db_hostaddress',$_POST['db_hostaddress']);
$smarty_installation->assign('table_prefix',$_POST['table_prefix']);
$smarty_installation->assign('session_prefix',$_POST['session_prefix']);
$smarty_installation->assign('table_field_prefix',$_POST['table_field_prefix']);
$smarty_installation->assign('cookie_prefix',$_POST['cookie_prefix']);
$smarty_installation->display('installation_db_session_setting.tpl');
exit();
}
}
}
}
else
{
$smarty_installation->assign('table_prefix','membersgear_table_');
$smarty_installation->assign('session_prefix','membersgear_session_');
$smarty_installation->assign('table_field_prefix','membersgear_field_');
$smarty_installation->assign('cookie_prefix','membersgear_cookie_');
$smarty_installation->display('installation_db_session_setting.tpl');
}
?>