<?
session_start();
include("../opendb.php");
include("../test.php");
if($save)
{
$ch=mysqli_query($db,"select * from itemmaster where pno='$pno'");
if(mysqli_num_rows($ch)>0)
{
print "<script> alert('Duplicate Entry'); document.location='itemmaster1.php'</script>";
return;
}
$ch=mysqli_query($db,"select * from itemmaster where pname='$pname'");
if(mysqli_num_rows($ch)>0)
{
print "<script> alert('Duplicate Part Name.'); document.location='itemmaster1.php'</script>";
return;
}

 $code=substr($pno,0,3).substr(time(),7,3).date("s"); 
 $code=str_replace(' ','-',$code);

$sql="insert into itemmaster values('$subgp','$pno','$pname','$unit','$pcat','$code')";
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error($db));

print "<script> document.location='itemmaster1.php?'</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>
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()">
<table cellspacing=1 cellpadding=3 >
<th colspan=4><font size=3>ITEM MASTER</th>
<tr><td>Sub Group</td><td><select name='subgp' size=1>
<?
$sb=mysqli_query($db,"select subname from subgroupmaster where gname='$gp'");
while($sbrow=mysqli_fetch_array($sb))
{
print "<option>$sbrow[0]</option>";
}
?>
</select>
</td>
    
 <td>Part No. </td><td><input type=text name='pno'  size=20></td>
    </tr>
<tr><td>Part Name </td><td><input type=text name='pname'  size=20></td>
    
<td>Unit </td><td><input type=text name='unit'  size=20></td>
    </tr>
<tr><td>Part Category </td><td><input type=text name='pcat'  size=20></td>
    </tr>
<th colspan=4><input type=submit value='Save' name='save'></td></tr>
</table>
</form>
</td></tr>
</table>
<br>
<table cellspacing=1 cellpadding=5 bgcolor='orange'>
<th>No <th>Subgroup <th>Part No. <th>Part Name<th>Unit<th>Part Cat<th>Edit<th>Del
<?
$i=1;
$res=mysqli_query($db,"select * from itemmaster");
while($row=mysqli_fetch_array($res))
{
 print "<tr bgcolor='white' onMouseOver=bgColor='b8d7b4'; onMouseOut=bgColor='white'>";
 print "<td>".$i++."</td><td>$row[subgp]</td><td>$row[pno]</td>";
 print "<td>$row[pname]</td><td>$row[unit]</td><td ALIGN=CENTER>$row[pcat]</td>";
 print "<td><input type=button value='Edit' onClick=window.open('edititemmast.php?code=$row[code]',menubar=false,resizable=false)></td>";
 print "<td><input type=button value='Del' name='del' onClick=delfun('$row[code]')></td></tr>";
}
?>
</table>

<script>
 function delfun(x)
 {
  if (confirm('do you want to delete '+x+' ?'))
   document.location='delitemmaster.php?code='+x;
 }
  
</script>
