<?php 
	include("../config.php");
	include("../Datatable.php");


	$obj = new Datatable($conn);

	$obj->aColumns 		= array('name', 'email', 'mobile', 'username', 'password', 'role_id', 'status');
    $obj->eColumns 		= array('id');
    $obj->sIndexColumn 	= "id";
    $obj->sTable 		= "users";
    $obj->datatable_process();
    
    $cou = 0;
    if(isset($_GET['iDisplayStart'])) {
    	$cou = $_GET['iDisplayStart'];
    }
    while ($aRow = mysqli_fetch_array($obj->rResult)) {
        $temp_arr = array();

        $role     = "SELECT * FROM roles WHERE id = '".$aRow['role_id']."'";
        $role_res = mysqli_query($conn,$role);
        $row_row  = mysqli_fetch_array($role_res);

		$temp_arr[] = ++$cou;
		$temp_arr[] = $aRow['name'];
		$temp_arr[] = $aRow['username'];
		$temp_arr[] = $row_row['name'];
		$temp_arr[] = $aRow['email'];
		$temp_arr[] = $aRow['mobile'];
		$label = '';
		if($aRow['status'] == '0'){ 
			$label .='<span class="label label-md label-warning">ACTIVE</span>';
		}else{
			$label .='<span class="label label-md label-danger">IN-ACTIVE</span>';
		}
		
		$temp_arr[] = $label;
		
		$str = '';
		if( hasPermission($_SESSION['user_detail']['role_id'], 'user_edit') ) {
		$str .= '<a href="index.php?page=user_management/edit.php&eid='.$aRow['id'].'" name="edit" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="EDIT USER...!!"><em class="fa fa-pencil"></em></a>&nbsp;';
		}

		if( hasPermission($_SESSION['user_detail']['role_id'], 'user_delete') ) {
		$str .= '<button type="button" class="btn btn-danger delete_data" id="'.$aRow["id"].'" data-toggle="tooltip" data-placement="top" title="DELETE USER..!!" onclick="confirmDelete(this);"><em class="fa fa-trash"></em></button>';
		}
		$temp_arr[] = $str;

        $obj->output['aaData'][] = $temp_arr;
    }

    echo json_encode($obj->output);
    exit();
?>