<?
$subgname=$_REQUEST['subgname'];
$nature=$_REQUEST['nature'];
$ungrp=$_REQUEST['ungrp'];
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("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;
}
$level=0;
$sql="insert into acgroups(gname,nature,headgroup,level,type,code) values('$subgname','$nature','$ungrp','$level','udf','$code')";
print $sql;
mysqli_query($db,$sql) or die(mysqli_error());
include('acgroup.php');
?>
