<html>
<head><title>EZ Shopper - Add a new category</title>
<script language="JavaScript">
function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}
</script>
</head>
<body>
<?php
/***************************************************************************
 *			categorys.php                   	           *
 *                     	          				           *
 *   File Info:		  Categories Menu                                  *
 *   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 "<p align=\"center\"><br><br><center><img src=images/line.gif border-0 width=500></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><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"]);
}

########  handle add of user category ########

if ($choice == "add")
{
echo "<center><img src=images/computer.gif border=0><center><font face=verdana size=3 color=navy>Adding a new Product Category</center></font></center><br>";

### error message for default shipping ###
if ($shipopt == "NO")
{
	if ($category != NULL and $catid != NULL and $cpic != NULL)
	{

	}else
	{
		echo("<center><img src=images/line.gif border=0 width=500></center><br><center><img src=images/sbullet.gif border=0> <font face=verdana size=2 color=darkred>Cannot continue adding category records!</font><br> <font face=verdana size=2>Category & Category ID & Category Picture field must contain data!</font><br>");
		echo("<font face=verdana size=2>Go back and add details before continuing to add a new category record!</font></center><br><center><a href=category_add.php><img src=images/back-to.gif border=0>Re-input and add new category</a></center><br><center><img src=images/line.gif border=0 width=500></center><br><br>");
		echo "<center>Return back to <b><a href=./categorys.php>category menu</a></b><br>";
		include_once("./footer.inc");
		exit();	
	}
}
### error message for shipping optiobs ###
if ($shipopt == "YES")
{
	if ($category != NULL and $catid != NULL and $cpic != NULL and $shiprate != NULL)
	{

	}else
	{
		echo("<center><img src=images/line.gif border=0 width=500></center><br><center><img src=images/sbullet.gif border=0> <font face=verdana size=2 color=darkred>Cannot continue adding category records!</font><br><br> <font face=verdana size=2>Category & Category ID & Category Picture field must contain data!<br>Also Fixed Shipping Rate must contain data also.</font><br>");
		echo("<font face=verdana size=2>Go back and add details before continuing to add a new category record!<br>Includes adding fixed shipping rate into database.</font></center><br><center><a href=category_add.php><img src=images/back-to.gif border=0>Re-input and add new category</a></center><br><center><img src=images/line.gif border=0 width=500></center><br><br>");
		echo "<center>Return back to <b><a href=./categorys.php>category menu</a></b><br>";
		include_once("./footer.inc");
		exit();	
	}
}
$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 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.");
$catnum = mysql_num_rows($rs);

while ($row = mysql_fetch_array($rs))
{
       $cats = $row["category"];
       $catids = $row["catid"];
       $cpic = $row["cpic"];
       echo("<center><img src=images/line.gif border=0 width=400></center><center><font face=verdana size=2>Category: $cats</font>"); 
       echo("<br><font face=verdana size=2>Category ID: $catids</font>");
       echo("<br><font face=verdana size=2>Category Picture: $cpic</font>");
       echo("<br><font face=verdana size=2>Already exists in Category table e.g category id '$catid'!</font><br>");
       echo("<font face=verdana size=2>Press 'Back' button to return to previous menu. <font></center><center><img src=images/line.gif border=0 width=400></center><br><br>");
       include_once("./footer.inc");
       exit();
}
$sql = "INSERT INTO $table (category,catid, cpic)
	VALUES ('$category','$catid','$cpic')";
//echo($sql);
?>
<?
$sql_result = mysql_query($sql,$conn)
	or die("Couldn't add category record.");

if (!$sql_result) {     
	echo "<P>Couldn't add category record!";
} else {

echo "<center><img src=images/line.gif border=0 width=400></center><br><center><b><font face=verdana size=2 color=darkred>New Category Record Added</font></b></center>

<br><center><table cellspacing=0 cellpadding=1 bgcolor =#FFFFFF>
<tr>
<td valign=top><strong><font face=verdana size=2>Category: </font></strong></td>
<td valign=top><font face=verdana size=2>$category</font></td>
</tr>
<tr>
<td valign=top><strong><font face=verdana size=2>Category ID: </font></strong></td>
<td valign=top><font face=verdana size=2>  $catid</font></td>
</tr>
<tr>
<td valign=top><strong><font face=verdana size=2>Category Picture: </font></strong></td>
<td valign=top>  <font face=verdana size=2>$cpic</font></td>
</tr>
</table></center>
"; 

echo "<br><center><font face=verdana size=2><img src=images/sbullet.gif border=0>Category successfully added to table</font></center><br><center><img src=images/line.gif border=0 width=400></center>";

### Insert category item and delivery rate for category item into shipping table ###

if ($shipopt == "YES")
{
	$table = "shipopts";
	$sqls = " SELECT shipitem, shipitemprice from $table where shipitem = '$category'";
	if ($catnum >= 1) 
	{
	$rss = @mysql_query($sqls,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
	while ($row = mysql_fetch_array($rss))
	{
       		$shipitem = $row["shipitem"];
       		$shipitemprice = $row["shipitemprice"];
       		echo("<br><br><center><img src=images/line.gif border=0 width=400></center><center>"); 
       		echo("<br><font face=verdana size=2>Shipping Category: $shipitem</font>");
       		echo("<br><font face=verdana size=2>Shipping Price: $shipitemprice</font>");
       		echo("<br><font face=verdana size=2>Already exists in Shipping table e.g shipping category '$shipitem'!</font><br>");
       		echo("<font face=verdana size=2>Press 'Back' button to return to previous menu. <font></center><center><img src=images/line.gif border=0 width=400></center><br><br>");
       include_once("./footer.inc");
       exit();
	}
	}

$sql1 = "INSERT INTO $table (shipitem,shipitemprice)
	VALUES ('$category','$shiprate')";

$sql_results = @mysql_query($sql1,$conn)
	or die("Couldn't add record.");

if (!$sql_results) {     
	echo "<P>Couldn't add shipping record!";
} else 
{
	echo "<br><center><font face=verdana size=2><img src=images/sbullet.gif border=0>Shipping Price & Shipping Category successfully added to Shipping table</font></center><br><center>";
}
}
echo "<center><font face=verdana size=2>Return back to <b><a href=./categorys.php>category menu</font></a></b>";

}
}
########## display the textboxes ############

if ($choice == NULL)
{
	$form = "<form method=post action=category_add.php>";
	$form.= "<table align=center width=400 cellspacing=0 border=1>";
	$form.="<tr><td colspan=2 bgcolor=#ccddff><b><font face=verdana size=2>Add New Category:</font><b></td></tr>";
	$form.="<tr><td width=150><b><font face=verdana size=2>Category </font></b></td><td width = 250><input type=text class=textbox name=category size=30 maxlength=35></td></tr>";
	$form.="<tr><td width=150><b><font face=verdana size=2>Category ID </font></b></td><td width = 250><input type=text class=textbox name=catid size=5 maxlength=10><img src=./images/bullets.gif border=0><a href = javascript:newWindow('./upload.html','acePopup',450,600,'scrollbars=yes')><font face=verdana size=2>Upload Picture</font></a><img src=./images/search.gif border=0><a href = javascript:newWindow('./checkids.php','acePopup',450,330,'scrollbars=yes')><font face=verdana size=2>Check ID</font></a></td></tr>";
	$form.="<tr><td width=150><b><font face=verdana size=2>Category Picture </font></b></td><td width = 250><input type=text class=textbox name=cpic size=30 maxlength=128></td></tr>";
	if ($shipopt == "YES")
	$form.="<tr><td width=150><b><font face=verdana size=2>Fixed Shipping Rate </font></b></td><td width = 250><input type=text class=textbox name=shiprate size=10 maxlength=15></td></tr>";
	$form.="<tr><td width=150>&nbsp;</td><td width=250><input type=submit value='Add Category'><input type = reset value = 'Clear'></td></tr>";
	$form.="<input type = hidden name=choice value='add'>";
	$form.="</table></form>";
	echo $form;
	if ($shipopt == "YES")
		echo "<br><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 "<br><p align=justify><font face=verdana size=2>Please use format ./images/xxxx.gif or ./images/xxxx.jpg or ./images/xxxx.png when adding a category picture. Please note that you replace xxxx with the category filename. If you wish to use the default category picture please use ./images/folder.gif when inputting into the category picture textbox.</font></p>";

echo "<br><p align = justify><font face = verdana size = 2 color = navy> NOTE TO USERS: After you uploaded the picture using the Upload picture function, please input the location for the picture. The format is ./images/xxxx.jpg or ./images/xxxx.gif where xxxx = name of picture. You must add the location of the picture else the product category picture cannot be displayed properly</font></p>";

	echo "<center><font face=verdana size=2>Return back to <b><a href=./categorys.php>category menu</font></a></b><br><center><a href = login.php><img src=images/back-to.gif border=0><font face=verdana size=2>Back to Administrator's Panel</font></a></center>";
}
include_once("./footer.inc");
?>
</body>
</html>