<?
require "./Cart.php";

adminHeader("$Company","Update An Item");

if (!empty($ItemID)) {
     $sql =    'SELECT ItemID, ItemSKU, ItemName, Category, ItemDescription, ItemGraphic, ShippingCost, ItemCost, PaymentCycle ' .
          "FROM Items WHERE ItemID = '$ItemID'";
     $result=mysql_query($sql);
     list($ItemID, $ItemSKU, $ItemName, $Category, $ItemDescription, $ItemGraphic, $ShippingCost, $ItemCost, $PaymentCycle) = mysql_fetch_row($result);
     mysql_free_result($result);
}

if (empty($ItemID))
     blueFont("Arial","Type the new data into the boxes, and then SUBMIT!<BR><BR>");

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

if (!empty($ItemID))
     echo "<INPUT TYPE=\"hidden\" NAME=\"II\" VALUE=\"$ItemID\">";

echo "<TR><TD>";
blueFont("Arial","Item ID (SKU)<BR>");
echo "<INPUT TYPE='text' NAME=\"ItemSKU\" SIZE=\"40\" VALUE=\"$ItemSKU\"></TD></TR><TR><TD>";
blueFont("Arial","Item Name<BR>");
echo "<INPUT TYPE=\"text\" NAME=\"ItemName\" SIZE=\"40\" VALUE=\"$ItemName\"></TD></TR>";

echo "<TR><TD>";
blueFont("Arial","Select A Category<BR>");
echo "<SELECT NAME=\"Category\" SIZE=\"1\">";
$result=mysql_query("SELECT CategoryID, Category FROM Category ORDER BY Category");
while (list($CategoryID, $CategoryName) = mysql_fetch_row($result)) {
     $selected = ($Category == $CategoryID) ? 'SELECTED' : '';
     echo "<OPTION VALUE=\"$CategoryID\" $selected> $CategoryName </OPTION>";
}
mysql_free_result($result);
echo "</SELECT></TD></TR>";


echo "<TR><TD COLSPAN='2'>";
blueFont("Arial","ItemDescription<BR>");
$ID=ereg_replace("\"","&quot;",$ID);
echo "<TEXTAREA NAME=\"ItemDescription\" ROWS=\"10\" COLS=\"50\" WRAP>$ItemDescription</TEXTAREA></TD></TR>";

echo "<TR><TD>";
blueFont("Arial","Item Cost<br>");
echo "<INPUT TYPE=\"text\" NAME=\"ItemCost\" SIZE=\"10\" VALUE=\"$ItemCost\"><br>";
blueFont("Arial","<br>Payment Cycle<br>");
echo "<SELECT name=\"PaymentCycle\">";
$selected = ($PaymentCycle == 'O') ? 'selected' : '';
echo "<option value=\"O\" $selected> One Time";
$selected = ($PaymentCycle == 'W') ? 'selected' : '';
echo "<option value=\"W\" $selected> Weekly";
$selected = ($PaymentCycle == 'M') ? 'selected' : '';
echo "<option value=\"M\" $selected> Monthly";
$selected = ($PaymentCycle == 'Y') ? 'selected' : '';
echo "<option value=\"Y\" $selected> Yearly";
echo "</SELECT>";

blueFont("Arial","<br><br>Shipping Cost<BR>");
echo "<INPUT TYPE=\"text\" NAME=\"ShippingCost\" SIZE=\"10\" VALUE=\"$ShippingCost\">";
echo "</td></tr>";

echo "<TR><TD COLSPAN='2'>";
blueFont("Arial","Item Graphic<BR>");

echo "<SELECT NAME=ItemPicture>\n";
echo "<OPTION VALUE=\"\">SELECT A PICTURE HERE OR ENTER HTML BELOW\n";
$handle=opendir("$images");
while ($f = readdir($handle))
     if ($f != '.' && $f != '..')
          echo '<option value="'.$f.'">'.$f."\n";
closedir($handle);
echo "</SELECT><BR>\n";

blueFont("Arial","Html<BR>");
echo "<TEXTAREA NAME=\"ItemGraphic\" ROWS=\"10\" COLS=\"50\" WRAP>$ItemGraphic</TEXTAREA></TD></TR>";

echo "<TR><TD COLSPAN=\"2\" ALIGN=\"center\"><INPUT TYPE=\"submit\" NAME=\"Update\" VALUE=\"Submit\"></FORM></TABLE>";

adminFooter($Relative);
?>
