<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
 $tbl2='esipfbr'.$brcode;
if($save)
{
 $tbl='esipfgrp'.$brcode;
 mysqli_query($db,"create table $tbl (grp varchar(20) primary key)");
 mysqli_query($db,"insert into $tbl values('$grp')")or die(mysqli_error());
} 
if($set)
{
 $sql="create table $tbl2 (grp varchar(100), br varchar(100) primary key)";
 mysqli_query($db,$sql);
 foreach($br as $a)
 {
   $sql="insert into $tbl2 values('$grp','$a')";
   mysqli_query($db,$sql)or die(mysqli_error());
 }
}

?>
<head>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:e3ecd2}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<center>
<form action='<?print $PHP_SELF ?>' method='post'>
<table>
<tr><td>Group </td><td><input type=text name='grp' size=20></td>
 <td><input type=submit value='Save' name='save'></td>
</tr>
</table>
</form>
<hr>
<form action='<?print $PHP_SELF ?>' method='post'>
<table border=1>
<tr><td>Select Group </td><td><select name='grp'>
<?
 $tbl='esipfgrp'.$brcode;
$re=mysqli_query($db,"select * from $tbl order by grp")or die(mysqli_error());
while($row=mysqli_fetch_array($re))
{
 print "\n<option>$row[0]</option>";
}
?>
</select></td></tr>
<?
$re1=mysqli_query($db,"select brname from br_master where brcode='$brcode' order by brname");
while($row1=mysqli_fetch_array($re1))
{
 print "\n<tr><td><input type=checkbox name='br[]' value='$row1[0]'></td><td>$row1[0]</td></tr>";
}
?>
<tr><td colspan=2 align=center><input type=submit value='Set Branch' name='set'></td></tr>
</table>
</form>
<hr>
<form action='<?print $PHP_SELF ?>' method='post'>
<table border=1>
<?
$re2=mysqli_query($db,"select * from $tbl2 order by grp");
while($row=mysqli_fetch_array($re2))
{
 print "\n<tr><td>$row[0]</td><td>$row[1]</td></tr>";
}
?>
</td></tr>
</table>

