Files
test/ver.php
2025-11-27 22:25:36 +00:00

141 lines
3.1 KiB
PHP

<?php
header("Access-Control-Allow-Origin: *");
// Connecting, selecting database
$dbconn = pg_connect("host=localhost dbname=nws user=nws password=nws")
or die('Could not connect: ' . pg_last_error());
//no gets, curent point outage info
if(empty($_GET)) {
$result = pg_query($dbconn,
"SELECT jsonb_build_object('type', 'FeatureCollection','features', jsonb_agg(features.feature)) FROM (SELECT jsonb_build_object('type', 'Feature','geometry', ST_AsGeoJSON(ST_Transform(geom, 4326))::jsonb,'properties', to_jsonb(properties) - 'geom') AS feature FROM (SELECT *FROM pzone where cwa ='RLX') AS properties) AS features") or die('Query failed: ' . pg_last_error());
$resultArray = pg_fetch_all($result);
header('Content-Type: application/json; charset=utf-8');
echo($resultArray[0]['jsonb_build_object']);
pg_free_result($result);
}
if (isset($_GET['lsrslist'])) {
$result = pg_query($dbconn,"SELECT * from simplever") or die('Query failed: ' . pg_last_error());
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
$array[] = $line;
}
echo json_encode($array);
pg_free_result($result);
}
if (isset($_GET['reset'])) {
$result = pg_query($dbconn,"truncate simplever") or die('Query failed: ' . pg_last_error());
$resultArray = pg_fetch_all($result);
echo($resultArray);
}
if (isset($_GET['lsrs'])) {
if (isset($_GET['zone'])) {
$zone = $_GET['zone'];
if (isset($_GET['lsr'])) {
$lsr = (int) $_GET['lsr'];
} else {
$lsr = 1;
}
if (isset($_GET['lsrs'])) {
$dir = $_GET['dir'];
}
if ($dir == 1) {
$result = pg_query_params($dbconn,"INSERT into simplever (zone,lsr) values ($1,$2) on conflict (zone) do update set lsr = (simplever.lsr + 1) where simplever.zone = $1", array($zone,$lsr)) or die('Query failed: ' . pg_last_error());
$resultArray = pg_fetch_all($result);
}
else {
$result = pg_query_params($dbconn,"INSERT into simplever (zone,lsr) values ($1,$2) on conflict (zone) do update set lsr = 0 where simplever.zone = $1", array($zone,$lsr)) or die('Query failed: ' . pg_last_error());
$resultArray = pg_fetch_all($result);
}
//echo($resultArray[0]);
pg_free_result($result);
}
}
if (isset($_GET['inc'])) {
if ($_GET['inc'] == 'true') {
$hideflag = 'true';
} else {
$hideflag = 'false';
}
$id = (int) $_GET['id'];
$query = "UPDATE reports SET hide = $1 WHERE id = $2";
$result = pg_query_params($dbconn, $query, array($hideflag, $id)) or die('Query failed: ' . pg_last_error());
pg_free_result($result);
}
if (isset($_GET['hide'])) {
if ($_GET['hide'] == 'true') {
$hideflag = 'true';
} else {
$hideflag = 'false';
}
$id = (int) $_GET['id'];
$query = "UPDATE reports SET hide = $1 WHERE id = $2";
$result = pg_query_params($dbconn, $query, array($hideflag, $id)) or die('Query failed: ' . pg_last_error());
pg_free_result($result);
}
pg_close($dbconn);
?>