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

include_once("./header.inc");
include_once("./config.php");
@session_start();
if ($_SESSION['admin'] != "admin" or $_SESSION['admin'] == NULL)
{
echo "<br><br><center><img src=images/line.gif border=0 height=1 width=400></center><p align=\"center\"><img src=images/keybord1.gif border=0><b><strong><font face = Verdana size = 3>   Sorry you are not the administrator!</strong></font></b><br>Click here to return to log in screen  <a href='shop_showall.php'>here.</a>
<br><br><img src=images/line.gif border=0 height=1 width=400><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
$caterid = getenv("QUERY_STRING");
if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $choice = addslashes($_POST["choice"]);
        $delete = addslashes($_POST["delete"]);

}
if ($delete == "delete" and $choice == "NO")
{
echo "<br><center><img src=images/computer1.gif border=0><font face=verdana size=2 color=navy> Deleting Category Record from Category Table</center><br>";
echo "<center><img src=images/line.gif border=0 width=400 height=1></center><br><center>Category record id  '$caterid' not deleted from category table</center>";
echo "<br><center>Return back to <b><a href=./categorys.php>category menu</a></b>";
echo "<center>Return back to <b><a href=./category_edit.php>edit/delete category menu</a></b></font><img src=images/line.gif border=0 width=400 height=1>";
}
if ($delete =="delete" and $choice =="YES")
{
echo "<br><center><img src=images/computer1.gif border=0><font face=verdana size=2 color=navy> Deleting Category Record from Category Table</center><br>";
$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.");

##### Also delete shipping record if exists ! #####

if ($shipopt == "YES")
{
$table = "category";
$sql = " SELECT category,catid from $table where catid = $caterid";

$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"];
       $catids = $row["catid"];
       $cpic = $row["cpic"];
}

$table = "shipopts";
$sqls = "DELETE from $table where shipitem = '$cats'";
$rst = mysql_query($sqls,$conn);
	
if ($rst)
echo "<br><center><img src=images/line.gif border=0 width=400 height=1></center><br><center><font face=verdana size=2 color=navy>Shipping record '$cats' successfully deleted from shipping table</center>";
if (!$rst)
	echo("<center>Unable to delete shipping record from shipping table....<br>Possibly shipping record has already been deleted!</center>");
}
$table = "category";
$sql = "DELETE from $table where catid = $caterid";
$rs = mysql_query($sql,$conn)
	or die("Unable to delete category record from category table....");
if ($rs)
echo "<br><center><img src=images/line.gif border=0 width=400 height=1></center><br><center><font face=verdana size=2 color=navy>Category record id  '$caterid' successfully deleted from category table</center>";

echo "<br><center>Return back to <b><a href=./categorys.php>category menu</a></b>";
echo "<center>Return back to <b><a href=./category_edit.php>edit/delete category menu</a></b></font><br><br><img src=images/line.gif border=0 width=400 height=1></center>";
}
if ($delete == NULL)
{
echo "<center><table width=250 border=1 cellspacing=0 cellpadding=0 height=80>
<tr><td width=250 bgcolor=#CCCCCC height=10>$header</td></tr>
<tr><td width=250 bgcolor=#CCDDFF height=80>";

if ($shipopt == "NO")
echo "<form action =./del_category.php?$caterid method = post><center>Delete category with Category ID = $caterid <input type=hidden name=delete value='delete'><select name = \"choice\"><option value=\"YES\">-- YES --</option><option value = \"NO\">-- NO --</option></select><input type=submit name = submit value='GO'></form></tr></table><br>Press 'GO' and select 'YES' to delete category.</center><hr>";
if ($shipopt == "YES")
echo "<form action =./del_category.php?$caterid method = post><center>Delete category with Category ID = $caterid <input type=hidden name=delete value='delete'><select name = \"choice\"><option value=\"YES\">-- YES --</option><option value = \"NO\">-- NO --</option></select><input type=submit name = submit value='GO'></form></tr></table><br>Press 'GO' and select 'YES' to delete category. N.B Also will delete associated shipping record!</center><hr>";

echo "<br><center>Return back to <b><a href=./categorys.php>category menu</a></b>";
echo "<center>Return back to <b><a href=./category_edit.php>edit/delete category menu</a></b>";
}
include_once("./footer.inc");
?>
</body>
</html>