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

function check_job_type($job_type_name)
{
	$Isql=mysql_query("select * from job_type_creation where job_type='$job_type_name'");
	$rscount=mysql_num_rows($Isql);
	return $rscount;
}
/*********************************Check item for edit********************************************************/

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

if(($check_item==$_POST['edit_id'])||($check_item==''))
{
$Insql=mysql_query("update job_type_creation set job_type='$job_type_name',job_type_status='$job_type_status',printer_production_status='$printer_production_status',fusing_production_status='$fusing_production_status',create_date='$create_date' where  job_id='$_POST[edit_id]'");
echo "Updated Successfully!!";
}
else
{
	echo "Already Exists";
	}
}
/********************************************DELETE*****************************************************************/
if($_POST['action']=="delete_job_type")
{ 		 
		   $delete2="delete from job_type_creation where job_id='$_POST[id]'";
			mysql_query($delete2);
			echo "<script>alert('Deleted Succesfully')</script>";
			include("job_type_entry_list.php");
}


?>
