35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
include 'db_config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$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 ($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("INSERT INTO rumah_ibadah (nama, alamat, pic, latitude, longitude, radius_m) VALUES (?, ?, ?, ?, ?, ?)");
|
|
$stmt->bind_param("sssddi", $nama, $alamat, $pic, $lat, $lng, $radius);
|
|
|
|
if ($stmt->execute()) {
|
|
echo json_encode(['status' => 'success', 'message' => 'Rumah ibadah berhasil disimpan']);
|
|
} else {
|
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
|
}
|
|
|
|
$stmt->close();
|
|
}
|
|
$conn->close();
|
|
?>
|