gpstools/access.php

76 lines
1.7 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"]) . "' ORDER BY ts ASC;";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
header('Content-Type: application/vnd.geo+json');
header('Content-Disposition: attachment; filename="export.geojson"');
$output = '{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature",
"properties": {
"Name": null,
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"styleUrl": "#style",
"styleHash": "1a1ac94e",
"stroke": "#ffff00",
"stroke_opacity": "0.4980392156862745",
"stroke_width": "4",
"fill": "#00ff00",
"fill_opacity": "0.4980392156862745"
},
"geometry": {
"type": "LineString",
"coordinates": [
';
while($row = $result->fetch_assoc()) {
$output .= " [ " . $row["lon"] . ", " . $row["lat"] . " ],\n";
}
$output = substr_replace($output, "", strrpos($output, ","), 1);
$output .= ' ]
}
}
]
}';
echo $output;
} else {
die("No records found.");
}
$conn->close();
?>