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

include_once("./header.inc");

echo "<center><img src=images/searching.gif border=0></center><center><font face=verdana size=3 color=navy>List all  categories and edit/delete category.</font></center>";
$page = getenv("QUERY_STRING");

if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $limit= addslashes($_POST["limit"]);
        $search = addslashes($_POST["search"]);
}
if ($limit == NULL)
	$limit = 5;

echo "<img src=images/line.gif border=0 width=100%><br><br><font face = Verdana size = 2>Please select number of categories you wish to view:- ";
$form = "<form action =category_edit.php method = POST>";
$form.= "<select name = limit><option value = 5>5 records</option><option value = 10>10 records</option><option value = 25>25 records</option><option value = 50>50 records</option></select>";
$form.= "<input type=submit value = 'View Records'></form>";
echo $form;

echo "<font face = Verdana size = 2>Please input the category you wish to search by:-";
$form = "<form action = category_edit.php method = POST>";
$form.= "Search by Category: <input type = text name = search size = 30 maxlength = 50>";
$form.= "<input type =submit value='Search'></form>";
echo $form;

########################################################
$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.");

######################### display information search only ###################################

if ($search != NULL)
{
if (empty($page))
$page = 1;
$limitv = $page * $limit - ($limit);
$query_count = "SELECT * from $table where (category like '%$search%') order by catid";
$res_count = mysql_query($query_count,$conn);
$totalrows = mysql_num_rows($res_count);
$query = "SELECT * from $table  where (category like '%$search%')  order by catid LIMIT $limitv,$limit";
$result = mysql_query($query,$conn)
	or die("SQL command fail ".mysql_error());
$count_result = mysql_num_rows($result);

$numpages = ceil($totalrows / $limit);

echo "<p><center><b><font face=verdana size=2>Found $totalrows</b> result(s) for category = '$search' - Listing $limit categories per page.</font></center></p>";
$from = $limit*$page-$limit+1;
$to = $from+$count_result-1;
if ($style == 1) #style 1
{
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"left\">";if($numpages>1){echo"<font face=verdana size=2>Showing item(s): $from to $to</font></td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b><font face=verdana size=2>Go to page:</font></b> ";} 
}
if ($style == 2) #style 2
{
echo "<table align=\"center\" width=\"60%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"left\">";if($numpages>1){echo"<font face=verdana size=2>Showing item(s): $from to $to</font></td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b><font face=verdana size=2>Go to page:</font></b> ";} 
}
if($page != 1){ 
$pageprev = $page - 1; 
echo("<a href=\"$PHP_SELF?$pageprev\"><img src = ./images/back.gif  width = 16 height = 20 border = 0></a>&nbsp;"); 

} 

// display page nos if not 1 
for($i = 1; $i <= $numpages; $i++){ 
if($numpages>1){
if($i == $page) 
echo("&nbsp;".$i."&nbsp;"); 
else
echo("&nbsp;<a href=\".\category_edit.php?$i\">$i</a>&nbsp;"); 
}}

// display next page link if there is more than one
if(($totalrows - ($limit * $page)) > 0){ 
$pagenext = $page + 1; 
echo("<a href=\"$PHP_SELF?$pagenext\"><img src = ./images/next.gif width = 16 height = 20 border = 0></a>"); 
}
echo "</td><tr></table><br>";

######################### display part ##############################

echo"<table align=\"center\" valign=\"top\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr bgcolor=\"$backcolor\"><td>
<table cellpadding=\"2\" border=\"0\" cellspacing=\"1\" valign=\"top\" width=\"100%\" align=\"center\"><tr bgcolor=\"#FFFFFF\">
<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Category ID</font></b></td><td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Category</font></b></td><td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Category Picture</font></b></td><td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Information</font></b></td></tr>";
					

	while($row = mysql_fetch_array($result))
	{
	$catid = $row["catid"];
	$category = $row["category"];
	$cpic = $row["cpic"];
	echo"<tr bgcolor=\"#FFFFFF\">
            <td><font face=verdana size=2>$catid</font></td>
            <td><font face=verdana size=2>$category</font></td>
            <td><font face=verdana size=2>$cpic</font></td>	
            <td><img src =\"images\web1.gif\" width = 32 height = 24><a href=./edit_category.php?$catid><font face=verdana size=2>[Edit]</font></a> | <a href=./del_category.php?$catid><font face=verdana size=2>[Delete]</font></a></td>
             </tr>";
	}
 echo "</table></tr></td></table><br><img src=images/line.gif border=0 width=100%>";
 echo "<br><font face = Verdana size = 2><p align = justify>NOTE TO USERS: Please click on the Edit button to edit a category and click on the Delete button to delete a category.<br><br><b>";echo "<center>Return back to <b><a href=./categorys.php>category menu</a></b><br><br><a href=login.php><img src=images/back-to.gif border=0><font face=verdana size=2>Back to Administrator's Panel</a></center></p></font><br>";
include("./your-footer.inc");
}

