57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
$status = 0;
|
|
|
|
include_once("config.php");
|
|
|
|
if (!$access)
|
|
die("Access not enabled in configuration file. Make sure that this page is not public before enabling it.");
|
|
|
|
if ($accessverification)
|
|
include("auth.php");
|
|
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
$sql = "SELECT ts, lat, lon FROM tracker WHERE device='" . mysqli_real_escape_string($conn, $_GET["device"]) . "' AND DATE(ts)='".date("Y-m-d")."' ORDER BY ts ASC;";
|
|
$result = $conn->query($sql);
|
|
|
|
if ($result->num_rows > 0) {
|
|
header('Content-Type: application/vnd.google-earth.kml+xml');
|
|
header('Content-Disposition: attachment; filename="export.kml"');
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>
|
|
<kml xmlns="http://www.opengis.net/kml/2.2">
|
|
<Document>
|
|
<Placemark>
|
|
<ExtendedData>
|
|
<Data name="styleUrl"><value>#style</value></Data>
|
|
<Data name="styleHash"><value>1a1ac94e</value></Data>
|
|
<Data name="stroke"><value>#ffff00</value></Data>
|
|
<Data name="stroke-opacity"><value>0.4980392156862745</value></Data>
|
|
<Data name="stroke-width"><value>4</value></Data>
|
|
<Data name="fill"><value>#00ff00</value></Data>
|
|
<Data name="fill-opacity"><value>0.4980392156862745</value></Data>
|
|
</ExtendedData>
|
|
<LineString>
|
|
<coordinates>
|
|
';
|
|
|
|
while($row = $result->fetch_assoc()) {
|
|
echo $row["lon"] . "," . $row["lat"] . "\n";
|
|
}
|
|
|
|
echo '</coordinates>
|
|
</LineString></Placemark>
|
|
</Document></kml>';
|
|
|
|
} else {
|
|
die("No records found.");
|
|
}
|
|
|
|
$conn->close();
|
|
|
|
?>
|
|
|