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


	$obj = new Datatable($conn);

	$obj->aColumns 		= array('id', 'module', 'company_id', 'branch', 'start_sr_no', 'end_sr_no');
    $obj->eColumns 		= array('id');
    $obj->sIndexColumn 	= "id";
    $obj->sTable 		= "document_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_company  = combine(getAllRecords('company_mst'), 'id', 'name');
    $master_branch   = combine(getAllRecords('branch_mst'), 'id', 'branch');
    while ($aRow = mysqli_fetch_array($obj->rResult)) {

    	$temp_arr = array();
		$temp_arr[] = ++$cou;
		$temp_arr[] = $aRow['module'];
		$temp_arr[] = @$master_company[$aRow['company_id']];
		$temp_arr[] = @$master_branch[$aRow['branch']];
		$temp_arr[] = $aRow['start_sr_no'];
		$temp_arr[] = $aRow['end_sr_no'];
		
		
		$str = '';
		if( hasPermission($_SESSION['user_detail']['role_id'], 'doc_edit') ) {
		$str .= '<a href="index.php?page=document_mst/add.php&eid='.$aRow['id'].'" name="edit" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="EDIT DOCUMENT...!!"><em class="fa fa-pencil"></em></a>&nbsp;';
		}
		
		if( hasPermission($_SESSION['user_detail']['role_id'], 'doc_delete') ) {
		$str .= '<button type="button" class="btn btn-danger delete_data" id="'.$aRow["id"].'" data-toggle="tooltip" data-placement="top" title="DELETE DOCUMENT..!!" onclick="confirmDelete(this);"><em class="fa fa-trash"></em></button>';
		}

		$temp_arr[] = $str;

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

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