<html>
<head>
<title>EZ Shopper - Managing customer orders</title></head>
<body bgcolor = "#CCDDFF">
<?
  
/***************************************************************************
 *			chg_status.php	                                   *
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~	                   *
 *   File Info:		  Change/Order Status                              *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/

include("./config.php");
include("./tests.php");
if ($_SESSION['admin'] == NULL)
{
echo("<br><br><br><br><br><br><br><center><img src=images/keybord1.gif border=0><b> You have not log in. If you are an existing member please click the <a href =./shop_showall.php>Login</a> link!</b><br>If you are a new user click the <a href=./newpass.php>Register Me</a> link.</center><br>");
exit();
}
$orderid = getenv("QUERY_STRING");
$done = "NO";
if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $act= addslashes($_POST["act"]);
        $orderid = addslashes($_POST["orders"]);
    
}

$table = "history";
$conn = @mysql_connect($server,$user,$password)
	or die("Unable to connect to SQL database...");
$rss = @mysql_select_db($database,$conn) 
	or die("Unable to select the database...Please press 'Create Database' to create new database.");
#if act == wait
if ($act == "wait")
{
	$table = "history";
	$sql1 = "UPDATE $table set stat = 'await payment' where orderid = '$orderid'";
	$up1 = @mysql_query($sql1,$conn)
		or die("SQL command failed - unable to update status !");
	$done = "YES";
}
#if act == paid
if ($act == "paid")
{
	$table = "history";
	$sql2 = "UPDATE $table set stat = 'payment received' where orderid = '$orderid'";
	$up2 = @mysql_query($sql2,$conn)
		or die("SQL command failed - unable to update status !");
	$done = "YES";
}
#if act == reject
if ($act == "reject")
{
	$table = "history";
	$sql3 = "UPDATE $table set stat = 'order rejected' where orderid = '$orderid'";
	$up3 = @mysql_query($sql3,$conn)
		or die("SQL command failed - unable to update status !");
	$done = "YES";
}


$sql = " SELECT * from $table where orderid = '$orderid'";
$rs = mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
echo "<center><img src=images/upd-cart.gif border=0><font face=verdana size=2> Update and change order status</font><br><br></center>";
echo"<table align=\"center\" valign=\"top\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr bgcolor=\"$backcolor\"><td>
			<table cellpadding=\"2\" border=\"0\" cellspacing=\"1\" valign=\"top\" width=\"100%\" align=\"center\">
				<tr bgcolor=\"#FFFFFF\">
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b>Order No</b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b>Status</b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b>Date/Time</b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b>Total</b></td></tr>";

	while($row = mysql_fetch_array($rs))
	{
	$orderid = $row["orderid"];
	$full = $row["fullname"];
	$stats = $row["stat"];
	$tot = $row["total"];
	$date_added = $row["rtime"];
	echo"<tr bgcolor=\"#FFFFFF\">
            <td>$orderid</td>
            <td>$stats</td>
            <td>$date_added</td>
             <td>$currency$tot</td>
              </tr>";
	}
 echo "</table></tr></td></table><br><img src=images/line.gif border=0 width=100% height=1>";
if ($done == "YES")
	echo "<center><font color = $color><b>Updating completed</b></font></center>";
echo "<br><font face = Verdana size = 3></b><center>Please select which action you wish to take</center></b></font>";
#set status to 'awaiting payment'
echo "<center><form action = chg_status.php method = post>
         <input type = hidden name = act value = wait>	
         <input type = hidden name = orders value =$orderid>
         <input type = submit value = 'Change status to awaiting payment'></form></center>
<center><form action = chg_status.php method = post>
         <input type = hidden name = act value = paid>	
         <input type = hidden name = orders value =$orderid>
         <input type = submit value = 'Change status to payment received'></form></center>
<center><form action = chg_status.php method = post>
         <input type = hidden name = act value = reject>	
         <input type = hidden name = orders value =$orderid>
         <input type = submit value = 'Change status to order rejected'></form></center>";
echo "<li>Change to payment received if you have receive payment from customer.<br><li>Change to order rejected if no payment received from customer.<br><li>Change to await payment if you have to await payment from customer.";
echo("<br><br><center><a href = javascript:window.close('acePopup')>Close Window</a></center>");
?>
  
</body>
</html>