Add WebGIS project documentation
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
require_once dirname(__DIR__) . '/config.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
if ($method === 'GET') {
|
||||
$stmt = $pdo->query("SELECT * FROM parsil");
|
||||
echo json_encode($stmt->fetchAll());
|
||||
} elseif ($method === 'POST') {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$stmt = $pdo->prepare("INSERT INTO parsil (nama_pemilik, status, luas, geojson) VALUES (?, ?, ?, ?)");
|
||||
if ($stmt->execute([$data['nama_pemilik'], $data['status'], $data['luas'], $data['geojson']])) {
|
||||
echo json_encode(["status" => "success", "id" => $pdo->lastInsertId()]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Failed to add data"]);
|
||||
}
|
||||
} elseif ($method === 'PUT') {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$stmt = $pdo->prepare("UPDATE parsil SET nama_pemilik = ?, status = ?, luas = ?, geojson = ? WHERE id = ?");
|
||||
if ($stmt->execute([$data['nama_pemilik'], $data['status'], $data['luas'], $data['geojson'], $data['id']])) {
|
||||
echo json_encode(["status" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Failed to update data"]);
|
||||
}
|
||||
} elseif ($method === 'DELETE') {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$stmt = $pdo->prepare("DELETE FROM parsil WHERE id = ?");
|
||||
if ($stmt->execute([$data['id']])) {
|
||||
echo json_encode(["status" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Failed to delete data"]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user