<html>
<head>
<title>EZ Shopper Installation Utility</title>
<style type=text/css>
.bmenulink {
	FONT-WEIGHT: bold; COLOR: #000000; TEXT-DECORATION: none
}
.bmenulink A {
	COLOR: #000000; TEXT-DECORATION: none
}
.bmenulink A:hover {
	COLOR: #668CB7
}
</style>
<script language="JavaScript">
function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}
</script>
</head>
<BODY text=#000000 bgcolor = #FFFFFF leftMargin=0 topMargin=0 rightMargin=0 bottommargin=0>
<?php
/***************************************************************************
 *			installer.php                                      *
 *                     	          				           *
 *   File Info:		  EZ SHOPPER INSTALLER                             *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
***************************************************************************/
echo "<br><center><h2><font face = Verdana>------ EZ Shopper Installation ------</font></h2></center>";

if (empty($step))
	$step = "0";

$submit = "false";

############ echo current directory/folder ##############
$url = $_SERVER['HTTP_HOST'];
$dir_name = dirname($_SERVER['PHP_SELF']);
$current_url = "http://$url$dir_name";
$current_dir = getcwd();

if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $step = addslashes($_POST["step"]);  
        $choice = addslashes($_POST["choice"]); 
        $start = addslashes($_POST["start"]);      
        $server = addslashes($_POST["server"]);      
        $database = addslashes($_POST["database"]);  
        $user = addslashes($_POST["user"]);
        $password = addslashes($_POST["password"]);   
        $permiss = addslashes($_POST["permiss"]);      
        $nodelete = addslashes($_POST["nodelete"]);       
}

if (($step == 1 and $choice == "NO") or ($step == 2 and $choice == "NO"))
{
	echo "<br><center>You opted not to install EZ Shopper at this present time.<br>You can resume installation by running this installer script any time.";
	include_once("./footer.inc");
	exit();
}
if ($step == 2 and $choice == "YES")
	$submit = "test";
if ($step == 2 and $choice == "YES" and $start == "GO")
	$submit = "false";
############# displays help information before starting ################

// bypass folders checking if installing on windows platform //
if ($step == 1 && $permiss == "YES")
{
	$step = 2;
	$stops = "false";
	$submit = "test";
}
if ($step == 0)
{
	echo "<br><b>Notes to all users of EZ Shopper:-</b><br>";
	echo "<br><p align = justify>Installation of EZ Shopper will take 2 steps to complete. The first step is to verify that you have the necessary folders installed on your server. Next you must fill in the user password, database name and username for use of your SQL database. The second step is to copy all the files to your server. After the second step is complete. You will have successfully installed EZ Shopper onto your server.</p>";

echo "<p align = justify>Please refer to the user documentation on how to use EZ Shopper and how to customize it to your own needs. If you are installing on a windows platform; please answer 'YES'  otherwise please answer 'NO' for LInux/Unix platforms. If installing on a windows platform, you will bypass Step 1 for checking for folders permissions. If you are updating from previous version and wish to keep your existing database data. Please answer 'YES', otherwse answer 'NO' and all database data will be automatically erased.</p>";
echo "<br><center><b>Start Installation</b><form action = installer.php method = post><select name = choice><option value = 'YES' selected>-- Yes --</option><option value = 'NO'>-- No --</option><input type = hidden name = step value = '1'><input type = submit name = submit value = 'Start'>";
echo "<br><br><b>Installing on Windows platform</b><br><select name = permiss><option value = 'YES'>-- Yes --</option><option value = 'NO' selected>-- No --</option></select><br><br><b><font color=#CC0000>Upgrading from previous version, keep existing database data</b><br><select name = nodelete><option value='YES' selected>-- Yes --</option><option value = 'NO'>-- No --</option></select></font></form>";
echo "<br>"; include_once("./footer.inc");
}

################ step 1 check folders ##################

