<html>
<head><title>EZ Shopper - Edit a stock record</title>
<body>
<?php
/***************************************************************************
 *			edit_stocks.php                                    *
 *                     	          				           *
 *   File Info:		  Edit Stock [user]                                *
 *   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=500 height=1></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=500 height=1><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"]);
        $sitem = addslashes($_POST["sitem"]);
        $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"]);
}
$strs = getenv("QUERY_STRING");

if ($choice == "edit")
{
$table="stocks";
echo "<center><img src=images/computer.gif border=0><center><font face=verdana size=3 color=navy>Updating a Record to STOCKS</center></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><font face=verdana size=2>Updating stock record with stock id = </font>");
echo($pid);
echo("<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"];
       $sitem1 = $row["sitem"];
       $scat1 = $row["scat"];
       $spic1 = $row["spic"];
       $stock1 = $row["stock"];
       $color1 = $row["color"];
       $size1 = $row["size"];
        $done = "OK";
}
       echo("<font face=verdana size=2>Stock ID: $pid1</font>"); 
       echo("<br><font face=verdana size=2>Stock Item: $sitem1</font>");
       echo("<br><font face=verdana size=2>Category: $scat1</font>");
       echo("<br><font face=verdana size=2>Picture: $spic1</font>");
       echo("<br><font face=verdana size=2>Stock: $stock1</font>");
       echo("<br><font face=verdana size=2>Color: $color1</font>");
       echo("<br><font face=verdana size=2>Size: $size1</font>");
       echo("<br><font face=verdana size=2>Press the 'View Records' menu link to view all stocks records.</font><br><img src=./images/window.gif border=0><font face=verdana size=2>Successfully updated the stock record.....</font><img src=images/line.gif border=0 width=100% height=1>");
    
       echo "<br><br><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=./stocks_edits.php>edit /delete stocks menu</a></font></b></center><br><br>";

if ($done == "OK")
{
	$upd1 = "UPDATE $table set sitem = '$sitem' where pid = $pid";
	$rs = @mysql_query($upd1,$conn)
		or die("SQL command failed - unable to update stock record!!!");
	$upd2 = "UPDATE $table set scat = '$scat' where pid = $pid";
	$rs1 = @mysql_query($upd2,$conn)
		or die("SQL command failed - unable to update stock record!!!");
	$upd3 = "UPDATE $table set spic = '$spic' where pid = $pid";
	$rs2 = @mysql_query($upd3,$conn)
		or die("SQL command failed - unable to update stock record!!!");
	$upd4 = "UPDATE $table set stock = '$stock' where pid = $pid";
	$rs3 = @mysql_query($upd4,$conn)
		or die("SQL command failed - unable to update stock record!!!");
	$upd5 = "UPDATE $table set color = '$color' where pid = $pid";
	$rs4= @mysql_query($upd5,$conn)
		or die("SQL command failed - unable to update stock record!!!");
	$upd6 = "UPDATE $table set size = '$size' where pid = $pid";
	$rs5 = @mysql_query($upd6,$conn)
		or die("SQL command failed - unable to update stock record!!!");

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

	$table = "products";
	$sqlx = "SELECT * from $table where pid = $pid";
	$rs6 = @mysql_query($sqlx,$conn)
		or die("SQL command failed - unable to locate stocks record!!!");
	$xrow = @mysql_fetch_array($rs6);
	$pitem = $xrow["pitem"];
	if ($sitem != $pitem) // update sitem as well
	{
		
	echo"<img src=./images/window.gif border=0>Successfully updated the product record with stock item = $sitem";
	$update = "UPDATE $table set pitem = '$sitem' where pid = $pid";
	$rs7 = @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)
{
#### get categories ###
$table = "category";
# get all categories
$sql = " SELECT * from $table order by category";
$rst = mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
$number = mysql_num_rows($rst);

$table = "stocks";
$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"];
$sitem = $row["sitem"];
$scat = $row["scat"];
$spic = $row["spic"];
$stock = $row["stock"];
$color = $row["color"];
$size = $row["size"];

echo "<center><img src=images/computer1.gif border=0><font face=verdana size=3 color=navy>  Edit a Stock Item - Default Categories</font></center><form method=post action=edit_stocks.php>";
	echo"<table align=center width=400 cellspacing=0 border=1>";
	echo"<tr><td colspan=2 bgcolor=#ccddff><b><font face=verdana size=2>Edit Stock Record:</font></b></td></tr>";
	echo"<tr><td width=150><b><font face=verdana size=2>Stock ID </font></b></td><td width = 250><input type=text class=textbox name=pid size=6 maxlength=10 value='$pid' readonly></td></tr>";
	echo"<tr><td width=150><b><font face=verdana size=2>Stock Item </font></b></td><td width = 250><input type=text class=textbox name=sitem size=30 maxlength=35 value='$sitem'></td></tr>";
	echo "<tr><td width=150><b><font face=verdana size=2>Category</font></b></td><td width=250><select name=\"scat\">";
if ($number == 0)
{
	echo "<option value = \"No Category\">-- No Category --</option></select>";
}
else
{
	while ($row = mysql_fetch_array($rst))
	{
		$category = $row["category"];
		if ($category != $scat)
		echo"<option value =\"$category\">-- $category --</option>";
		else
			echo"<option value = \"$category\" selected>-- $category --</option>";
	}
	echo "</select></td></tr>";
}
	echo"<tr><td width=150><b><font face=verdana size=2>Picture</font> </b></td><td width = 	250><input type=text class=textbox name=spic size=35 maxlength=50 value='$spic'></td></tr>";
	echo"<tr><td width=150><b><font face=verdana size=2>Stock </font></b></td><td width = 250><input type=text class=textbox name=stock size=6 maxlength=10 value='$stock'></td></tr>";
	echo"<tr><td width=150><b><font face=verdana size=2>Color </font></b></td><td width = 250><input type=text class=textbox name=color size=20 maxlength=25 value=$color></td></tr>";
	echo"<tr><td width=150><b><font face=verdana size=2>Size </font></b></td><td width = 250><input type=text class=textbox name=size size=20 maxlength=25 value=$size></td></tr>";
	echo"<tr><td width=150>&nbsp;</td><td width=250><input type=submit value='Edit Product'><input type = reset value = 'Clear'></td></tr>";
	echo"<input type = hidden name=choice value='edit'>";
	echo"</table></form>";
	
	echo "<center><font face=verdana size=2>Return back to <b><a href=./prodstocks.php>products/stocks menu</font></a></b>";
}

include_once("./footer.inc");

?>
</body>
</html>