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


	$obj = new Datatable($conn);

	$obj->aColumns 		= array('driver_code', 'name', 'city', 'state', 'contact', 'status', 'created_id', 'file_img');
    $obj->eColumns 		= array('id');
    $obj->sIndexColumn 	= "id";
    $obj->sTable 		= "driver_mst";
    //$obj->myWhere 		= "WHERE company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND DATE(created_datetime)>='".$_SESSION['from_year']."' AND DATE(created_datetime)<='".$_SESSION['to_year']."'";
    $obj->datatable_process();
    
    $cou = 0;
    if(isset($_GET['iDisplayStart'])) {
    	$cou = $_GET['iDisplayStart'];
    }
    $master_user = combine(getAllRecords('users'), 'id', 'name');
    while ($aRow = mysqli_fetch_array($obj->rResult)) {

    	$temp_arr = array();

		$temp_arr[] = ++$cou;
		$temp_arr[] = $aRow['driver_code'];
		$temp_arr[] = $aRow['name'];
		$temp_arr[] = $aRow['contact'];
		$temp_arr[] = $aRow['city'];
		$temp_arr[] = $aRow['state'];
		$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;
		$temp_arr[] = @$master_user[$aRow['created_id']];		
		$str = '';

		if($aRow['file_img'] != ''){
             $str .= '<a href="assets/upload/driver/'.$aRow['file_img'].'" name="edit" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="IMAGE" target="_BLANK"><em class="fa fa-picture-o"></em></a>&nbsp;';
        }

		if( hasPermission($_SESSION['user_detail']['role_id'], 'accountm_edit') ) {
		$str .= '<a href="index.php?page=driver/add.php&eid='.$aRow['id'].'" name="edit" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="EDIT DRIVER...!!"><em class="fa fa-pencil"></em></a>&nbsp;';
		}

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

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

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