<?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['employeemailid'];
        $activity= $value['activity'];
      //   $activity= $value['attendenceteam'];
        $timesheetdate= $value['timesheetdate'];
        
        
        $starttime= $value['starttime'];
        $endtime= $value['endtime'];
        $latitude= $value['latitude'];
        $longitude= $value['longitude'];
        $location= $value['location'];
        $dateandtime= $value['dateandtime'];
        $id=$value['_id'];
        $facility_id = $value['facility_id'];


    
    /*$companyname= $_POST['companyname'];
    $employeemailid= $_POST['employeemailid'];
    $activity = $_POST['activity'];
	$timesheetdate= $_POST['timesheetdate'];
	$starttime= $_POST['starttime'];
    $endtime= $_POST['endtime'];
    $attendancegroup= $_POST['attendancegroup'];
    $attendancesubgroup= $_POST['attendancesubgroup'];
    $attendenceteam= $_POST['attendenceteam'];
    $latitude= $_POST['latitude'];
    $longitude= $_POST['longitude'];
    $location= $_POST['location'];
    $dateandtime= $_POST['dateandtime'];*/

 
    $query="INSERT INTO timesheet(companyname, employeemailid, activity, timesheetdate, starttime, endtime, latitude, longitude, location,dateandtime,facility_id) VALUES ('$companyname', '$emailid', '$activity', '$timesheetdate', '$starttime', '$endtime', '$latitude', '$longitude', '$location','$dateandtime','$facility_id') ";
      // $query="INSERT INTO timesheet(companyname, employeemailid, activity, timesheetdate, starttime, endtime, latitude, longitude, location,dateandtime) VALUES ('companyname', 'emailid', 'activity', '2019-12-17', '01:00:00', '02:00:00', '0.0', '0.0', 'location','2019-12-17 01:00:00') ";
     
     //  $result = mysql_query("INSERT INTO timesheet(companyname, employeemailid, activity, timesheetdate, starttime, endtime, attendancegroup, attendancesubgroup, attendenceteam, latitude, longitude, location, dateandtime) VALUES('$companyname', '$employeemailid', '$activity', '$timesheetdate' , '$starttime' ,'$endtime', '$attendancegroup', '$attendancesubgroup', '$attendenceteam', '$latitude', '$longitude','$location', '$dateandtime')");
      
        $result = mysqli_query($con,$query);
        
        if ($result) {
            array_push($response["list"],$id);
        }
    }
	
 mysqli_close($con);

}
echo json_encode($response);
?>