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


    $obj = new Datatable($conn);

    $obj->aColumns      = array('code', 'name', 'mobile', 'email', 'pan', 'created_id');
    $obj->eColumns      = array('id');
    $obj->sIndexColumn  = "id";
    $obj->sTable        = "agent";
    $obj->datatable_process();
    
    $cou = 0;
    if(isset($_GET['iDisplayStart'])) {
        $cou = $_GET['iDisplayStart'];
    }
    $master_user = combine(getAllRecords('users'), 'id', 'name');
    $master_act = combine(getAllRecords('act_master'), 'act_code', 'ac_name');
    while ($aRow = mysqli_fetch_array($obj->rResult)) {
        $temp_arr = array();

        $temp_arr[] = ++$cou;
        $temp_arr[] = $aRow['code'];
        $temp_arr[] = $aRow['name'];
        $temp_arr[] = $aRow['mobile'];
        $temp_arr[] = $aRow['email'];
        $temp_arr[] = $aRow['pan'];
        $temp_arr[] = @$master_user[$aRow['created_id']];
        $str = '';
        if( hasPermission($_SESSION['user_detail']['role_id'], 'agent_edit') ) {
        $str .= '<a href="index.php?page=agent/edit.php&eid='.$aRow['id'].'" name="edit" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="EDIT AGENT...!!"><em class="fa fa-pencil"></em></a>&nbsp;';
        }

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

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

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