68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
ini_set('display_errors', '0');
|
|
include __DIR__ . '/../../db_config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
if ($id <= 0) {
|
|
http_response_code(400);
|
|
echo json_encode(['status' => 'error', 'message' => 'ID parsel tidak valid']);
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
// Check if it is a geometry update or attribute update
|
|
$isGeometryUpdate = isset($_POST['geometry']);
|
|
|
|
if ($isGeometryUpdate) {
|
|
$geometry = $_POST['geometry'] ?? '';
|
|
$nilai = (float)($_POST['nilai'] ?? 0);
|
|
|
|
if ($geometry === '') {
|
|
http_response_code(400);
|
|
echo json_encode(['status' => 'error', 'message' => 'Data geometri kosong']);
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
$stmt = $conn->prepare("UPDATE spatial_features SET geometry_data = ?, nilai_ukur = ? WHERE id = ?");
|
|
$stmt->bind_param("sdi", $geometry, $nilai, $id);
|
|
} else {
|
|
$nama = trim($_POST['nama'] ?? '');
|
|
$status = trim($_POST['status'] ?? '');
|
|
|
|
if ($nama === '' || $status === '') {
|
|
http_response_code(400);
|
|
echo json_encode(['status' => 'error', 'message' => 'Nama atau status tidak boleh kosong']);
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
$stmt = $conn->prepare("UPDATE spatial_features SET nama_objek = ?, status_objek = ? WHERE id = ?");
|
|
$stmt->bind_param("ssi", $nama, $status, $id);
|
|
}
|
|
|
|
if (!$stmt) {
|
|
http_response_code(500);
|
|
echo json_encode(['status' => 'error', 'message' => $conn->error]);
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
if ($stmt->execute()) {
|
|
echo json_encode(['status' => 'success', 'message' => 'Parsil tanah berhasil diperbarui']);
|
|
} else {
|
|
http_response_code(500);
|
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
|
}
|
|
$stmt->close();
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
http_response_code(405);
|
|
echo json_encode(['status' => 'error', 'message' => 'Method tidak diizinkan']);
|
|
$conn->close();
|
|
?>
|