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

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

function check_party_edit($measurement_name)
{
	$sql_query="select * from measurement_creation where measurement_name='$measurement_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")) 
{
$measurement_name=ucfirst($_POST['measurement_name']);
$measurement_remarks=$_POST['measurement_remarks'];
$create_date=date('Y-m-d');
$check_item=check_party_edit($measurement_name);
if($check_item==0)
{
$Insql=mysql_query("insert into measurement_creation(measurement_name,measurement_remarks,create_date)values('$measurement_name','$measurement_remarks','$create_date')");
echo "Added Successfully!!";
}
else
{
echo "Already Exists!!";
}
}
/********************************** UPDATE QUERY ***************************************/
if(($_POST['action']=="EDIT"))
{
$edit_id = $_POST['edit_id']; 
$measurement_name=ucfirst($_POST['measurement_name']);
$measurement_remarks=$_POST['measurement_remarks'];
$create_date=date('Y-m-d');
$check_item=check_party_edit($measurement_name);

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


?>