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

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

//cname, city, pincode, mobile, gst_type, ccode, open_balance
$columns = array( 
// datatable column index  => database column name
	0 => 'username', 
	1 => 'password',
	2 => 'Permisson',
	3 => 'id'
);

$sql = "SELECT id FROM user_login";
$query=mysqli_query($conn, $sql) or die("expensegriddata.php: get expense_master Data");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  

$sql = "SELECT username,password,loginstatus,flag,user_permisson,id ";
$sql.=" FROM user_login WHERE 1=1";
if( !empty($requestData['search']['value']) ) {   

	$sql.=" AND ( username LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" AND ( password LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" AND ( user_permisson LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR id LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("expensegriddata.php: get expense_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("expensegriddata.php: get expense_master Data");
	
//cname, city, pincode, mobile, gst_type, ccode, open_balance
$data = array();
while( $row=mysqli_fetch_array($query) ) { 
	$nestedData=array(); 

	$nestedData[] = $row["username"];
	$nestedData[] = $row["password"];
	$nestedData[] = $row["user_permisson"];

	if ($row['id'] == 1) {
	$nestedData[] = "<a class='btn btn-primary'  disabled>Disabled</a>";
	} else {
		$nestedData[] = "<a href='usersMasterEdit.php?id=".$row['id']."' id='usersMaster_".$row['id']."' class='btn btn-primary'  >Edit</a>&nbsp<a href='usersMasterPermission.php?id=".$row['id']."' id='usersMaster_".$row['id']."' class='btn btn-primary'  >Permission</a>";

	}
	
	$data[] = $nestedData;
}

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

echo json_encode($json_data);  

?>
