72 lines
3.0 KiB
PHP
72 lines
3.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/common.php';
|
|
|
|
$dbconn = getDBConnection();
|
|
|
|
if($_GET['camstatic'] ?? null) {
|
|
if ($_GET['camstatic'] == 'radius') {
|
|
if($_GET['lat1'] ?? null) {
|
|
$lat1 = getParam('lat1');
|
|
if($_GET['lon1'] ?? null) {
|
|
$lon1 = getParam('lon1');
|
|
if($_GET['radius'] ?? null) {
|
|
$radius = getParam('radius');
|
|
$rad = $radius / 70;
|
|
|
|
$lat1 = floatval($lat1);
|
|
$lon1 = floatval($lon1);
|
|
$radius = floatval($rad);
|
|
$query = "select * from cams where active = true and cwa = 'RLX' and (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) and st_dwithin(geom, ST_SetSRID(ST_Point(" . strval($lon1) . ", " . strval($lat1) . "), 4326)," . strval($radius) . ") order by elevation desc";
|
|
$result = pg_query($dbconn,$query) or die('Query failed: ' . pg_last_error());
|
|
|
|
$array = array();
|
|
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
|
|
$array[] = $line;
|
|
}
|
|
echo json_encode($array);
|
|
pg_free_result($result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if($_GET['camstatic'] ?? null) {
|
|
if ($_GET['camstatic'] == 'bbox') {
|
|
if($_GET['lat1'] ?? null) {
|
|
$lat1 = getParam('lat1');
|
|
if($_GET['lon1'] ?? null) {
|
|
$lon1 = getParam('lon1');
|
|
if($_GET['lat2'] ?? null) {
|
|
$lat2 = getParam('lat2');
|
|
if($_GET['lon2'] ?? null) {
|
|
$lon2 = getParam('lon2');
|
|
if($_GET['elevbottom'] ?? null) {
|
|
$elevbottom = getParam('elevbottom');
|
|
if($_GET['elevtop'] ?? null) {
|
|
$elevtop = getParam('elevtop');
|
|
|
|
$result = pg_query_params($dbconn,
|
|
"select * from cams where active = true and cwa = 'RLX' and elevation > $5 and elevation < $6 and (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) and lat < $1 and lat > $2 and lon < $3 and lon > $4 order by elevation desc",
|
|
array($lat1,$lat2,$lon1,$lon2,$elevbottom,$elevtop)) or die('Query failed: ' . pg_last_error());
|
|
|
|
$array = array();
|
|
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
|
|
$array[] = $line;
|
|
}
|
|
echo json_encode($array);
|
|
pg_free_result($result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Close database connection when needed
|
|
if (isset($dbconn)) {
|
|
pg_close($dbconn);
|
|
}
|
|
?>
|