<?php 
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');
// Logical section of page


if (isset($_REQUEST['act']) && $_REQUEST['act']=='load' && $_REQUEST['log_id'] != ''){
    $records = $_REQUEST['length'];
    $start=0;
    if(isset($_GET['start']) && $_GET['start']!='0'){
        $page = $_GET['start'];
    }
    $start=($page-1)*$limit;
    $limit = array('start'=>$_GET['start'],'record'=>$records);
    
  
    if(isset($_REQUEST['log_id']))
    {
        $file_name = '';

        if($_REQUEST['log_id'] == '1')
        {
            $file_name = DIR_ADMIN_LOG.'appointment.log';
        }else if($_REQUEST['log_id'] == '2')
        {
            $file_name = DIR_ADMIN_LOG.'provider.log';
        }else if($_REQUEST['log_id'] == '3')
        {
            $file_name = DIR_ADMIN_LOG.'patient.log';
        }else if($_REQUEST['log_id'] == '4')
        {
            $file_name = DIR_ADMIN_LOG.'guarantor.log';
        }else if($_REQUEST['log_id'] == '5')
        {
            $file_name = DIR_ADMIN_LOG.'prescreen.log';
        }else if($_REQUEST['log_id'] == '6')
        {
            $file_name = DIR_ADMIN_LOG.'reminder.log';
        }

        if(file_exists($file_name))
        {
            $lines = array_slice(file($file_name), -50);

            if(!empty($lines))
            {
                $i=1;
                foreach ($lines as $key => $value) 
                {
                    if(!empty($value))
                    {
                        $response[] = array(
                            $i++,  
                            $value
                        );
                    }
                }

                $recordsTotal = count($response);
                    
                $result=array('recordsFiltered'=>$recordsTotal,'recordsTotal'=>$recordsTotal,'data'=>$response); 

                //$result=array('recordsFiltered'=>$recordsTotal,'recordsTotal'=>$recordsTotal,'data'=>$response);
                
            }else{
                $result=array('recordsFiltered'=>0,'recordsTotal'=>0,'data'=>array());
            }
        }else{
            $result=array('recordsFiltered'=>0,'recordsTotal'=>0,'data'=>array());
        }
    }else{
        $result=array('recordsFiltered'=>0,'recordsTotal'=>0,'data'=>array());
    }

    echo json_encode($result);
    exit;
}

// Include Template 
include_once('../libs/routs.php')
?>