<? session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
if($submit)
{
  if(strlen($itname)<=0)
  {
     print "<script> alert('In sufficient entry'); </script>";
     return;
  }
 $code=substr($itname,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);
 $re=mysqli_query($db,"select * from itemmaster where itname='$itname' and brcode='$brcode'");
 if(mysqli_num_rows($re)>0)
 {
    print "<script> alert('Duplicate entry'); history.back(1);  </script>";
    return;
  }
 $sql="insert into itemmaster values('$code','$itname','$brcode')";
 mysqli_query($db,$sql) or die(mysqli_error());
}
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>

<CENTER>
<BR>
<FORM ACTION='<?print $PHP_SELF?>' METHOD='POST'>
<table cellspacing=1 cellpadding=1 bgcolor=green>
 <tr><td align=center>
  <table>
    <tr><td colspan=2 align=center BGCOLOR='BROWN'><FONT COLOR='IVORY'><B>ITEM MASTER</TD></TR>
    <tr><td>Item Name </td><td><input type=text name='itname' size=40></td></tr>
    <tr><td colspan=2 align=center><input type=submit name='submit' value='ADD'>
    <input type=button value='CANCEL' onClick=document.location='../blank.html'></td></tr>
  </table>
 </td></tr>
</table>

<br>
<table border=1>
<th>No <th>Item Name <th>Edit
<?
 $re=mysqli_query($db,"select * from itemmaster where brcode='$brcode' order by itname");
  $i=1;
 while($row=mysqli_fetch_row($re))
  {
    print "<tr><td>".$i++."</td><td>$row[1]</td> <td><a href='edititm.php?code=$row[0]'> <img src='../img/signit.gif' border=0></a> </td></tr>";
  }
?>
</table>
