<?php
include("../../include/db.php");
error_reporting(0);
function check_group($group_name)
{
	$Isql=mysql_query("select * from group_creation where sub_group_name='$group_name'");
	$rscount=mysql_num_rows($Isql);
	return $rscount;
}

function check_group_edit($group_name)
{
	$sql_query="select * from group_creation where sub_group_name='$group_name'";
$rs=mysql_query($sql_query);
 $rscount1=mysql_num_rows($rs);
 if($rscount1!=0)
 {
 while($rsdata=mysql_fetch_object($rs))
 {
 $id=$rsdata->sub_grpid;
 } 
	return $id;
 }
 }
 
 /********************************** ADD  QUERY ***************************************/
if(($_POST['action']=="ADD")) 
{
$group_name=$_POST['group_name'];
$group_id=$_POST['group_id'];
$group_type=$_POST['group_type'];
$group_remarks=$_POST['group_remarks'];
$create_date=date('Y-m-d');
$check_item=check_group($group_name);
if($check_item==0)
{
 $Insql=mysql_query("insert into group_creation(sub_group_name,group_id,group_remarks,create_date)values('$group_name','$group_id','$group_remarks','$create_date')");
echo "Added Successfully";




}
else
{
echo "Already Exists";
}
}
/********************************** UPDATE QUERY ***************************************/
if(($_POST['action']=="EDIT"))
{
$edit_id = $_POST['edit_id']; 
$group_name=$_POST['group_name'];
$group_id=$_POST['group_id'];
$group_remarks=$_POST['group_remarks'];
$create_date=date('Y-m-d');
$check_item=check_group_edit($group_name);
if(($check_item==$_POST['edit_id'])||($check_item==''))
{

 $Insql=mysql_query("update group_creation set sub_group_name='$group_name',group_id='$group_id',group_remarks='$group_remarks',create_date='$create_date' where  sub_grpid='$_POST[edit_id]'");
}
else
{
	echo "Already Exists";
}
}
/********************************************DELETE*****************************************************************/
if($_POST['action']=="delete_groups")
{ 		
  $id1=$_POST[id]; 
		    $delete3="delete from group_creation where sub_grpid='$_POST[id]'";
			mysql_query($delete3);
			echo "<script>alert('Deleted Succesfully')</script>";
			include("group_entry_list.php");
}


?>