<?php
/* FIRESHOP: Advanced Content Market System                         */
/* ============================================                         */
/*                                                                      */
/* Copyright (c) 2012 by Mohamad Porhaji                                */
/* http://Firedesign.ir                                                   */
/*                                                                      */
/* This program is free software.  */
/************************************************************************/
/* $Id: index.php,v 1.0.0.1 2012/02/18 By Mohamad Porhaji $ */
@session_start();
error_reporting(E_ALL & ~E_NOTICE);

if(isset($_GET['step'])){
$step = $_GET['step'];
switch ($step){
case '1':


include("template/step1.html");


break;
case '2':


if(isset($_POST['SEND_STEP2'])){

include("includes/functions.php");

if(empty($_POST['DB_SERVER'])
or empty($_POST['DB_NAME'])
or empty($_POST['DB_USERNAME'])
or empty($_POST['DB_PASSWORD']))
{
echo"پر كردن تمامي فيلد ها اجباري است";
}else
{

    $DB_SERVER = $_POST['DB_SERVER'];
    $DB_DATABASE = $_POST['DB_NAME'];
    $DB_SERVER_USERNAME = $_POST['DB_USERNAME'];
    $DB_SERVER_PASSWORD = $_POST['DB_PASSWORD'];
    $DB_TYPE = MySQL;
    

if (!$connection = @mysql_connect($DB_SERVER, $DB_SERVER_USERNAME, $DB_SERVER_PASSWORD)) 
{

echo"سيستم به بانك اطلاعاتي متصل نشد.لطفا از صحت اطلاعات وارد شده مطمئن شويد";
}else
{

if (!@mysql_select_db($DB_DATABASE,$connection)) {echo"چنين بانك اطلاعاتي وجود ندارد";}else
{

$_SESSION['db_host']     = $DB_SERVER;
$_SESSION['db_user']     = $DB_SERVER_USERNAME;
$_SESSION['db_password'] = $DB_SERVER_PASSWORD;
$_SESSION['db_name']     = $DB_DATABASE;


$file = dirname(__FILE__) . '/fireshop.sql';
if ($sql = file($file)) 
{
$query = '';
foreach($sql as $line) 
{
$tsl = trim($line);						
if (($sql != '') && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != '#')) 
{     	
$query .= $line;if (preg_match('/;\s*$/', $line)) {$result = mysql_query($query, $connection);
if (!$result) 
{
die(mysql_error());
}
$query = '';
}
}
}	
mysql_close($connection);

} else 
{
echo"فايل بانك اطلاعاتي وجود ندارد";
}		







$config = realpath(dirname(__FILE__) . '/../config.php');

if (is_writable($config)) {

				$output  = '<?php
' . "\n";
				$output .= '/* FIRESHOP: Advanced Content Market System                         */
' . "\n";
				$output .= '/* ============================================                         */
' . "\n";
				$output .= '/*                                                                      */
' . "\n";
				$output .= '/* Copyright (c) 2012 by Mohamad Porhaji                                */
' . "\n";
				$output .= '/* http://Firedesign.ir                                                   */
' . "\n";
				$output .= '/*                                                                      */
' . "\n";
				$output .= '/* This program is free software.  */
' . "\n";
				$output .= '/************************************************************************/
' . "\n";
				$output .= '/* $Id: config.php,v 1.0.0.1 2012/02/18 By Mohamad Porhaji $ */
' . "\n";

				$output .= 'if (stristr(htmlentities($_SERVER["PHP_SELF"]), "config.php")) {
    Header("Location: index.php");
    die();
}
'."\n";
				
				$output .= '// DB
' . "\n";
				$output .=  '$dbtype = "MySQL";
' . "\n";
				$output .= '$dbhost = "' . $_SESSION['db_host'] . '";
' . "\n";
				$output .= '$dbuname = "' . $_SESSION['db_user'] . '";
' . "\n";
				$output .= '$dbpass = "' . $_SESSION['db_password'] . '";
' . "\n";
				$output .= '$dbname = "' . $_SESSION['db_name'] . '";
' . "\n";

				$output .= '//***************************************************************
'."\n";
				$output .= '// IF YOU WANT TO LEGALY REMOVE ANY COPYRIGHT NOTICES PLAY FAIR AND CHECK: http://firedesign.ir
'."\n";
				$output .= '//***************************************************************
'."\n";
				$output .= '$commercial_license = 0;
'."\n";


				$output .= '?>';

				$file = fopen($config, 'w');
				
				fwrite($file, $output);
		
    			fclose($file);
			} else {

echo"<span dir='rtl'>خطا فايل config.php قابل نوشتن نيست لطفا مطمئن شويد حق دسترسي به اين فايل برابر 777 است يا اين دسترسي را به 777 تغيير دهيد</span>";
}

include("template/step1_ok.html");


}
}

}
}

break;
case '3':


if(isset($_POST['SEND_STEP3'])){
include("includes/functions.php");

if(empty($_POST['ADMIN_USER'])
or empty($_POST['ADMIN_PASS'])
or empty($_POST['ADMIN_EMAIL']))
{
echo"پر كردن تمامي فيلد ها اجباري است";
}else
{

    $ADMIN_USER = $_POST['ADMIN_USER'];
    $ADMIN_PASS = $_POST['ADMIN_PASS'];
    $ADMIN_EMAIL = $_POST['ADMIN_EMAIL'];


if (!$connection = @mysql_connect($_SESSION['db_host'], $_SESSION['db_user'], $_SESSION['db_password'])) {
echo"سيستم به بانك اطلاعاتي متصل نشد.لطفا از صحت اطلاعات وارد شده مطمئن شويد";
} else {
if (!@mysql_select_db($_SESSION['db_name'], $connection)) {
echo"چنين بانك اطلاعاتي وجود ندارد";
}

}

mysql_query("SET CHARATER SET utf8", $connection);
				
mysql_query("SET @@session.sql_mode = 'MYSQL40'", $connection);

mysql_query("DELETE FROM  fireshop_admin WHERE id = '1'");
$num_admin="1";
$sql_admin=mysql_query("INSERT INTO `fireshop_admin` SET id = '" . $num_admin . "',username = '" . $ADMIN_USER . "', password = '" . $ADMIN_PASS . "', email ='" . $ADMIN_EMAIL . "'", $connection);

if($sql_admin){include("template/step2_ok.html");}else{echo"يك مشكل در ايجاد شناسه براي مدير فروشگاه به وجود آمده است";}

}
}else{

include("template/step2.html");
}



break;
case '4':

include("template/step3.html");



break;
}
}else{

include("template/home.html");


}
?>