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

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

$userID = $_POST['userID'];
//userID,filenames, dataadd,dataedit, datadelete,datashow,dataprint, dataexcelformat, activestatus FROM user_permission
$columns = array( 
// datatable column index  => database column name
	0 => 'id', 
	1 => 'dataadd',
	2 => 'dataedit',
    3 => 'datadelete',
	4 => 'datashow',
    5 => 'dataprint',
    6 => 'dataexcelformat',
    7 => 'id'
);

$sql = "SELECT id FROM user_permission where activestatus=1 and userID='$userID' ";
$query=mysqli_query($conn, $sql) or die("get product_master Data");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  

$sql = "SELECT userID,filenames, dataadd,dataedit, datadelete,datashow,dataprint, dataexcelformat, activestatus,id ";
$sql.=" FROM user_permission WHERE 1=1 and activestatus=1 and userID='$userID'";

$query=mysqli_query($conn, $sql) or die("customergriddata.php: get product_master Data");

$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("customergriddata.php: get product_master Data");
	
//userID,filenames, dataadd,dataedit, datadelete,datashow,dataprint, dataexcelformat, activestatus FROM user_permission


$data = array();
while( $row=mysqli_fetch_array($query) ) { 
	$nestedData=array(); 

	$nestedData[] = $row["filenames"];

	if($row['filenames']=='usersMaster') {
		$nestedData[]='-';	
		$nestedData[]='-';	
		$nestedData[]='-';	
		$nestedData[]='-';	
		$nestedData[]='-';	
		$nestedData[]='-';	

	}else {
    
   	$datashow  = ($row["datashow"]==1)?"checked":"";
	$nestedData[] = "<input type='checkbox' onclick='permissionShow(".$row['id'].",".$row['datashow'].",".$userID.")' value=".$row["datashow"]." ".$datashow." >";	
	
	$dataadd = ($row["dataadd"]==1)?"checked":"";
	$nestedData[] = "<input type='checkbox' onclick='permissionAdd(".$row['id'].",".$row['dataadd'].",".$userID.")' value=".$row["dataadd"]." ".$dataadd." >";
	
	$dataedit = ($row["dataedit"]==1)?"checked":"";
	$nestedData[] = "<input type='checkbox' onclick='permissionEdit(".$row['id'].",".$row['dataedit'].",".$userID.")' value=".$row["dataedit"]." ".$dataedit." >";
	
	$datadelete = ($row["datadelete"]==1)?"checked":"";
	$nestedData[] = "<input type='checkbox' onclick='permissionDelete(".$row['id'].",".$row['datadelete'].",".$userID.")'  ".$datadelete." >";
	
	$dataprint = ($row["dataprint"]==1)?"checked":"";
	$nestedData[] = "<input type='checkbox' onclick='permissionPrint(".$row['id'].",".$row['dataprint'].",".$userID.")'  ".$dataprint." >";
	
	$dataexcelformat = ($row["dataexcelformat"]==1)?"checked":"";
	$nestedData[] = "<input type='checkbox' onclick='permissionExcelFormat(".$row['id'].",".$row['dataexcelformat'].",".$userID.")'  ".$dataexcelformat." >";
	}
	$data[] = $nestedData;
}

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

echo json_encode($json_data);  

?>
