<?php
require "./Cart.php";

$Category=ereg_replace("\"","&quot;","$Category");
$PagingStep = intval($PagingStep);

if (isset($Add)) {
     mysql_query("INSERT INTO Category (Category, PagingStep) VALUES('$Category', $PagingStep)");
}
if (isset($Del)) {
     mysql_query("DELETE FROM Category WHERE CategoryID = $CategoryID");
}
if (isset($Mod)) {
     if (!empty($Category))
          $aset[] = "Category = '$Category'";
     if (!empty($PagingStep))
          $aset[] = "PagingStep = $PagingStep";
     if (count($aset) > 0) {
          $set = implode(',', $aset);
          mysql_query("UPDATE Category SET $set  WHERE CategoryID = $CategoryID");
     }
}

$result=mysql_query("SELECT CategoryID, Category, PagingStep FROM Category ORDER BY Category");

adminHeader("$Company","Remove A Category");

echo "<FORM ACTION=\"$PHP_SELF?topic=category.php\" METHOD=\"POST\">";
echo "<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"10\"><TR>";

echo "<TR><TD colspan=2>";
blueFont('Arial','Add a new category');
echo "</tr></td><tr><td>";
blueFont('Arial','Category');
echo "</td><td><INPUT TYPE=\"text\" name=\"Category\"></td></tr>";
echo "</tr></td><tr><td>";
blueFont('Arial','Paging Step');
echo "</td><td><INPUT TYPE=\"text\" name=\"PagingStep\" size=2>";
echo " <INPUT TYPE=\"submit\" NAME=\"Add\" VALUE=\"ADD\"></td></tr></TABLE></FORM>";

echo "<hr>";

echo "<FORM ACTION=\"$PHP_SELF?topic=category.php\" METHOD=\"POST\">";
echo "<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"10\">";

echo "<TR><TD>";
blueFont('Arial','To DELETE a category<br>');
echo "<SELECT NAME=\"CategoryID\" SIZE=\"1\">";
echo "<OPTION VALUE=\"\">Select a Category here then press DELETE";
mysql_data_seek($result,0);
while (list($id, $name, $step) = mysql_fetch_row($result)) {
     echo "<OPTION VALUE=\"$id\"> $name ($step) </OPTION>";
}
echo "</SELECT> ";
echo "<INPUT TYPE=\"submit\" NAME=\"Del\" VALUE=\"DELETE\"></td></tr></TABLE></FORM>";

echo "<hr>";

echo "<FORM ACTION=\"$PHP_SELF?topic=category.php\" METHOD=\"POST\">";
echo "<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"10\">";

echo "<TR><TD colspan=2>";
blueFont('Arial','Update a category');
echo "<TR><TD>";
echo "<SELECT NAME=\"CategoryID\" SIZE=\"1\">";
echo "<OPTION VALUE=\"\">Select an existing Category here";
mysql_data_seek($result,0);
while (list($id, $name, $step) = mysql_fetch_row($result)) {
     echo "<OPTION VALUE=\"$id\"> $name ($step) </OPTION>";
}
echo "</SELECT> ";
echo "</tr></td><tr><td>";
blueFont('Arial','Category<br>(leave empty to keep old one)');
echo "</td><td><INPUT TYPE=\"text\" name=\"Category\"></td></tr>";
echo "</tr></td><tr><td>";
blueFont('Arial','Paging Step<br>(leave empty to keep old one)');
echo "</td><td><INPUT TYPE=\"text\" name=\"PagingStep\" size=2>";
echo " <INPUT TYPE=\"submit\" NAME=\"Mod\" VALUE=\"MODIFY\"></TABLE></FORM>";

adminFooter($Relative);
?>
