<?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'];
        $employeemailid= $value['employeemailid'];
        $leavetype = $value['leavetype'];
    	$leavefrom= $value['leavefrom'];
    	$leaveto= $value['leaveto'];
        $leavedays= $value['leavedays'];
        $permissiondate= $value['permissiondate'];
        $permissionfrom= $value['permissionfrom'];
        $permissionto= $value['permissionto'];
        $permissioninminutes= $value['permissioninminutes'];
        $appliedateandtime= $value['appliedateandtime'];
        $reasonforleaveorpermission= $value['reasonforleaveorpermission'];
        $status= $value['status'];
        $id=$value['_id'];

        $query ="INSERT INTO leavetable(companyname, employeemailid, leavetype, leavefrom, leaveto, leavedays, permissiondate, permissionfrom, permissionto, permissioninminutes, appliedateandtime, reasonforleaveorpermission, status) VALUES('$companyname', '$employeemailid', '$leavetype', '$leavefrom' , '$leaveto' ,'$leavedays', '$permissiondate', '$permissionfrom', '$permissionto', '$permissioninminutes', '$appliedateandtime','$reasonforleaveorpermission', '$status')";
        
        $result = mysqli_query($con,$query);
        if($result){
            array_push($response["list"],$id);
        }
    }
    mysqli_close($con);
}
echo json_encode($response);

?>