<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
$subgname=$_REQUEST['subgname'];
$ungrp=$_REQUEST['ungrp'];

$nature=$_REQUEST['nature'];
$level=$_REQUEST['level'];
$code=$_REQUEST['code'];
$udf=$_REQUEST['udf'];


 if(strlen($subgname)<=0)
  {
    print "<script> alert('Insufficient Entry'); history.back(1); </script>";
    return;
  }
 if(strlen($ungrp)<=0)
  {
    print "<script> alert('Insufficient Entry'); history.back(1); </script>";
    return;
  }

$code=substr($subgname,0,3).substr(time(),7,3);
$code=str_replace(' ','-',$code);
 include_once("opendb.php");
  $result=mysqli_query($db,"select * from acgroups where gname='$subgname' or headgroup='$subgname'");
   if(mysqli_num_rows($result)>0)
  {
    print "<script> alert('Duplicate Entry'); history.back(1); </script>";
    return;
  }

$sql="insert into acgroups(gname,nature,headgroup,level,type,code) values('$subgname','$nature','$ungrp','$level','udf','$code')";
 mysqli_query($db,$sql) or die(mysqli_error($db));
 include('acgroup.php');
?>