if ($step == 1)
{
	echo "<br><b>Begin checking your folders for correct permissions:-</b><br><br>";
$images_perms = fileperms("$current_dir/images");
$backup_perms = fileperms("$current_dir/backup");
$info_perms = fileperms("$current_dir/info");
$octalperms1 = sprintf("%o",$images_perms);
$perms1=(substr($octalperms1,2));
$octalperms2 = sprintf("%o",$backup_perms);
$perms2=(substr($octalperms2,2));
$octalperms3 = sprintf("%o",$info_perms);
$perms3=(substr($octalperms3,2));

if($perms1==755){
echo "$current_url/images/ file permission set to <font color=$color>chmod 755</font><br>";
$stop = "false";
}
if($perms1 !=755){
echo "<font color=$highlight>Please chmod folder $current_url/images/ to \"755\" manually before installation can resume! </font><br>";
$stop="true";
}
if($perms2 ==755){
echo "$current_url/backup/ file permission set to <font color=$color>chmod 755</font><br>";
$stop = "false";
}
if($perms2 !=755){
echo "<font color=$highlight>Please chmod folder $current_url/backup to \"755\" manually before installation can resume! </font><br>";
$stop="true";
}
if($perms3 ==755){
echo "$current_url/info/ file permission set to <font color=$color>chmod 755</font><br>";
$stop = "false";
}
if($perms3 !=755){
echo "<font color=$highlight>Please chmod folder $current_url/info/ to \"755\" manually before installation can resume! </font><br>";
$stop="true";
}
if($stop=="true")
{echo"<br><br><b>These folders should be chmod to the correct value before installation can continue!<br>Use your FTP software to change folders permissions</b><br>";
exit();
}

if ($stop == "false")
{
	$step = 2;
	echo "<br><b>STEP 1: Checking folder pernissions was succesful, continuing to STEP 2 NOW....</b><br>";
	echo "<br><center>Continue with installation<form action = installer.php method = post> <select name = choice><option value = 'YES' selected>--Yes --</option><option value = 'NO'>-- No --</option></select><input type = hidden name = step value = '2'><input type = submit name=submit value='Continue'></form></center><br>";
echo "<br>";include_once("./footer.inc");
}

}

###################### STEP 2 Get the user's password, database name, username ##########################

