<?php
// array for JSON response
$response = array();
$response["list"] = array();

require_once __DIR__ . '/db_config.php';

if (isset($_POST['JSON'])) {
    
    $JSON_Received = $_POST['JSON'];
    $obj = json_decode($JSON_Received, true);                      
    $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());
    
                   
    foreach($obj as $key => $value )  {  

        $companyname = $value['companyname'];
        $emailid= $value['emailid'];
        $date= $value['date'];
        $checkintime= $value['checkintime'];
        $checkouttime= $value['checkouttime'];
        $checkinlocation= $value['checkinlocation'];
        $checkoutlocation= $value['checkoutlocation'];
        $status= $value['status'];
        $totaltime= $value['totaltime'];
        $id=$value['_id'];
        $facility_id_out=$value['facility_id_out'];
        
        $query ="UPDATE attendance SET checkouttime= '$checkouttime' , checkoutlocation= '$checkoutlocation' , status= '$status' , totaltime= '$totaltime',facility_id_out='$facility_id_out' WHERE ( companyname = '$companyname ' AND emailid= '$emailid'  AND date= '$date' ) ";
        $result = mysqli_query($con,$query);
        if($result){
            array_push($response["list"],$id);
        }
    }
  mysqli_close($con);
}
echo json_encode($response);
?>