<?
session_start();
include("../opendb.php");
include("../test.php");

$re=mysqli_query($db,"select * from partmaster where code='$code'");
$rerow=mysqli_fetch_array($re);
$dt1=explode('-',$rerow[crdate]);
$dt2=explode('-',$rerow[lcdate]);

if($save)
{
 
 $crdate=$y.'-'.$m.'-'.$d;
 $lcdate=$y1.'-'.$m1.'-'.$d1;

$sql="update partmaster set pcode='$pcode',pname='$pname',bunit='$bunit',pcat='$pcat',acti='$acti',crdate='$crdate',
lcdate='$lcdate',subgp='$subgp',minod='$minod',snorm='$snorm' where code='$code'";
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error());

print "<script> opener.document.location='partmaster.php'; window.close()</script>";
return;
}
//$re=mysqli_query($db,"select * from configmaster");
//$row=mysqli_fetch_array($re);
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{background-color:steelblue;color:white}
</style>
<script>
this.resizeTo(750,270);
function valid()
{
 
 /*if(document.f1.tax.value.length<=0)
 {
   alert("Invalid Tax.");
   document.f1.tax.focus();
   return false;
 }*/

}
</script>

<center>
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td align=center bgcolor='white'>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<input type=hidden name='code' value='<?print $code?>'>
<table cellspacing=1 cellpadding=3 >
<th colspan=4><font size=3>EDIT PART MASTER</th>
<tr><td>Part Code</td><td><input type=text name='pcode'  size=20 value='<?print $rerow[pcode]?>'></td>
    <td>Part Name</td><td><input type=text name='pname'  size=20 value='<?print $rerow[pname]?>'></td></tr>
<tr><td>Base Unit </td><td><input type=text name='bunit'  size=20 value='<?print $rerow[bunit]?>'></td>
    <td>Part Category</td><td><input type=text name='pcat' size=20 value='<?print $rerow[pcat]?>'></td></tr>
<tr><td>Activated</td><td><select name='acti'>
<option><?print $rerow[acti]?></option>
<option>A</option><option>D</option></select></td>
    <td>Created On</td><td>dd <input type=text name='d' size=4 value='<?print $dt1[2]?>'> mm <input type=text name='m' size=4 value='<?print $dt1[1]?>'> yyyy <input type=text name='y' size=5 value='<?print $dt1[0]?>'></td></tr>

<tr><td>Last Changed</td><td>dd <input type=text name='d1' size=4 value='<?print $dt2[2]?>'> mm <input type=text name='m1' size=4 value='<?print $dt1[1]?>'> yyyy <input type=text name='y1' size=5 value='<?print $dt1[0]?>'></td>
<td>Subgroup</td><td><select name='subgp'  size=1>
<option><?print $rerow[subgp]?></option>
<?
$g=mysqli_query($db,"select * from subgroupmaster");
while($grow=mysqli_fetch_array($g))
{
print "<option>$grow[subname]</option>";
}
?>
</select>
</td>
    </tr>
<tr><td>Minimum Order Quantity</td><td><input type=text name='minod'  size=20 value='<?print $rerow[minod]?>'></td>
    <td>Stocking Norm</td><td><input type=text name='snorm'  size=20 value='<?print $rerow[snorm]?>'></td></tr>

<th colspan=4><input type=submit value='Save' name='save'> <input type=button value='Cancel' onClick=window.close()></td></tr>
</table>
</form>
</td></tr>
</table>
