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

include_once("./header.inc");
include_once("./config.php");
@session_start();
$catsid = getenv("QUERY_STRING");
if ($_SESSION['admin'] != "admin" or $_SESSION['admin'] == NULL)
{
	 echo "<p align=\"center\"><b><strong><font face = Verdana size = 5>Sorry you not the administrator!</strong></font></b><br>Click here to return to log in screen <a href='shop_showall.php'>here.</a><br><br><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
 if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $choice = addslashes($_POST["choice"]);
        $category = addslashes($_POST["category"]);
        $catid = addslashes($_POST["catid"]);
        $cpic = addslashes($_POST["cpic"]);
	$shiprate = addslashes($_POST["shiprate"]);
}
$strs = getenv("QUERY_STRING");

if ($choice == "edit")
{
$table="category";
echo "<center><h3><center>Updating a Record to CATEGORY</center></h3></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>Updating category record with category = ");
echo($category);
echo("<br>");
$done = "FALSE";
$sql = " SELECT category,catid from $table where catid = $catid";
$rs = @mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
while($row=mysql_fetch_array($rs))
{
       $cats = $row["category"];
       $catid = $row["catid"];
       echo("Category: $cats"); 
       echo(" Category ID: $catid");
       echo(" Category Picture: $cpic");
       echo("<br>Press the 'View Records' menu link to view all category records. <br><img src=./images/window.gif border=0>Successfully updated the category record.....<img src=./images/line.gif border=0 width=100% height=1><br>");
    
echo "<br><center>Return back to <b><a href=./categorys.php>category menu</a>";
echo "<center>Return back to <b><a href=./category_edit.php>edit /delete category menu</a></b></center><br><br>";
       $done = "OK";
if ($done == "OK")
{
	$upd = "UPDATE $table set category = '$category' where catid = $catid";
	$rs = @mysql_query($upd,$conn)
	or die("SQL command failed - unable to update category record!!!");
	$upd1 = "UPDATE $table set cpic = '$cpic' where catid = $catid";
	$rs1 = @mysql_query($upd1,$conn)
	or die("SQL command failed - unable to update category record!!!");
	
	### update shipping item price in shipping table ###

	if ($shipopt == "YES")
	{
		$table = "shipopts";
		$upds = "UPDATE $table set shipitemprice = $shiprate where shipitem = '$cats'";
		$rs = @mysql_query($upds,$conn)
			or die("SQL command failed - unable to update shipping record!!!");
		if ($rs)
			echo "<img src=./images/window.gif border=0><font face=verdana color = #000080>Successfully updated the shipping record.....</font>";
	}
	include_once("./footer.inc");
	exit();
}
}
if ($done=="FALSE")
{
	echo("Opps...its seems cannot update category record with category id = ");
	echo($catid);
	exit();
}
}
############## display the text boxes with data ###############

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

#### read ship item price from shipping table ####

$table = "shipopts";
$sqls = "SELECT * from $table where shipitem = '$category'";
$rst = @mysql_query($sqls,$conn)
	or die("SQL command failed - unable to get shipping price details!!!");

$rows = @mysql_fetch_array($rst);
$shiprate = $rows["shipitemprice"];

$form = "<form method=post action=edit_category.php>";
	$form.= "<table align=center width=400 cellspacing=0 border=1>";
	$form.="<tr><td colspan=2 bgcolor=#ccddff><b>Edit Category:<b></td></tr>";
	$form.="<tr><td width=150><b>Category </b></td><td width = 250><input type=text class=textbox name=category size=30 maxlength=35 value='$category'></td></tr>";
	$form.="<tr><td width=150><b>Category ID </b></td><td width = 250><input type=text class=textbox name=catid size=30 maxlength=35 value=$catid readonly></td></tr>";
	$form.="<tr><td width=150><b>Category Picture </b></td><td width = 250><input type=text class=textbox name=cpic size=30 maxlength=128 value=$cpic></td></tr>";
	if ($shipopt == "YES")
	$form.="<tr><td width=150><b>Fixed Shipping Rate </b></td><td width = 250><input type=text class=textbox name=shiprate size=10 maxlength=15 value=$shiprate></td></tr>";
	$form.="<tr><td width=150>&nbsp;</td><td width=250><input type=submit value='Edit Category'><input type = reset value = 'Clear'></td></tr>";
	$form.="<input type = hidden name=choice value='edit'>";
	$form.="</table></form>";
	echo $form;
	if ($shipopt == "YES")
		echo "<center><font face=verdana size=2 color = navy>The value of fixed shipping rate is determined by administrative costs for posting.<br>The value is dependent on postage costs from your host country and may vary accordingly.</center><br></font>";
	echo "<center>Return back to <b><a href=./categorys.php>category menu</a></b>";
}

include_once("./footer.inc");

?>
</body>
</html>