<?php
include("../include/db.php");
/*********************************Check item********************************************************/

function check_roll_size($roll_size_name)
{
	$Isql=mysql_query("select * from roll_size_creation where roll_size_name='$roll_size_name'");
	$rscount=mysql_num_rows($Isql);
	return $rscount;
}
/*********************************Check item for edit********************************************************/

function check_party_edit($roll_size_name)
{
	$sql_query="select * from roll_size_creation where roll_size_name='$roll_size_name'";
$rs=mysql_query($sql_query);
 $rscount1=mysql_num_rows($rs);
 if($rscount1!=0)
 {
 while($rsdata=mysql_fetch_object($rs))
 {
 $id=$rsdata->id;
 } 
	return $id;
 }
 }
 
 /********************************** ADD  QUERY ***************************************/
if(($_POST['action']=="ADD")) 
{
$roll_size_name=ucfirst($_POST['roll_size_name']);
$roll_size_remarks=$_POST['roll_size_remarks'];
$create_date=date('Y-m-d');
$check_item=check_party_edit($roll_size_name);
if($check_item==0)
{
$Insql=mysql_query("insert into roll_size_creation(roll_size_name,roll_size_remarks,create_date)values('$roll_size_name','$roll_size_remarks','$create_date')");
echo "Added Successfully!!";
}
else
{
echo "Already Exists!!";
}
}
/********************************** UPDATE QUERY ***************************************/
if(($_POST['action']=="EDIT"))
{
$edit_id = $_POST['edit_id']; 
$roll_size_name=ucfirst($_POST['roll_size_name']);
$roll_size_remarks=$_POST['roll_size_remarks'];
$create_date=date('Y-m-d');
$check_item=check_party_edit($roll_size_name);

if(($check_item==$_POST['edit_id'])||($check_item==''))
{
$Insql=mysql_query("update roll_size_creation set roll_size_name='$roll_size_name',roll_size_remarks='$roll_size_remarks',create_date='$create_date' where  id='$_POST[edit_id]'");
echo "Updated Successfully!!";
}
else
{
	echo "Already Exists";
	}
}
/********************************************DELETE*****************************************************************/
if($_POST['action']=="delete_roll_size")
{ 		 
		   $delete2="delete from roll_size_creation where id='$_POST[id]'";
			mysql_query($delete2);
			echo "<script>alert('Deleted Succesfully')</script>";
			include("roll_size_entry_list.php");
}


?>