| Current Path : /var/www/html/mmishra/istore/ |
| Current File : /var/www/html/mmishra/istore/stitems.inc |
<h3>Item Specification</h3>
<?php
$tbl = "st_items";
$id = $_REQUEST["id"];
$code = $_POST["code"];
$description = $_POST["description"];
$category = $_REQUEST["category"];
$subcategory = $_REQUEST["subcategory"];
$dated = date("Y-m-d");
if ($_POST["submit"] == 'SAVE') {
if (mysql_num_rows(mysql_query("select * from $tbl where id=$id"))) {
mysql_query("update $tbl set code='$code',description='$description',subcategory=$subcategory,category=$category,loginID='$user'
where id=$id");
} else {
mysql_query("insert into $tbl(code,description,subcategory,category,loginID)
values('$code','$description',$subcategory,$category,'$user')");
}
} if ($_POST["submit"] == 'DELETE') {
mysql_query("delete from $tbl where id=$id");
}
echo "Select category <select name='category' onchange=\"javascript: document.location.href='?pg=$pg&category='+this.value\">
<option value=''></option>";
$rs = mysql_query("select id,code from st_category order by code");
while ($o = mysql_fetch_object($rs)) {
echo "<option value='$o->id'";
if ($o->id == $category) echo " selected";
echo ">$o->code</option>";
}
echo "</select>
item <select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&category=$category&subcategory='+this.value\">
<option value=''></option>";
$rs = mysql_query("select id,code,item_type from st_subcategory where category=$category order by code");
while ($o = mysql_fetch_object($rs)) {
echo "<option value='$o->id'";
if ($o->id == $subcategory) echo " selected";
echo ">$o->code ($o->item_type)</option>";
}
echo "</select>
<br><br><center>";
if ($category && $subcategory) {
echo "<table width='80%' border='1' style='border-collapse: collapse'>
<tr><th>No</th><th>Code</th><th>Specification (Make/model etc.)</th><th>Dated</th></tr>
<tr><td><a name='new'>+</a></td>";
if (!$id) {
echo "<td><input type='text' name='code' size='30' value=''></td>
<td><input type='text' name='description' size='50' value=''></td>
<td>$dated<input type='hidden' name='id' value='0'></td></tr>
<tr><th colspan='4'><input type='submit' name='submit' value='SAVE'></th>";
} else {
echo "<td colspan='3'><a href='?pg=$pg&category=$category&subcategory=$subcategory&id=#new'>Item</a></td>";
}
echo "</tr>";
//existing records
$rs = mysql_query("select * from $tbl where category=$category and subcategory=$subcategory order by code");
while ($o = mysql_fetch_object($rs)) {
$i++;
$j = $i - 2;
echo "<tr><td><a name='$i' href='?pg=$pg&id=$o->id&category=$category&subcategory=$subcategory#$j'>$i</a></td>";
if ($o->id == $id) {
echo "<td><input type='text' name='code' size='30' value='$o->code'></td>
<td><input type='text' name='description' size='50' value='$o->description'></td>
<td>$dated<input type='hidden' name='id' value='$o->id'></td></tr>
<tr><th colspan='3'><input type='submit' name='submit' value='SAVE'></th>
<th><input type='submit' name='submit' value='DELETE'></th>";
} else {
echo "<th>$o->code</th><td>$o->description</td><td>$o->dateCreation</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
</center>