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

	$where = '';
	$type  = $_GET['type'];
	if($type != '' && $type != 'null' && !empty($type)){
        if($type == 'P'){
			$where .= ' AND  pan_img = ""';
		}else if($type == 'R'){
			$where .= ' AND  rc_img = ""';
		}
    }
	$obj = new Datatable($conn);
	$obj->aColumns 		= array('truck_code', 'truck_no', 'o_name', 'o_contact', 'o_pan', 'rc_no', 'pan_img', 'rc_img', 'created_id');
    $obj->eColumns 		= array('id');
    $obj->sIndexColumn 	= "id";
    $obj->sTable 		= " truck_mst";
    $obj->myWhere 		= ' WHERE 1=1 ' . $where;
    $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();

		if($aRow['rc_img'] == ''){
			$rflag = '<i class="fa fa-times" aria-hidden="true" style="color:red;"></i>';
		}else{
			$rflag = '<a href="assets/upload/rc/'.$aRow['rc_img'].'" target="_blank"><i class="fa fa-check" aria-hidden="true" style="color:green;"></i></a>';
		}

		if($aRow['pan_img'] == ''){
			$pflag = '<i class="fa fa-times" aria-hidden="true" style="color:red;"></i>';
		}else{
			$pflag = '<a href="assets/upload/pan/'.$aRow['pan_img'].'" target="_blank"><i class="fa fa-check" aria-hidden="true" style="color:green;"></i></a>';
		}

		$temp_arr[] = ++$cou;
		$temp_arr[] = $aRow['truck_code'];
		$temp_arr[] = $aRow['truck_no'];
		$temp_arr[] = $aRow['o_name'];
		$temp_arr[] = $aRow['o_contact'];
		$temp_arr[] = $pflag;
		$temp_arr[] = $rflag;
		$temp_arr[] = @$master_user[$aRow['created_id']];
		$str = '';
		if( hasPermission($_SESSION['user_detail']['role_id'], 'truck_edit') ) {
		$str .= '<a href="index.php?page=truck_mst/edit.php&eid='.$aRow['id'].'" name="edit" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="EDIT TRUCK...!!"><em class="fa fa-pencil"></em></a>&nbsp;';
		}
		
		$str .= '<a href="index.php?page=truck_mst/permit_add.php&eid='.$aRow['id'].'" name="edit" class="btn btn-success " data-toggle="tooltip" data-placement="top" title="UPLOAD DOCUMENT...!!"><em class="fa fa-upload"></em></a>&nbsp;';


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

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

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