<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Viewing / Deleting Records</TITLE>
</HEAD>
<BODY>

<?php
/***************************************************************************
 *			view_history.php                                   *
 *                     	          				           *
 *   File Info:		  View History                                     *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include ("./your-header.inc");
?>
<center><img src=images/searching.gif border=0><font face=verdana size=3 color=darkred>  Viewing Records from your ACCOUNT HISTORY</font></center>
<br>
<?php
include("./config.php");
$strvar = getenv("QUERY_STRING");
$pos = strpos($strvar,'=');
if ($pos>=0) 
	$username = substr($strvar,$pos+1);
 if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $username = addslashes($_POST["username"]);
}
$table = "history";
$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...Please press 'Create Database' to create new database.");
$sql = " SELECT * from $table where username = '$username'";
$rs = mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");

$list.="<table width=50% cellpadding=2 cellspacing=0 border=0 bgcolor=#FFFFFF align = center>";
$list.="<tr>";
$list.="<td><strong><center><img src=images/docs.gif border=0><b><font face=verdana size=2> ACCOUNT HISTORY</font></b></center></strong></td>";
$list.="</tr>";
$list.="</table><br>";
echo($list);
?>
<img src=images/line.gif border=0 width=100% height=1>
<br>
<p align = "justify"><font face = "Verdana" size = 3">Below is a list of orders you have placed so far. To view the details of each order
click on the Order Number of the order you wish to view.</p>
<?php 

######## order information for customer ###############

$numords = mysql_num_rows($rs);	// number of customer orders

$xsql = "SELECT * from $table where username = '$username' and stat = 'Awaiting payment'";
$xres = @mysql_query($xsql,$conn)
	or die("SQL command failed - unable to get information for customer orders...");
$number = mysql_num_rows($xres);	// number of awaiting payment orders
$xsql1 = "SELECT * from $table where username = '$username' and stat = 'payment received'";
$xres1 = @mysql_query($xsql1,$conn)
	or die("SQL command failed - unable to get information for customer orders...");
$number1 = mysql_num_rows($xres1);	// number of awaiting payment orders
$xsql2 = "SELECT * from $table where username = '$username' and stat = 'order rejected'";
$xres2 = @mysql_query($xsql2,$conn)
	or die("SQL command failed - unable to get information for customer orders...");
$number2 = mysql_num_rows($xres2);	// number of rejected orders

echo "<center><b>YOUR ORDERS SUMMARY</b><br><br><table width=400 border=0 cellpadding=0 cellspacing=0><tr><b><td><img src=images/bullets.gif border=0><b>Total Orders:</b></td><td> $numords</td><b></tr><tr><td><img src=images/bullets.gif border=0><b>Orders awaiting payment: </b></td><td>$number</td></tr><tr><td><img src=images/bullets.gif border=0><b>Orders completed: </b></td><td>$number1</td></tr><tr><td><img src=images/bullets.gif border=0><b>Rejected Orders: </b></td><td>$number2</td></tr></table></center><br>";
$list = "<center><table border =\"1\" cellpadding =\"2\" bgcolor = $backcolor width=100%>";
$list.="<th><font face=verdana size=2 color=navy>Order ID</font></th>";
$list.="<th><font face=verdana size=2 color=navy>Full Name</font></th>";
$list.="<th><font face=verdana size=2 color=navy>Status</font></th>";
$list.="<th><font face=verdana size=2 color=navy>Grand Total</font></th>";
$list.="<th><font face=verdana size=2 color=navy>Order Date</font></th>";
$list.="</tr>";

while($row = mysql_fetch_array($rs))
{
	$orderid = $row["orderid"];
	$full = $row["fullname"];
	$stats = $row["stat"];
	$tot = $row["total"];
	$tot = number_format($tot,2);
	$date_added = $row["rtime"];
	$list.= "<tr>";
	$list.="<td width=120><form action = view_cust.php?$orderid method=post><input type = image src=images/searchs1.gif alt=View></form><font face=verdana size=2>$orderid</font>";
	$list.="</td>";
	if ($full != NULL)
	$list.="<td><font face=verdana size=2>$full</font></td>";
	else
	$list.="<td><font face=verdana size=2>N/A</font></td>";
	$list.="<td><font face=verdana size=2>$stats</font></td>";
	if ($wcurrency == "NO")
	$list.="<td><font face=verdana size=2>$currency$tot</font></td>";
	if ($wcurrency != "NO")
	$list.="<td><font face=verdana size=2>($wcurrency)$tot</font></td>";
	$list.="<td><font face=verdana size=2>$date_added</font></td>";
	$list.="</tr>";
}
$list.= "</table></center>";
echo($list);
echo("<br><center><font color = $highlight face=verdana size=2>NOTE: The order date is date/time of host server and not localtime.</font></center>");
echo"
<center><br>
<table width=60% cellpadding=0 cellspacing=0 border=0 bgcolor=FFFFFF align = middle><tr><td valign=top>
<table width=100% cellpadding=1 cellspacing=3 border=0 align = middle>
<tr bgcolor=ffffff><td>
&nbsp;<font face=verdana size=-1><b><a href=./shop_showall.php>Product List</a></b><img src = ./images/shop.gif><br><small>&nbsp;</small></font>
<td>&nbsp;<font face=verdana size=-1><b><a href=./shop_delcart.php>Empty Cart</a></b><img src = ./images/trashicon.gif><br><small>&nbsp;</small></font></td>
<td>&nbsp;<font face=verdana size=-1><b><a href=./shop_viewcart.php>View Cart</a></b><img src = ./images/shoppingcart.gif width=18 height = 18><br><small>&nbsp;</small></font></td>
</table></td></tr></table></center><br><img src=images/line.gif border=0 width=100% height=1>";


echo "<br><br><center><font face=verdana size=2>Back to store page</font><a href=store.php><img src=images/homes.gif border=0></a>";
include("./your-footer.inc");?>
</BODY>
</HTML>