36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
include 'db_config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
$nama = trim($_POST['nama'] ?? '');
|
|
$alamat = trim($_POST['alamat'] ?? '');
|
|
$pic = trim($_POST['pic'] ?? '');
|
|
$lat = $_POST['latitude'] ?? null;
|
|
$lng = $_POST['longitude'] ?? null;
|
|
$radius = $_POST['radius_m'] ?? 1000;
|
|
|
|
if ($id <= 0 || $nama === '' || $alamat === '' || $pic === '' || $lat === null || $lng === null) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Data rumah ibadah tidak lengkap']);
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
$lat = (float)$lat;
|
|
$lng = (float)$lng;
|
|
$radius = max(50, (int)$radius);
|
|
|
|
$stmt = $conn->prepare("UPDATE rumah_ibadah SET nama = ?, alamat = ?, pic = ?, latitude = ?, longitude = ?, radius_m = ? WHERE id = ?");
|
|
$stmt->bind_param("sssddii", $nama, $alamat, $pic, $lat, $lng, $radius, $id);
|
|
|
|
if ($stmt->execute()) {
|
|
echo json_encode(['status' => 'success', 'message' => 'Rumah ibadah berhasil diperbarui']);
|
|
} else {
|
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
|
}
|
|
|
|
$stmt->close();
|
|
}
|
|
$conn->close();
|
|
?>
|