<?php 

if($_POST[install])
{
	$url_i = str_replace("install","",getcwd());
	if($_POST['mysql_host'] && $_POST['mysql_username'] && $_POST['mysql_password'] && $_POST['database_name'] && $_POST['server_domain'] && $_POST['email'] && $_POST['password'] && $_POST['password'] && $_POST['last_name'] && $_POST['server_domain'] )
	{
    $config_file=file_get_contents($url_i."/install/config.php");
    $config_file=str_replace("@mysql_host@",$_POST['mysql_host'],$config_file);
	$config_file=str_replace("@root@",$url_i,$config_file);
    $config_file=str_replace("@mysql_username@",$_POST['mysql_username'],$config_file);
    $config_file=str_replace("@mysql_password@",$_POST['mysql_password'],$config_file);
    $config_file=str_replace("@database_name@",$_POST['database_name'],$config_file);
    $config_file=str_replace("@server_domain@",$_POST['server_domain'],$config_file);
    file_put_contents($url_i."/app_needed/config.php",$config_file);
    $command="mysql -h '".$_POST['mysql_host']."' -u '".$_POST['mysql_username']."' -p'".$_POST['mysql_password']."' '".$_POST['database_name']."' < '".'database.sql'."'";
    $output = shell_exec($command);
    sleep(5);
    $conn = @mysql_connect($_POST['mysql_host'],$_POST['mysql_username'],$_POST['mysql_password']);
    @mysql_select_db($_POST['database_name']) or die(mysql_error());
    require_once($url_i."/app_classes/module_users.inc");
    $unique=class_users::add('','1','1',$_POST['email'],$_POST['password'],$_POST['first_name'],$_POST['last_name'],'','','','','','','','','','','','1','1','1','1','');
	if(!$conn)
	{
		echo "Invalid Database Connection";
		exit();
	}
    $user=new class_users($unique);
	session_start();
	$_SESSION['unique'] = $unique;
    $user->set_valid("1");
    $user->set_verified("1");
   	$user->logout();
    $config_file=file_get_contents($url_i."/install/adb.php");
    $config_file=str_replace("@server_domain@",$_POST['server_domain'],$config_file);
    file_put_contents($url_i."/adb.php",$config_file);
    echo "The product is succesfully installed! <a href='../login.html'>Login Now</a>";

		
	}
	else echo "All fields are required to install the product.";
}
?>