######################## display information no search #####################################

if ($search == NULL)
{

if (empty($page))
$page = 1;
$limitv = $page * $limit - ($limit);

$query_count = "SELECT * from $table order by catid";
$res_count = mysql_query($query_count,$conn);
$totalrows = mysql_num_rows($res_count);
$query = "SELECT * from $table order by catid LIMIT $limitv,$limit";
$result = mysql_query($query,$conn)
	or die("SQL command fail ".mysql_error());
$count_result = mysql_num_rows($result);

$numpages = ceil($totalrows / $limit);

echo "<p><center><b><font face=verdana size=2>Found $totalrows</b> result(s)  - Listing $limit categories per page.</font></center></p>";
$from = $limit*$page-$limit+1;
$to = $from+$count_result-1;
if ($style == 1) #style 1
{
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"left\">";if($numpages>1){echo"<font face=verdana size=2>Showing item(s): $from to $to</font></td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b><font face=verdana size=2>Go to page:</font></b> ";} 
}
if ($style == 2) #style 2
{
echo "<table align=\"center\" width=\"60%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"left\">";if($numpages>1){echo"<font face=verdana size=2>Showing item(s): $from to $to</font></td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b><font face=verdana size=2>Go to page:</font></b> ";} 
}
if($page != 1){ 
$pageprev = $page - 1; 
echo("<a href=\"$PHP_SELF?$pageprev\"><img src = ./images/back.gif  width = 16 height = 20 border = 0></a>&nbsp;"); 

} 

// display page nos if not 1 
for($i = 1; $i <= $numpages; $i++){ 
if($numpages>1){
if($i == $page) 
echo("&nbsp;".$i."&nbsp;"); 
else
echo("&nbsp;<a href=\".\category_edit.php?$i\">$i</a>&nbsp;"); 
}}

// display next page link if there is more than one
if(($totalrows - ($limit * $page)) > 0){ 
$pagenext = $page + 1; 
echo("<a href=\"$PHP_SELF?$pagenext\"><img src = ./images/next.gif width = 16 height = 20 border = 0></a>"); 
}
echo "</td><tr></table><br>";

######################### display part ##############################

echo"<table align=\"center\" valign=\"top\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr bgcolor=\"$backcolor\"><td><table cellpadding=\"2\" border=\"0\" cellspacing=\"1\" valign=\"top\" width=\"100%\" align=\"center\"><tr bgcolor=\"#FFFFFF\"><td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Category ID</font></b></td>
<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Category</font></b></td><td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Category Picture</font></b></td><td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Information</font></b></td></tr>";

	while($row = mysql_fetch_array($result))
	{
	$catid = $row["catid"];
	$category = $row["category"];
	$cpic = $row["cpic"];
	echo"<tr bgcolor=\"#FFFFFF\">
            <td><font face=verdana size=2>$catid</font></td>
            <td><font face=verdana size=2>$category</font></td>
            <td><font face=verdana size=2>$cpic</font></td>
    <td><img src =\"images\web1.gif\" width = 32 height = 24><a href=./edit_category.php?$catid><font face=verdana size=2>[Edit]</font></a> | <a href=./del_category.php?$catid><font face=verdana size=2>[Delete]</font></a></td>
             </tr>";
	}
 echo "</table></tr></td></table><br><hr>";
 echo "<br><font face = Verdana size = 2><p align = justify>NOTE TO USERS: Please click on the Edit button to edit a category and click on the Delete button to delete a category.<br><br><b>";echo "<center>Return back to <b><a href=./categorys.php>category menu</a></b></p></font><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>