<?php

// array for JSON response
$response = array();

require_once __DIR__ . '/db_config.php';

if ( isset($_POST["companyname"]) && isset($_POST["email"]) && isset($_POST["startdate"]) && isset($_POST["enddate"]) ) {
    
    $companyname = $_POST['companyname'];
    $emailid = $_POST['email'];
    $startdate = $_POST['startdate'];
    $enddate = $_POST['enddate'];
 
    $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());
 
    $query="SELECT companyname,emailid,date,checkintime,checkouttime,checkinlocation,checkoutlocation,status,totaltime,facility_id,facility_id_out FROM attendance WHERE  companyname = '$companyname' AND emailid = '$emailid' AND date<='$enddate' AND date>='$startdate' ORDER BY Id ASC";
 
    $result = mysqli_query($con,$query);
    
    if(!empty($result) && mysqli_num_rows($result) > 0){
        
        $response["list"] = mysqli_fetch_all($result,MYSQLI_ASSOC);
        $response["s"] = 1;
        
    }else{
        $response["s"] = 0;
    }
    
    mysqli_close($con);
    
}else {
    $response["s"] = 2;
}
    echo json_encode($response);


?>