if ($step == 2)
{
	if ($submit == "test")
	{
		echo "<BR><b><u>STEP 2: Create your database for EZ Shopper</u></b><br><BR>
	<b><font color =$highlight>IMPORTANT: </FONT><font face = Verdana size = 3><b>IF YOU CONTINUE ANY PREVIOUS DATABASE DATA WILL BE LOST!</b><BR>";

	echo "<br><b>NOTES to all users:</b><br><p align = justify>You must input the server, username, user password and database name into the text boxes. Failure to do so, may hinder your progress in installing EZ Shopper. We recommend you carefully input the details as the password may be case sensitive and can be rejected if not correctly inputted. If your details are inputed correctly, a verification test is carried out before continuing to create your SQL database. If your details are incorrect, you are given the opportunity to rectify. If you wish to backup any data, please use the link to call the database backup utility. The backup files will be tab delimited files of the actual tables in the SQL database.</p>";

	 echo "<img src = ./images/private.gif><a href = javascript:newWindow('./backup.php','acePopup',600,500,'scrollbars=yes')>Backup database</a>";

	########## display the textboxes ############

	$form = "<form method=post action=installer.php>";
	$form.= "<table align=center width=400 cellspacing=0 border=1>";
	$form.="<tr><td colspan=2 bgcolor=#ccddff><b>Database Connection:<b></td></tr>";
	$form.="<tr><td width=150><b>Hostname: (default:localhost) </b></td><td width = 250><input type=text class=textbox name=server size=30 maxlength=35></td></tr>";
	$form.="<tr><td width=150><b>Database name: </b></td><td width = 250><input type=text class=textbox name=database size=30 maxlength=35></td></tr>";
	$form.="<tr><td width=150><b><font color = $color>Database username: </font></b></td><td width = 250><input type=text class=textbox name=user size=30 maxlength=35></td></tr>";
	$form.="<tr><td width=150><b><font color=$highlight>Database password: </font>(careful case sensitive) </b></td><td width=250><input type=password class=textbox name=password size=30 maxlength=35>";
	$form.="<input type=hidden name=step value='2'>";
	$form.="<input type=hidden name=start value='GO'>";
	$form.="<input type=hidden name=nodelete value=$nodelete>";
	$form.="<tr><td width=150>&nbsp;</td><td width=250>Continue installing<select name=choice><option value='YES' selected>-- Yes --</option><option value ='NO'>-- No --</option></select>";
	$form.="<input type=submit name=submit value='Continue'></form>";

	echo $form;
	}

	#################### proceed with installing ##################

	if ($start == "GO")
	{
		// display error message for null server field
		if ($server == NULL)
		{
			echo "<br><hr><li>Opps...Server field cannot be null...please reinput again !";
			echo "   Click to go back to <a href = javascript:history.back()>previous</a> Page<hr>";
			exit();	
		}
		// display error message for null database name field
		if ($database == NULL)
		{
			echo "<br><hr><li>Opps...Database name field cannot be null...please reinput again !";
			echo "   Click to go back to <a href = javascript:history.back()>previous</a> Page<hr>";
		exit();
		}
		// display error message for null user field
		if ($user == NULL)
		{
			echo "<br><hr><li>Opps...Username field cannot be null...please reinput again !";
			echo "   Click to go back to <a href = javascript:history.back()>previous</a> Page<hr>";
		exit();
		}	
	

		echo "<BR><b><u>STEP 2: Checking your database details !!!</u></b><br><BR>
	<b><font color =$highlight>IMPORTANT: </FONT><font face = Verdana size = 3><b>IF YOU CONTINUE ANY PREVIOUS DATABASE DATA WILL BE LOST!</b></font><BR>";

	##### test the database #####
	
	echo "<br><hr><center><h3><font face = Verdana size = 3 color = $backcolor1>Begin installation...please be patient!!!</font></center><br>";

	$conn = @mysql_connect($server,$user,$password)
		or die("Unable to connect to your MYSQL database on your server");	
	if(!@mysql_select_db($database,$conn))
	die("Unable to find the database <b>$database</b> on your MySQL server.");

	#### drop database and rebuild ####
	
	if ($nodelete == "YES")
	{
	echo "<center><img src =./images/private.gif><font color = $color>All SQL database data will not be deleted...</font></center><br>";
	echo "<font face = Verdana size =2><p align = jusitify>As a safety feature EZ Shopper installation will now be terminated. This is to preserve your existing database data from been accidentically erase automatically.</p><br><br>";
	include_once("./footer.inc");
	exit();
	}
	### delete table 0 ###
	$table = "products";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");
	
	### create table 0 ###
	@mysql_query ("CREATE TABLE $table (pid int, pitem char(50),pdes text,price double)");
	echo "<img src =./images/private.gif><font color = $color>Successfully created products table on your SQL database.</font><br>";

	### delete table 1 ###
	$table = "contacts";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 1 ###
	@mysql_query("CREATE TABLE $table (cid int,ctitle char(10),cfirst char(25),csurname char(30),cadd1 char(100),cadd2 char(100),ccity char(50),ccounty char(50),ccode char(15),cphone char(25),cfax char(25),cemail char(50))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created contacts table on your SQL 		database.</font><br>";

	### delete table 2 ###
	$table = "stocks";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");
	
	### create table 2 ###
	@mysql_query("CREATE TABLE $table (pid int,sitem char(50),scat char(50),spic char(100),stock int,color char(15),size char(25))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created stocks table on your SQL 		database.</font><br>";	

	### delete table 3 ###
	$table = "myorders";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");
	
	### create table 3 ###
	@mysql_query("CREATE TABLE $table (user_id char(32),sel_item char(50),sel_item_title text,sel_item_qty int,sel_item_price double,sel_item_totalprice double,date_added char(25))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created myorders table on your SQL 		database.</font><br>";

	### delete table 4 ###
	$table = "users";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 4 ###
	@mysql_query("CREATE TABLE $table (username char(25),firstname char(25),lastname char(25),passwrd char(32),email char(50),hint char(50),date_added char(25))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created users table on your SQL 		database.</font><br>";

	############ auto create administrator account ############

	$passwrd = md5("999");
	$date_added = date("Y-m-d");
	$sqls = "INSERT INTO $table (username,firstname,lastname,passwrd,email,hint,date_added) 	values('admin','The','Administrator','$passwrd','yourname@yourdomain.com','Dial number for police','$date_added')";
	$results=mysql_query($sqls,$conn)
		or die("Unable to excute the SQL query!!! Possibly SQL command already executed");
	echo "<img src =./images/private.gif><font color = $color>Successfully created administrator's account on your SQL 		database.</font><br>";

	### delete table 5 ###
	$table = "userlogs";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 5 ###
	@mysql_query("CREATE TABLE $table (sessid char(32),username char(25),timein char(32),timeout char(32),ip char(20),referer char(100),browser char(100),date_added char(30))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created userlogs table on your SQL 		database.</font><br>";

	### delete table 6 ###
	$table = "setting";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 6 ###
	$sql = "CREATE TABLE $table (setid char(6),mincost double,shipcost double,company char(100),cline1 char(100),cline2 char(100),cline3 char(100),cline4 char(20),sitecompany char(50),siteaddress char(150),sitetown char(50),sitecounty char(50),sitepostcode char(25),sitecountry char(50),sitetel char(50),siteemail char(75),footer char(150),color char(7),highlight char(7),backcolor char(7),backcolor1 char(7),online int,scurrency char(3),usecat char(3),wcurrency char(3),conv1 double,conv2 double,conv3 double,conv4 double,conv5 double,zone1 double,zone2 double,zone3 double,hits int,shiprates double)";
	$result=mysql_query($sql,$conn)
	or die("Unable to excute the SQL query!!! Possibly SQL command already executed");
	echo "<img src =./images/private.gif><font color = $color>Successfully created setting table on your SQL 		database.</font><br>";
	$sqls = "INSERT INTO $table (setid,mincost,shipcost,company,cline1,cline2,cline3,cline4,sitecompany,siteaddress,sitetown,sitecounty,sitepostcode,sitecountry,sitetel,siteemail,footer,color,highlight,backcolor,backcolor1,online,scurrency,usecat,wcurrency,conv1,conv2,conv3,conv4,conv5,zone1,zone2,zone3,hits,shiprates) values('admin','50','2.95','128 Concepts','PO BOX 11236','Kings Norton','Birmingham','B30 1YA','Your company','Your address1, Your address2, Your address 3','Your town','Your county','Your Zip or Post Code','Your Country','Tel:Your Telephone','email:yourname@yourdomain.com','128 Concepts Copyright 2002-2003 ©','#00CC00','#DD0000','#FFFFFF','#00CCFF',0,'gbp','NO','NO',0,0,0,0,0,0,0,0,0,0)";
	$results=mysql_query($sqls,$conn)
	or die("Unable to excute the SQL query!!! Possibly SQL command already executed");
	if ($results)
	echo "<img src =./images/private.gif><font color = $color>Successfully created setting record on your SQL 		database.</font><br>";

	### delete table 7 ###
	$table = "history";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 7 ###
	@mysql_query("CREATE TABLE $table (orderid char(50),username char(16),fullname char(75),email char(75),address1 char(100),address2 char(100),city char(50),postcode char(16),phone char(16),paytype char(32),stat char(25),total double,rtime char(32))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created history table on your SQL 		database.</font><br>";

	### delete table 8 ###
	$table = "custdet";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 8 ###
	@mysql_query("CREATE TABLE $table (orderid char(16),username char(50),qty int,product char(100),price double,totalprice double,currency char(3))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created custdet table on your SQL 		database.</font><br>";

	### delete table 9 ###
	$table = "rating";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 9 ###
	@mysql_query("CREATE TABLE $table (pid int,item char(50),rating int)");
		echo "<img src =./images/private.gif><font color = $color>Successfully created rating table on your SQL 		database.</font><br>";

	### delete table 10 ###
	$table = "category";
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 10 ###
	@mysql_query("CREATE TABLE $table (category char(40),catid int,cpic char(128))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created category table on your SQL 	database.</font><br>";

	### delete table 11 ###
	$table = "reviews";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 11 ###
	@mysql_query("CREATE TABLE $table (pid int,pitem char(50),rating char(10),title char(100),review text,dispname char(50),location char(50),date_added char(32))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created reviews table on your SQL 	database.</font><br>";

	### delete table 12 ###
	$table ="shipping";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 12 ###
	@mysql_query("CREATE TABLE $table (orderid char(16),status char(50),shipinfo char(32),datetime char(32),shiptype char(32),shiploct char(75),orderstat char(32))");
	echo "<img src =./images/private.gif><font color = $color>Successfully created shipping table on your SQL 	database.</font><br>";

	### delete table 13 ###
	$table = "shipopts";
	if ($nodelete == "NO")
	@mysql_query ("DROP TABLE IF EXISTS $table");

	### create table 13 ###
	@mysql_query("CREATE TABLE $table (shipitem char(100),shipitemprice double)");
	echo "<img src =./images/private.gif><font color = $color>Successfully created shipping options table on your SQL 	database.</font><br>";

	echo "<br><hr><center><font color = $color>EZ Shopper Installation successful...</font></center>";
	echo "<br><b>NOTE TO USERS:</b><br><p align = justify>The installation script installer.php should be removed from your server once the installation is complete. Failure to do so may render security risks to your database data.</p>";
	echo "<br>";
	include_once("./footer.inc");
	exit();
	}
	
}

?>

</body>
</html>