<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
<HTML>
<HEAD>
<TITLE>Empty Shopping Cart Contents</TITLE>
</HEAD>
<BODY>
<?
/***************************************************************************
 *			shop_deletecarts.php                               *
 *                     	          				           *
 *   File Info:		  Delete cart                                      *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include ("./config.php");
include ("./tests.php");

######################### if first time...url will contain PHPSESSID=xxxx  #############################
######################### code below will refresh page to remove PHPSESSID #############################

$strvar = getenv("QUERY_STRING");
$pos = strpos($strvar,'=');
session_start();
$PHPSESSID = session_id();
$exit = "false";
$strs = substr($strvar,0,$pos);
if ($pos > 0 && $empty == NULL)
{
	include_once("./your-header.inc");
	echo "<table width=450 border=1 cellspacing=0 cellpadding=0 height=150>
<tr><td width=450 bgcolor=#CCCCCC height=10>EZ Shopper Information</td></tr>
<tr><td width=450 bgcolor=#FFFFFF height=140>";
	echo "<b><br><center>Please be patient as we now re-directing you to main store page...<br>You will only see this message once i.e every time you start a new browser window.</center></b><br></td></tr></table>";
	include_once("./redirect-me.php");
}
else {
if ($phpcart == "NO"){
if ($usecat =="YES")
	include_once("./sidebars.php");
else
	include_once("./sidebar.php");}

$prods = array();
$quant = array();
$indexs = getenv("QUERY_STRING"); 
$pos = strpos($indexs,"&");
if ($pos > 0)
{
	$index = substr($indexs,0,$pos);
}
else
{
	$index = 	getenv("QUERY_STRING"); 
}
$table= "myorders";
$sel_item_totalprice = $sel_item_qty * $sel_item_price;
$conn = @mysql_connect($server,$user,$password)
	or die("Unable to connect to SQL database...");
$rs = @mysql_select_db($database,$conn) 
	or die("Unable to select the database 'mydata'...Please press 'Create Database' to create new database.");

// Generate list for delete SQL command
$get_cart ="SELECT SEL_ITEM, SEL_ITEM_TITLE, SEL_ITEM_QTY, SEL_ITEM_PRICE, 
		SEL_ITEM_TOTALPRICE FROM $table where user_id =  '$PHPSESSID'";
$cart_result = mysql_query($get_cart)
	or die("SQL command failed - Couldn't get cart.");

$nitems = mysql_num_rows($cart_result);
if ($nitems == 0)
{
	// check if any items in stock table //

	$sql1 = "SELECT * from $table";
	$rs = @mysql_query($sql1,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
	$nums = mysql_num_rows($cart_result);

	if ($nums >= 1)
	{

		$table = "products";
		$sql = "SELECT * from $table";
		$products = mysql_query($sql,$conn);
		$prods = mysql_num_rows($products);

		$items = array();
		$count = 1;

	// only show items when there are items to show !!!
	if ($prods >= 1)
	{
		while ($row = mysql_fetch_array($products))
		{
	
			$items[$count] = $row["pid"];
			$count += 1;
		}
		srand(microtime() * 1000000);
		$num = rand(1,$prods);
		if ($num == 0) $num = 1;
		$sqls = "SELECT * from $table where pid = $items[$num]";
		$details = mysql_query($sqls,$conn);

		while ($rows = mysql_fetch_array($details))
		{
			$pid = $rows["pid"];
			$pitem = $rows["pitem"];
			$pdes = $rows["pdes"];
		}
		$table = "stocks";
		$sql = " SELECT pid,sitem,scat,spic,stock,color,size from $table where pid=$items[$num]";
		$rs = @mysql_query($sql,$conn)
		or die("Could not execute SQL query!!! Possibly SQL query already been executed.");

		$row=mysql_fetch_array($rs);
		$pics = $row["spic"];
		$scat=$row["scat"];
		$stocknum = $row["stock"];
	}
	}
	else
	{
		$pitem = "N/A";
		$pdes = "N/A";
		$scat = "N/A";
	}
	if (strlen($pics) < 1)
	{	
		$pics="./images/nopic.jpg";
	}
	if (fopen($pics,"r") == NULL)
		$pics = "./images/nopic.jpg";
	if (strlen($scat) < 1)
	{
		$scat = "N/A";
	}
	echo "<center><TABLE cellSpacing=0 cellPadding=0 border=0><TR>
      <TD background=./images/border_cnr_tl.gif><IMG height=8 alt= src=./images/px.gif width=8 border=0></TD>
      <TD background=./images/border_top.gif><IMG height=8 alt= src=./images/px.gif width=120 border=0></TD>
      <TD background=./images/border_cnr_tr.gif><IMG height=8 alt= src=./images/px.gif width=8          border=0></TD></TR><TR><TD background=./images/border_left.gif>
       <IMG height=60 alt= src=./images/px.gif width=8 border=0></TD>
       <TD width=120>
       <TABLE cellSpacing=0 cellPadding=4 width=480 border=0>
       <TBODY>
       <TR>
       <TD align=center><img src=images/cart-contents.gif border=0><img src=images/shoppingcart.gif width = 22 height = 22 align=middle><font face=verdana size=1 color=#00CCCC> No Items in Basket</font></td></tr>
<tr><td align=center><font face=verdana size=1 color=navy>We recommend the following product item</font></td></tr>";
echo "<tr><td align=center><img src=$pics border=0 alt=Picture></td></tr>";
echo "<tr><td><font face=verdana size=1><b>Product Item ID:</b>	$pid <a href = ./shop_showitem.php?pid=$pid></font><font color = $highlight><u>Show Item</u></font></a>";
echo "</td></tr><tr><td><font face=verdana size=1><b>Product Item   :</b>    $pitem</font>";
echo "</td></tr><tr><td><font face=verdana size=1><b>Product Description:</b> $pdes</font></td></tr>";
echo "<tr><td><font face=verdana size=1><b>Product Category:</b> $scat</font></td></tr>";
if ($stocknum >=1)
echo "<tr><td><font face=verdana size=1><b>Stock: </b> $stocknum</td></tr>";
if ($stocknum < 1)
echo "<tr><td><font face=verdana size=1><b>Stock: </b> <font face=verdana size=1 color=red>Out of Stock!</font></td></tr>";
echo "</TBODY></TABLE></TD><TD background=./images/border_right.gif>
      <IMG height=60 alt= src=./images/px.gif width=8 border=0></TD></TR>
      <TR><TD background=./images/border_cnr_bl.gif>
      <IMG height=8 alt= src=./images/px.gif width=8 border=0></TD>
      <TD background=./images/border_bottom.gif>
      <IMG height=8 alt= src=./images/px.gif width=121 border=0></TD>
      <TD background=./images/border_cnr_br.gif>
      <IMG height=8 alt= src=./images/px.gif 
      width=8 border=0></TD></TR></TABLE></center><br><br>";
	$exit = "true";
}
if ($exit == "false"){
while ($row = mysql_fetch_array($cart_result)) {
	$a += 1;
	$sel_item_qty = $row["SEL_ITEM_QTY"];
	$sel_item = $row["SEL_ITEM"];	
	$sel_item_title = $row["SEL_ITEM_TITLE"];
	$sel_item_price = $row["SEL_ITEM_PRICE"];
	$sel_item_totalprice = $row["SEL_ITEM_TOTALPRICE"];
	$fmt_item_totalprice = sprintf("%0.2f",$sel_item_totalprice);
	$prods[$a] = $sel_item;
	$quant[$a] = $sel_item_qty;
}
$sql = "DELETE from $table where user_id = '$PHPSESSID' and sel_item = '$prods[$index]' and sel_item_qty = $quant[$index] LIMIT 1";

$deleted = $prods[$index];

$cart_result = mysql_query($sql)
	or die("SQL command failed - Couldn't empty single cart item.");
?>

<?
	$table = "products";
	$sql = "SELECT * from $table";
	$products = mysql_query($sql,$conn);
	$prods = mysql_num_rows($products);

	$items = array();
	$count = 1;
	
	// Only show recommended item if one exists !!

	if ($prods >= 1)
	{
		while ($row = mysql_fetch_array($products))
		{
	
			$items[$count] = $row["pid"];
			$count += 1;
		}
		srand(microtime() * 1000000);
		$num = rand(1,$prods);
		if ($num == 0) $num = 1;
		$sqls = "SELECT * from $table where pid = $items[$num]";
		$details = mysql_query($sqls,$conn);

		while ($rows = mysql_fetch_array($details))
		{
			$pid = $rows["pid"];
			$pitem = $rows["pitem"];
			$pdes = $rows["pdes"];
		}
		$table = "stocks";
		$sql = " SELECT pid,sitem,scat,spic,stock,color,size from $table where pid=$pid";
		$rs = @mysql_query($sql,$conn)
		or die("Could not execute SQL query!!! Possibly SQL query already been executed.");

		$row=mysql_fetch_array($rs);
		$pics = $row["spic"];
		$scat=$row["scat"];
		$stocknum = $row["stock"];
	}
	else
	{
		$pitem = "N/A";
		$pdes = "N/A";
		$scat = "N/A";
	}
	if (strlen($pics) < 1)
	{	
		$pics="./images/nopic.jpg";
	}
	if (fopen($pics,"r") == NULL)
		$pics = "./images/nopic.jpg";
	if (strlen($scat) < 1)
	{
		$scat = "N/A";
	}
	if ($prods >= 1)
	echo "<center><TABLE cellSpacing=0 cellPadding=0 border=0><TR>
      <TD background=./images/border_cnr_tl.gif><IMG height=8 alt= src=./images/px.gif width=8 border=0></TD>
      <TD background=./images/border_top.gif><IMG height=8 alt= src=./images/px.gif width=120 border=0></TD>
      <TD background=./images/border_cnr_tr.gif><IMG height=8 alt= src=./images/px.gif width=8          border=0></TD></TR><TR><TD background=./images/border_left.gif>
       <IMG height=60 alt= src=./images/px.gif width=8 border=0></TD>
       <TD width=120>
       <TABLE cellSpacing=0 cellPadding=4 width=480 border=0>
       <TBODY>
       <TR>
       <TD align=center><img src=images/cart-contents.gif border=0><img src=images/shoppingcart.gif width = 22 height = 22 align=middle><font face=verdana size=1 color=#00CCCC></font></td></tr>
<tr><td align=center><font color = $highlight size = 2 face=verdana>'$deleted' has been removed from your cart!!!</font></td></tr>
<tr><td align=center><font face=verdana size=1 color=navy>We recommend the following product item</font></td></tr>";
	else
	echo "<center><TABLE cellSpacing=0 cellPadding=0 border=0><TR>
      <TD background=./images/border_cnr_tl.gif><IMG height=8 alt= src=./images/px.gif width=8 border=0></TD>
      <TD background=./images/border_top.gif><IMG height=8 alt= src=./images/px.gif width=120 border=0></TD>
      <TD background=./images/border_cnr_tr.gif><IMG height=8 alt= src=./images/px.gif width=8          border=0></TD></TR><TR><TD background=./images/border_left.gif>
       <IMG height=60 alt= src=./images/px.gif width=8 border=0></TD>
       <TD width=120>
       <TABLE cellSpacing=0 cellPadding=4 width=480 border=0>
       <TBODY>
       <TR>
       <TD align=center><img src=images/cart-contents.gif border=0><img src=images/shoppingcart.gif width = 22 height = 22 align=middle><font face=verdana size=1 color=#00CCCC></font></td></tr>
<tr><td align=center><font color = $highlight size = 2 face=verdana>'$prods[$index]' has been removed from your cart!!!</font></td></tr>
<tr><td align=center><font face=verdana size=1 color=navy>We recommend the following product item</font></td></tr>";

echo "<tr><td align=center><img src=$pics border=0 alt=Picture></td></tr>";
if ($prods >= 1)
echo "<tr><td><font face=verdana size=1><b>Product Item ID:</b>	$pid <a href = ./shop_showitem.php?pid=$pid></font><font color = $highlight><u>Show Item</u></font></a>";
else
echo "<tr><td><font face=verdana size=1><b>Product Item ID:</b>	N/A";
echo "</td></tr><tr><td><font face=verdana size=1><b>Product Item   :</b>    $pitem</font>";
echo "</td></tr><tr><td><font face=verdana size=1><b>Product Description:</b> $pdes</font></td></tr>";
echo "<tr><td><font face=verdana size=1><b>Product Category:</b> $scat</font></td></tr>";
if ($stocknum >=1)
echo "<tr><td><font face=verdana size=1><b>Stock: </b> $stocknum</td></tr>";
if ($stocknum < 1)
echo "<tr><td><font face=verdana size=1><b>Stock: </b> <font face=verdana size=1 color=red>Out of Stock!</font></td></tr>";
echo "</TBODY></TABLE></TD><TD background=./images/border_right.gif>
      <IMG height=60 alt= src=./images/px.gif width=8 border=0></TD></TR>
      <TR><TD background=./images/border_cnr_bl.gif>
      <IMG height=8 alt= src=./images/px.gif width=8 border=0></TD>
      <TD background=./images/border_bottom.gif>
      <IMG height=8 alt= src=./images/px.gif width=121 border=0></TD>
      <TD background=./images/border_cnr_br.gif>
      <IMG height=8 alt= src=./images/px.gif 
      width=8 border=0></TD></TR></TABLE></center><br><br>";
echo "<br><center><b>Click icon to go back to previous page.       </b><a href=javascript:history.back()><img src=images/back-to.gif border = 0></a></center><br></tr></table>";
}
}
?>

</BODY>
</HTML>
