gpstools/day.php

77 lines
1.7 KiB
PHP
Raw Normal View History

2017-10-05 12:43:32 +00:00
<?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.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": [
2017-10-05 12:43:32 +00:00
';
while($row = $result->fetch_assoc()) {
$output .= " [ " . $row["lon"] . ", " . $row["lat"] . " ],\n";
2017-10-05 12:43:32 +00:00
}
$output = substr_replace($output, "", strrpos($output, ","), 1);
$output .= ' ]
}
}
]
}';
echo $output;
2017-10-05 12:43:32 +00:00
} else {
die("No records found.");
}
$conn->close();
?>