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


    $obj = new Datatable($conn);

    $obj->aColumns      = array('code', 'name', 'mobile', 'email', 'e_contact', 'address', 'b_group', 'status', 'created_id', 'file_img');
    $obj->eColumns      = array('id');
    $obj->sIndexColumn  = "id";
    $obj->sTable        = " emp_mst";
    //$obj->myWhere       = " WHERE company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."'";
    $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)) {
        if($aRow['status'] == '0'){
            $status = 'ACTIVE';
        }else{
            $status = 'IN-ACTIVE';
        }
        $temp_arr = array();
        $temp_arr[] = ++$cou;
        $temp_arr[] = $aRow['code'];
        $temp_arr[] = $aRow['name'];
        $temp_arr[] = $aRow['mobile'];
        $temp_arr[] = $aRow['e_contact'];
        $temp_arr[] = $aRow['email'];
        $temp_arr[] = $aRow['address'];
        $temp_arr[] = $aRow['b_group'];
        $temp_arr[] = $status;
        $temp_arr[] = @$master_user[$aRow['created_id']];
        
        $str = '';
        
        if($aRow['file_img'] != ''){
            $str .= '<a href="assets/upload/employee/'.$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'], 'emp_edit') ) {
        $str .= '<a href="index.php?page=emp_mst/add.php&eid='.$aRow['id'].'" name="edit" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="EDIT EMPLOYEE...!!"><em class="fa fa-pencil"></em></a>&nbsp;';
        }

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

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

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