<?php
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if ($contentType === "application/json") {
    $content = trim(file_get_contents("php://input"));
    $decodeData = json_decode($content, true);
    if (is_array($decodeData)) {
        $obj=new updateFTAdetails();
        $obj->updateFTADetails($decodeData);
    }else{
        echo json_encode("error on fetching");  
    }
}
class updateFTAdetails
{

    function __construct()
    {
        require_once dirname(__DIR__)."../../php/DB_Connect.php";
        $dbClassObj=new DB_conncect();
        $this->db=$dbClassObj->connectToDB();

    }
    function updateFTADetails($data){
      
        $uniquId=$data['empId']."_".$data['siteId']."_".$data['siteVisitDate'];
        $query=$this->db->prepare("UPDATE tesf SET `DISTANCE_(KMS)`=?, `USER_LAT`=?, `USER_LNG`=?, `USER_LOCATION_ADDRESS`=? WHERE `UNIQUE_ID`=?");
        $query->bind_param('dssss',$data['distance'],$data['userLat'],$data['userLong'],$data['userLntAddress'],$uniquId);
        $query->execute();
        if( $query->execute()){
            $res_array=array(
            "error"=>false,
            "message"=>"Succesfully Updated"
            );

            echo json_encode($res_array);
        }else{
            $res_array=array(
                "error"=>true,
                "message"=>"Not Updated"
                );
            echo json_encode($res_array);
        }
    }
}
