<?php  include_once('../../config/db.php');  //include_once('../config/check.php'); 






$query = "  SELECT a.*,b.fname,b.mname,b.lname,b.username,c.name cname  FROM sys_user_guard a 
            LEFT JOIN sys_user b ON a.id = b.id
            LEFT JOIN admbranch c  ON a.branch = c.id    ";


$statement = $conn->prepare($query);

$statement->execute();

$number_filter_row = $statement->rowCount();

$statement = $conn->prepare($query );

$statement->execute();

$result = $statement->fetchAll();

$data = array();



foreach($result as $row)
{
    $actionButton = '<i class="fa fa-circle" style="color:green;"></i>';
    $sub_array = array();
    $sub_array[] =  $actionButton  ;
    $sub_array[] = $row['date']; 
    $sub_array[] = $row['fname'].''.$row['mname'].''.$row['lname'];
    $sub_array[] = $row['username'];
    $sub_array[] = $row['cname']; 
    $data[] = $sub_array;

}

function count_all_data($conn,$query)
{
 $statement = $conn->prepare($query);
 $statement->execute();
 return $statement->rowCount();
}

$output = array(
                       "draw"       =>  $number_filter_row ,
                        "recordsTotal"   =>  count_all_data($conn,$query),
                        "recordsFiltered"  =>  $number_filter_row,
                        "data"       =>  $data
);

echo json_encode($output);

?>
