52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
// ToDo's
|
|
// Whitelists oder Prepared Statements gegen SQL-Injection hinzufügen
|
|
|
|
// PostgreSQL-Serververbindung
|
|
include 'init.php';
|
|
|
|
// HTTP-POST-Methode für Formulardaten
|
|
$table = htmlspecialchars($_POST['table'], ENT_QUOTES);
|
|
$field = htmlspecialchars($_POST['field'], ENT_QUOTES);
|
|
$value = htmlspecialchars($_POST['value'], ENT_QUOTES);
|
|
|
|
try {
|
|
// Datenbankabfrage
|
|
$result = $pdo -> query("SELECT *, ST_AsGeoJSON(geom) as geojson FROM $table WHERE $field = '$value'");
|
|
|
|
$features = [];
|
|
|
|
foreach($result as $row) {
|
|
// PHP-Objekt erstellen
|
|
$geometry = json_decode($row['geojson']);
|
|
|
|
// PHP-Objekt bereinigen
|
|
unset($row['geom']);
|
|
unset($row['geojson']);
|
|
|
|
// JSON-Feature hinzufügen
|
|
$feature = [
|
|
"type"=>"Feature",
|
|
"geometry"=>$geometry,
|
|
"properties"=>$row
|
|
];
|
|
|
|
array_push($features, $feature);
|
|
};
|
|
|
|
// Feature-Collection hinzufügen
|
|
$featureCollection = [
|
|
"type"=>"FeatureCollection",
|
|
"features"=>$features
|
|
];
|
|
|
|
echo json_encode($featureCollection);
|
|
|
|
// Fehlernachricht ausgeben
|
|
} catch(PDOException $e) {
|
|
echo "ERROR ".$e->getMessage();
|
|
|
|
}
|
|
|
|
?>
|