<html>
<head><title>EZ Shopper - Edit a category</title>
<body>
<?php
/***************************************************************************
 *			edit_product.php                                   *
 *                     	          				           *
 *   File Info:		  Edit Product                                     *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/

include_once("./header.inc");
include_once("./config.php");
@session_start();
$pid = getenv("QUERY_STRING");
if ($_SESSION['admin'] != "admin" or $_SESSION['admin'] == NULL)
{
	
 echo "<p align=\"center\"><br><br><center><img src=images/line.gif border-0 width=100%></center><b><br><center><strong><font face = Verdana size = 2 color=navy>You must login as administrator to use this function!</strong></font></b><br>Click here to return to log in screen <a href='reglog.php'>here.</a><br><br><img src=images/line.gif border=0 width=100%><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
 if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $choice = addslashes($_POST["choice"]);
        $pid = addslashes($_POST["pid"]);
        $pitem = addslashes($_POST["pitem"]);
        $pdes = addslashes($_POST["pdes"]);
        $price = addslashes($_POST["price"]);
        $scat = addslashes($_POST["scat"]);
        $color = addslashes($_POST["color"]);
        $size = addslashes($_POST["size"]);
        $price = addslashes($_POST["price"]);
        $stock = addslashes($_POST["stock"]);
        $spic = addslashes($_POST["spic"]);
	$price = number_format($price,2);
}
$strs = getenv("QUERY_STRING");

if ($choice == "edit")
{
$table="products";
echo "<center><img src=images/computer.gif border=0><font face=verdana size=3 color=navy>Updating a Record to PRODUCT</font></center><br>";
$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.");
echo("<img src=images/line.gif border=0 width=100% height=1><br><font face=verdana size=2>Updating product record with product id = ");
echo($pid);
echo("</font><br>");
$done = "FALSE";
$sql = " SELECT * from $table where pid = $pid";
$rs = @mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
while($row=mysql_fetch_array($rs))
{
       $pid1 = $row["pid"];
       $pitem1 = $row["pitem"];
       $pdes1 = $row["pdes"];
       $price1 = $row["price"];
       $price1 = number_format($price1,2);
       $done = "OK";
}
       echo("<font face=verdana size=2>Product ID: $pid1</font>"); 
       echo("<br><font face=verdana size=2>Product Item: $pitem1</font>");
       echo("<br><font face=verdana size=2>Description: $pdes1</font>");
       echo("<br><font face=verdana size=2>Price: $price1</font>");
       echo("<br><font face=verdana size=2 color=navy>Updated items:-</font>");
       echo("<br><font face=verdana size=2><b>Product Item:</b> $pitem</font>");
       echo("<br><font face=verdana size=2><b>Description:</b> $pdes</font>");
       echo("<br><font face=verdana size=2><b>Price:</b> $price</font>");
       echo("<br><font face=verdana size=2>Press the 'View Records' menu link to view all product records.</font><br><img src=./images/window.gif border=0><font face=verdana size=2>Successfully updated the product record.....</font><img src=images/line.gif border=0 width=100% height=1><br><br>");
    
echo "<center><font face=verdana size=2>Return back to <b><a href=./prodstocks.php>products/stocks menu</font></a>";
echo "<center><font face=verdana size=2>Return back to <b><a href=./products_edit.php>edit /delete category menu</font></a></b></center><br><br>";
if ($done == "OK")
{
	$upd1 = "UPDATE $table set pitem = '$pitem' where pid = $pid";
	$rs = @mysql_query($upd1,$conn)
		or die("SQL command failed - unable to update product record!!!");
	$upd2 = "UPDATE $table set pdes = '$pdes' where pid = $pid";
	$rs1 = @mysql_query($upd2,$conn)
		or die("SQL command failed - unable to update product record!!!");
	$upd3 = "UPDATE $table set price = '$price' where pid = $pid";
	$rs2 = @mysql_query($upd3,$conn)
		or die("SQL command failed - unable to update product record!!!");

	##### check see we need to update sitem #####

	$table = "stocks";
	$sqlx = "SELECT * from $table where pid = $pid";
	$rs3 = @mysql_query($sqlx,$conn)
		or die("SQL command failed - unable to locate stocks record!!!");
	$xrow = @mysql_fetch_array($rs3);
	$sitem = $xrow["sitem"];
	if ($sitem != $pitem) // update sitem as well
	{
		
	echo"<center><img src=./images/window.gif border=0>Successfully updated the stock record with product item = $pitem</center>";
	$update = "UPDATE $table set sitem = '$pitem' where pid = $pid";
	$rs4 = @mysql_query($update,$conn)
		or die("SQL command failed - unable to update stocks record!!!");
	}
	include_once("./footer.inc");
	exit();
}
if ($done=="FALSE")
{
	echo("Opps...its seems cannot update product record with product id = ");
	echo($pid);
	exit();
}
}
############## display the text boxes with data ###############

if ($choice == NULL)
{
$table = "products";
$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 pid = $strs";
$rs = @mysql_query($sql,$conn)
	or die("SQL command failed - unable to get category details!!!");
$row = mysql_fetch_array($rs);
$pid = $row["pid"];
$pitem = $row["pitem"];
$pdes = $row["pdes"];
$price = $row["price"];
$price = number_format($price,2);
    

$form = "<form method=post action=edit_product.php>";
	$form.= "<table align=center width=400 cellspacing=0 border=1>";
	$form.="<tr><td colspan=2 bgcolor=#ccddff><b>Edit Product:<b></td></tr>";
	$form.="<tr><td width=150><b>Product ID </b></td><td width = 250><input type=text class=textbox name=pid size=6 maxlength=10 value='$pid' readonly></td></tr>";
	$form.="<tr><td width=150><b>Product Item </b></td><td width = 250><input type=text class=textbox name=pitem size=30 maxlength=35 value='$pitem'></td></tr>";
	$form.="<tr><td width=150><b>Description </b></td><td width = 250><textarea rows=3 name=pdes cols=40 value='$pdes' >$pdes</textarea></td></tr>";
	$form.="<tr><td width=150><b>Price </b></td><td width = 250><input type=text class=textbox name=price size=7 maxlength=10 value=$price></td></tr>";
	$form.="<tr><td width=150>&nbsp;</td><td width=250><input type=submit value='Edit Product'><input type = reset value = 'Clear'></td></tr>";
	$form.="<input type = hidden name=choice value='edit'>";
	$form.="</table></form>";
	echo $form;
	echo "<center>Return back to <b><a href=./prodstocks.php>products/stocks menu</a></b>";
}

include_once("./footer.inc");

?>
</body>
</html>