<?
session_start();
$brcode = $_SESSION['brcode'];
include ("includes/top.php");
?>
<head>
<script>
function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }
 if(yy.indexOf('"')>-1) 
  {
    alert("\" is not allowed");
    abc.value='';
  }
 if(yy.indexOf('&')>-1) 
  {
    alert("\& is not allowed");
    abc.value='';
  }
}
</script>

</head>
<?
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login'); parent.document.location='ind.php' </script>";
 return;
}
include("../opendb.php");
include("../test.php");
if($_REQUEST['add'])
{
    $agrp = $_REQUEST['agrp'];
    if(strlen($agrp)<=0)
    {
        print "In sufficient entry"; 
        return;
    }
    $re=mysqli_query($db,"select * from astgroup where agrp='$agrp' and brcode='$brcode'");
    if(mysqli_num_rows($re)>0)
    {
        print "Duplicate entry $agrp";
        return;
    }
    else
    {
        mysqli_query($db,"insert into astgroup values('".addslashes($agrp)."','$brcode')");
    }
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
body,td{font-family:arial narrow;font-size:14}
th{background-color:silver}
</style>
<center>
<h3>Asset Group Master</h3>
<form action='<?print $PHP_SELF?>'>
<table>
<tr><td>Group Name </td><td><input type=text name='agrp' size=40 onKeyUp=chkey(this)></td>
 <td><input type=submit value='Add' name='add'></td></tr>
</table>
</form>
<br>
<table border=1>
<?
$i=1;
$res=mysqli_query($db,"select * from astgroup where brcode='$brcode' order by agrp");
 while($row=mysqli_fetch_array($res))
 {
  print "<tr><td>".$i++."</td><td>$row[0]</td></tr>";
 }
?>
