<?php
require_once("config/configDB.php"); 

// storing  request (ie, get/post) global array to a variable  
$requestData= $_REQUEST;


$userpermissionEdit 	= $_POST['userpermissionEdit'];
$userpermissionDelete 	= $_POST['userpermissionDelete'];
//cname, city, pincode, mobile, gst_type, ccode, open_balance
$columns = array( 
// datatable column index  => database column name
	0 => 'id', 
	1 => 'areaname',
	2 => 'area_tamil',
   
    3 => 'areacode'
);

$sql = "SELECT id FROM area_master where isdelete=1";
$query=mysqli_query($conn, $sql) or die("productgriddata.php: get product Data step 1");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  

$sql = "SELECT areacode, areaname,isdelete, area_tamil, id FROM area_master WHERE 1=1 ";
if( !empty($requestData['search']['value']) ) {   

	$sql.=" AND ( id  LIKE '".$requestData['search']['value']."%' ";    		
	$sql.=" OR areaname LIKE '".$requestData['search']['value']."%' ";
   
    $sql.=" OR areacode LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("productgriddata.php: get product Data step 2");
$totalFiltered = mysqli_num_rows($query); 

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";

$query=mysqli_query($conn, $sql) or die("productgriddata.php: get product Data step 3");
	
//cname, city, pincode, mobile, gst_type, ccode, open_balance
$data = array();
while( $row=mysqli_fetch_array($query) ) { 
	$nestedData=array(); 

	$nestedData[] = $row["id"];
	$nestedData[] = $row["areacode"];
    //$nestedData[] = $row["collectiondate"];
   
	$nestedData[] = $row["areaname"];
	$nestedData[] = $row["area_tamil"];
 
	
	$edit  = "";
	if($userpermissionEdit==1) {
		$edit .="<a href='areaMasterEdit.php?id=".$row['id']."' id='productMaster_".$row['id']."' class='btn btn-primary'>Edit</a>&nbsp";
	}

	$deleted_status=$row["isdelete"];
	
	
	$Delete  = "";
	
	
	if($deleted_status=="1")
	{
				//$Delete  = "";
	if($userpermissionEdit==1) {
		$Delete .="<a   class='btn btn-danger '  href='fetchAjaxData/deleteareamasterData.php?pid=".$row['id']."'>De-Activate</a>";
	}

	}
	
	else
	{
		
	if($userpermissionEdit==1) {
		$Delete .="<a   class='btn btn-success '  href='fetchAjaxData/activateareamasterData.php?pid=".$row['id']."'>Activate</a>";
	}
	}
	
	$nestedData[] = $edit."&nbsp".$Delete;
	
	$data[] = $nestedData;
}

$json_data = array(
			"draw"            => intval( $requestData['draw'] ),   
			"recordsTotal"    => intval( $totalData ),  
			"recordsFiltered" => intval( $totalFiltered ), 
			"data"            => $data   
			);

echo json_encode($json_data);  

?>
