<?php 
ob_clean();
include("../../../include/startup.php"); 
if(isset($_REQUEST['action']) && $_REQUEST['action']=='add_ess_heading'){
	////////////// For Insert and Update ///////////////////////////
	utility::addslashesOnAllInput(array("query_string"));
    
	$page_action = $_REQUEST['page_action'];	
	$id = $_REQUEST['id'];	
	$ess_heading= $_REQUEST['ess_heading'];
   
	$created_on = date("Y-m-d H:i:s");
	$created_by = $_SESSION["user_id"];
	$updated_by = $_SESSION["user_id"];
		
	if($page_action == "add"){
		$sql= "INSERT INTO ess_heading(heading,created_on,created_by,updated_by) VALUES('$ess_heading','$created_on','$created_by','$updated_by')";
		mysqli_query($conn,$sql);
	}else{
		$sql= "UPDATE ess_heading SET heading = '$ess_heading',updated_by = '$updated_by' WHERE id = '$id' ";
		mysqli_query($conn,$sql);
	}
	$returnArray["status"] = "success";
	echo json_encode($returnArray);
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='delete_ess_heading'){
	$post_out_id = $_REQUEST['post_out_id'];
	mysqli_query($conn,"DELETE FROM ess_heading WHERE id = '$post_out_id'");
	$returnArray["status"] = "success";
	echo json_encode($returnArray);
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='edit_ess_heading'){
	$id = $_REQUEST['post_out_id'];
	
	$sql= "SELECT * FROM ess_heading WHERE id = '$id' ";
    $result_edit = mysqli_query($conn,$sql);
    $row_edit = mysqli_fetch_assoc($result_edit);
	
	$data_array = array();
	$dataArray["status"] = 0;
	$dataArray["ess_heading"] = $row_edit['heading'];
	$dataArray["status"]		= 1;
	echo json_encode($dataArray);
    //echo json_encode($returnArray, JSON_FORCE_OBJECT);
}else{
	////////////// For Listing data through JSON ///////////////////////////
    $query_for_ess_heading = "SELECT * FROM ess_heading ";
	$sql_for_ess_heading = mysqli_query($conn,$query_for_ess_heading);
	$result_for_ess_heading = mysqli_num_rows($sql_for_ess_heading);
	$post_out = "";
	if($result_for_ess_heading > 0){
		$post_out .= '{';
		$post_out .= '"data" : [';
		while($row_for_ess_heading = mysqli_fetch_array($sql_for_ess_heading)){
			$post_out .= '{"heading":"'  . $row_for_ess_heading['heading']. '",';
			$post_out .= '"id":"'  . $row_for_ess_heading['id'] . '"},';
		}
		$post_out = substr($post_out,0,-1);
		$post_out .= "]";
		$post_out .= '}';
	}else{
		$post_out .= '{';
		$post_out .= '"data" : [';
		$post_out .= "]";
		$post_out .= '}';
	}
	echo $post_out;
}
die;
?>