<?php

$r = array();
require_once __DIR__ . '/db_config.php';


if (isset($_POST["email"])) {
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());
$email = $_POST['email'];

$query="SELECT f.companyname,f.atmid,f.state,f.country,f.location,f.atmaddress,f.sitename,f.latitude,f.longitude,b.geofencing,b.geo_distance  
FROM signupdetails s 
INNER JOIN atmdetails f ON f.companyname = s.companyname AND f.deleted='no'
INNER JOIN b2lcustomers b ON f.companyname=b.companyname
INNER JOIN emp_facility ON s.emailid = emp_facility.emp_emailid AND f.Id=emp_facility.atmdetail_id
WHERE s.emailid='$email' AND b.geofencing='enable'";
$result = mysqli_query($con,$query);
if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r, $row);
    }
}else{
    $query="SELECT f.companyname,f.atmid,f.state,f.country,f.location,f.atmaddress,f.sitename,f.latitude,f.longitude,b.geofencing,b.geo_distance  
    FROM signupdetails s 
    INNER JOIN atmdetails f ON f.companyname = s.companyname AND f.deleted='no'
    INNER JOIN b2lcustomers b ON f.companyname=b.companyname
    WHERE s.emailid='$email'  AND b.geofencing='enable'";
    
    $result = mysqli_query($con,$query);
    if(!empty($result) && mysqli_num_rows($result) > 0){
        while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
            array_push($r, $row);
        }
    }
}
    
mysqli_close($con);               
echo json_encode($r);
}
?>