<?
if(isset($_SERVER['HTTPS'])) {
	$domainurl = 'https://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
} else {
	$domainurl = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
}
	
if($_REQUEST['filled']==1) {
	$server   = trim($_REQUEST['hostname']);
	$database = trim($_REQUEST['database']);
	$username = trim($_REQUEST['user']);
	$password = trim($_REQUEST['pass']);
	
	$mysqlConnection = @mysqli_connect($server, $username, $password);
	if (!$mysqlConnection)
	{
	  echo "Your Database Credentials Are Not Correct, We Could Not Connect.";
	  die();
	}
	else
	{
	mysqli_select_db($mysqlConnection,$database);
	  //echo "Database Connection: Success";
	  
	$output = 1;
	        
	        if($output==1 || $output==7) {  
	        			
			$path_to_file = getcwd().'/Preferences.php';
			$file_contents = file_get_contents($path_to_file);
			$file_contents = str_replace("DBUSERNAME",$_REQUEST['user'],$file_contents);
			$file_contents = str_replace("DBUSERPASSWORD",$_REQUEST['pass'],$file_contents);
			$file_contents = str_replace("DBNAME",$_REQUEST['database'],$file_contents);
			$file_contents = str_replace("HOSTNAME",$_REQUEST['hostname'],$file_contents);
			$file_contents = str_replace("SITETITLE",$_REQUEST['title'],$file_contents);
			$file_contents = str_replace("SITESLOGAN",$_REQUEST['slogan'],$file_contents);
			$file_contents = str_replace("DOMAINURL",$domainurl,$file_contents);
			file_put_contents($path_to_file,$file_contents);	
				
				$file_content = file('shorturl.sql');
				$query = "";
				foreach($file_content as $sql_line){
					if(trim($sql_line) != "" && strpos($sql_line, "--") === false){
						$query .= $sql_line;
						if (substr(rtrim($query), -1) == ';'){
							// echo $query;
							$result = mysqli_query($mysqlConnection,$query);
							$query = "";
						}
					}
				}
				
				
				
				
				
				

				
			} 
			
			echo '<center>Install Complete, Please Delete The install.php File NOW!</center>';
			die();
	}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Webinar System Installer</title>
<style type="text/css">
.auto-style1 {
	text-align: center;
}
.auto-style2 {
	font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
	font-size: 24px;
	width:50%
}
.auto-style3 {
	text-align: center;
	font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
	font-size: 24px;
	margin-bottom: 0px;
}
.auto-style4 {
	text-align: center;
	font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
	font-size: 24px;
	margin-bottom: 3px;
}
.auto-style5 {
	font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
	font-size: 24pt;
	width:50%
}
input {
	border-radius:10px;
	padding:8px;
}
</style>
</head>

<body style="background-color: #C0C0C0">

<p class="auto-style4">
<strong>

<p class="auto-style4" style="font-size:30px">
<strong>ShortURL Installation System</strong></p>
<p class="auto-style4">
<strong>Enter Your Database Credentials
</strong></p><form method="post">
	<div class="auto-style1">
<input name="hostname" type="text" class="auto-style2" placeholder="Enter Host Name"/><br class="auto-style2" />
<input name="database" type="text" class="auto-style2" placeholder="Enter Database Name"/><br class="auto-style2" />
<input name="user" type="text" class="auto-style2" placeholder="Enter Database User Name"/><br class="auto-style2" />
<input name="pass" type="text" class="auto-style2" placeholder="Enter Database User Password"/>
<input name="title" type="text" class="auto-style2" placeholder="Enter Site Title"/>
<input name="slogan" type="text" class="auto-style2" placeholder="Enter Site Slogan"/>
		<br />
		<br />
		<input name="Button1" type="submit" value="CHECK INFORMATION AND INSTALL" class="auto-style5" /></div>
	<input name="filled" type="hidden" value="1" />
</form>


</body>

</html>
