<?php

if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

date_default_timezone_set("America/Panama");
include 'conn.php';
//Select data from database

include 'funciones.php';

session_start();
$_SESSION['database'] = $_GET["database"];

$_SESSION['num'] = $_GET["num"];
$_SESSION['lat'] = $_GET["lat"];
$_SESSION['lon'] = $_GET["lon"];
$_SESSION['id'] = $_GET["id"];

//$info=$_SESSION["newsession"];
/*session created*/
//echo $_SESSION["newsession"];

$hoynow = getdate();

$timeStamp = $hoynow["year"] . "-" . $hoynow["mon"] . "-" . $hoynow["mday"] . " " . $hoynow["hours"] . ":" . $hoynow["minutes"] . ":" . $hoynow["seconds"];

$SQLupdate = "insert into   " . $_SESSION['database'] . ".longitud (numero,latitud,longitud,date,id) value ('" . $_SESSION['num'] . "','" . $_SESSION['lat'] . "','" . $_SESSION['lon'] . "',' " . $timeStamp . " ',' " . $_SESSION['id'] . " ' )  ";

//echo $SQLupdate;

//logs($SQLupdate);

if ($connection->query($SQLupdate) === true) {
    echo "true";
} else {

    echo "Error: " . $SQLupdate . "<br>" . $conn->error;
}

@mysqli_close($connection);
?>