chore: prepare docker webgis deployment

This commit is contained in:
Andrie
2026-06-11 18:14:21 +07:00
parent d2214ad9c8
commit a90748d9c1
149 changed files with 20844 additions and 5 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
header('Content-Type: application/json');
require_once '../../config.php';
require_once '../../auth/helper.php';
require_once '../../koneksi.php';
// Public viewer boleh akses — tidak perlu require_auth
// Hanya tampilkan warga yang sudah Terverifikasi di agregat publik
$sql = "
SELECT ri.id, ri.nama, ri.jenis, ri.alamat, ri.lat, ri.lng,
ri.radius_m, ri.kontak, ri.created_at, ri.updated_at,
COUNT(pm.id) AS total_kk,
COALESCE(SUM(pm.jumlah_jiwa), 0) AS total_jiwa,
COALESCE(SUM(CASE WHEN pm.is_blank_spot = 0 THEN pm.jumlah_jiwa ELSE 0 END), 0) AS jiwa_terjangkau,
COALESCE(SUM(CASE WHEN pm.is_blank_spot = 1 THEN pm.jumlah_jiwa ELSE 0 END), 0) AS jiwa_blankspot
FROM rumah_ibadah ri
LEFT JOIN penduduk_miskin pm
ON pm.ibadah_id = ri.id
AND pm.is_active = 1
AND pm.deleted_at IS NULL
AND pm.status_verifikasi = 'Terverifikasi'
WHERE ri.deleted_at IS NULL
GROUP BY ri.id
ORDER BY ri.created_at DESC
";
$result = $conn->query($sql);
$data = [];
while ($row = $result->fetch_assoc()) $data[] = $row;
echo json_encode(['status' => 'success', 'total' => count($data), 'data' => $data]);
$conn->close();
+102
View File
@@ -0,0 +1,102 @@
<?php
header('Content-Type: application/json');
require_once '../../config.php';
require_once '../../auth/helper.php';
require_once '../../koneksi.php';
require_auth('administrator');
require_csrf();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => 'error', 'message' => 'Method not allowed']); exit;
}
$id = (int) ($_POST['id'] ?? 0);
if (!$id) { echo json_encode(['status' => 'error', 'message' => 'ID tidak valid']); exit; }
$active_stmt = $conn->prepare("SELECT id FROM rumah_ibadah WHERE id = ? AND deleted_at IS NULL LIMIT 1");
$active_stmt->bind_param('i', $id);
$active_stmt->execute();
$active_row = $active_stmt->get_result()->fetch_assoc();
$active_stmt->close();
if (!$active_row) {
http_response_code(404);
echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan atau sudah dihapus']); exit;
}
// Cek operator yang terkait
$stmt = $conn->prepare(
"SELECT nama_lengkap FROM users WHERE ibadah_id = ? AND is_active = 1 LIMIT 5"
);
$stmt->bind_param('i', $id);
$stmt->execute();
$ops_result = $stmt->get_result();
$operators = [];
while ($op = $ops_result->fetch_assoc()) $operators[] = $op['nama_lengkap'];
$stmt->close();
// Jika belum konfirmasi dan ada operator terkait, kembalikan warning
$confirmed = ($_POST['confirmed'] ?? '0') === '1';
if (!$confirmed && count($operators) > 0) {
echo json_encode([
'status' => 'warning',
'operators' => $operators,
'message' => 'Rumah ibadah ini dikaitkan dengan akun Operator: ' . implode(', ', $operators)
. '. Operator tidak akan bisa login sampai dikaitkan ke rumah ibadah lain.',
]);
exit;
}
$conn->begin_transaction();
try {
// Soft delete
$stmt = $conn->prepare("UPDATE rumah_ibadah SET deleted_at = NOW() WHERE id = ? AND deleted_at IS NULL");
if (!$stmt) {
throw new RuntimeException('prepare delete failed: ' . $conn->error);
}
$stmt->bind_param('i', $id);
if (!$stmt->execute()) {
throw new RuntimeException('delete failed: ' . $stmt->error);
}
$deleted = $stmt->affected_rows > 0;
$stmt->close();
if (!$deleted) {
$conn->rollback();
http_response_code(404);
echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan atau sudah dihapus']);
$conn->close();
exit;
}
$recalc = $conn->query("SELECT id, lat, lng FROM penduduk_miskin WHERE is_active=1 AND deleted_at IS NULL");
if (!$recalc) {
throw new RuntimeException('read penduduk failed: ' . $conn->error);
}
while ($warga = $recalc->fetch_assoc()) {
_recalc_proximity($conn, $warga['id'], $warga['lat'], $warga['lng']);
}
$conn->commit();
echo json_encode(['status' => 'success', 'message' => 'Rumah ibadah berhasil dihapus']);
} catch (Throwable $e) {
$conn->rollback();
error_log('ibadah/hapus transaction failed: ' . $e->getMessage());
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Gagal menghapus rumah ibadah.']);
}
function _recalc_proximity($conn, $penduduk_id, $lat, $lng) {
$p = calc_proximity($conn, (float)$lat, (float)$lng);
$s = $conn->prepare(
"UPDATE penduduk_miskin SET ibadah_id=?, jarak_m=?, is_blank_spot=? WHERE id=?"
);
if (!$s) {
throw new RuntimeException('prepare recalc failed: ' . $conn->error);
}
$s->bind_param('idii', $p['ibadah_id'], $p['jarak_m'], $p['is_blank_spot'], $penduduk_id);
if (!$s->execute()) {
throw new RuntimeException('recalc update failed: ' . $s->error);
}
$s->close();
}
$conn->close();
@@ -0,0 +1,51 @@
<?php
header('Content-Type: application/json');
require_once '../../config.php';
require_once '../../auth/helper.php';
require_once '../../koneksi.php';
require_auth('administrator');
require_csrf();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => 'error', 'message' => 'Method not allowed']); exit;
}
$conn->begin_transaction();
try {
$warga_list = $conn->query(
"SELECT id, lat, lng FROM penduduk_miskin WHERE is_active=1 AND deleted_at IS NULL"
);
if (!$warga_list) {
throw new RuntimeException('read penduduk failed: ' . $conn->error);
}
$updated = 0;
while ($warga = $warga_list->fetch_assoc()) {
$p = calc_proximity($conn, (float)$warga['lat'], (float)$warga['lng']);
$s = $conn->prepare(
"UPDATE penduduk_miskin SET ibadah_id=?, jarak_m=?, is_blank_spot=? WHERE id=?"
);
if (!$s) {
throw new RuntimeException('prepare recalc failed: ' . $conn->error);
}
$s->bind_param('idii', $p['ibadah_id'], $p['jarak_m'], $p['is_blank_spot'], $warga['id']);
if (!$s->execute()) {
throw new RuntimeException('recalc update failed: ' . $s->error);
}
$s->close();
$updated++;
}
$conn->commit();
echo json_encode([
'status' => 'success',
'updated' => $updated,
'message' => "$updated data penduduk berhasil diperbarui",
]);
} catch (Throwable $e) {
$conn->rollback();
error_log('ibadah/recalculate transaction failed: ' . $e->getMessage());
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Gagal menghitung ulang proximity.']);
}
$conn->close();
@@ -0,0 +1,48 @@
<?php
header('Content-Type: application/json');
require_once '../../config.php';
require_once '../../auth/helper.php';
require_once '../../includes/validation.php';
require_once '../../koneksi.php';
require_auth('administrator');
require_csrf();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => 'error', 'message' => 'Method not allowed']); exit;
}
$nama = trim($_POST['nama'] ?? '');
$jenis = trim($_POST['jenis'] ?? 'Masjid');
$alamat = trim($_POST['alamat'] ?? '');
$kontak = trim($_POST['kontak'] ?? '');
$coord = validate_lat_lng($_POST['lat'] ?? null, $_POST['lng'] ?? null);
if (!$coord['ok']) {
echo json_encode(['status' => 'error', 'message' => $coord['message']]); exit;
}
$lat = $coord['lat'];
$lng = $coord['lng'];
$radius = (int) ($_POST['radius_m'] ?? 500);
if (!$nama) {
echo json_encode(['status' => 'error', 'message' => 'Nama ibadah tidak boleh kosong']); exit;
}
if ($radius < 100 || $radius > 5000) {
echo json_encode(['status' => 'error', 'message' => 'Radius minimum 100 meter, maksimum 5.000 meter']); exit;
}
$valid_jenis = ['Masjid','Mushola','Gereja','Pura','Vihara','Klenteng'];
if (!in_array($jenis, $valid_jenis)) $jenis = 'Masjid';
$stmt = $conn->prepare(
"INSERT INTO rumah_ibadah (nama, jenis, alamat, lat, lng, radius_m, kontak) VALUES (?,?,?,?,?,?,?)"
);
$stmt->bind_param('sssddis', $nama, $jenis, $alamat, $lat, $lng, $radius, $kontak);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Data berhasil disimpan',
'data' => ['id'=>$conn->insert_id,'nama'=>$nama,'jenis'=>$jenis,
'alamat'=>$alamat,'kontak'=>$kontak,'lat'=>$lat,'lng'=>$lng,'radius_m'=>$radius]]);
} else {
echo json_encode(['status' => 'error', 'message' => 'Gagal menyimpan: '.$stmt->error]);
}
$stmt->close(); $conn->close();
@@ -0,0 +1,90 @@
<?php
header('Content-Type: application/json');
require_once '../../config.php';
require_once '../../auth/helper.php';
require_once '../../includes/validation.php';
require_once '../../koneksi.php';
require_auth('administrator');
require_csrf();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => 'error', 'message' => 'Method not allowed']); exit;
}
$id = (int) ($_POST['id'] ?? 0);
$nama = trim( $_POST['nama'] ?? '');
$jenis = trim( $_POST['jenis'] ?? 'Masjid');
$alamat = trim( $_POST['alamat'] ?? '');
$kontak = trim( $_POST['kontak'] ?? '');
$coord = validate_lat_lng($_POST['lat'] ?? null, $_POST['lng'] ?? null);
if (!$coord['ok']) {
echo json_encode(['status' => 'error', 'message' => $coord['message']]);
$conn->close(); exit;
}
$lat = $coord['lat'];
$lng = $coord['lng'];
$radius = (int) ($_POST['radius_m'] ?? 500);
$valid_jenis = ['Masjid', 'Mushola', 'Gereja', 'Pura', 'Vihara', 'Klenteng'];
if (!$id) { echo json_encode(['status' => 'error', 'message' => 'ID tidak valid']); exit; }
if (!$nama) { echo json_encode(['status' => 'error', 'message' => 'Nama wajib diisi']); exit; }
if (!in_array($jenis, $valid_jenis)) { echo json_encode(['status' => 'error', 'message' => 'Jenis tidak valid']); exit; }
if ($radius < 100 || $radius > 5000) { echo json_encode(['status' => 'error', 'message' => 'Radius minimum 100 meter, maksimum 5.000 meter']); exit; }
$active_stmt = $conn->prepare("SELECT id FROM rumah_ibadah WHERE id = ? AND deleted_at IS NULL LIMIT 1");
$active_stmt->bind_param('i', $id);
$active_stmt->execute();
$active_row = $active_stmt->get_result()->fetch_assoc();
$active_stmt->close();
if (!$active_row) {
http_response_code(404);
echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan atau sudah dihapus']);
$conn->close(); exit;
}
$conn->begin_transaction();
try {
$stmt = $conn->prepare(
"UPDATE rumah_ibadah SET nama=?, jenis=?, alamat=?, kontak=?, lat=?, lng=?, radius_m=? WHERE id=? AND deleted_at IS NULL"
);
if (!$stmt) {
throw new RuntimeException('prepare update failed: ' . $conn->error);
}
$stmt->bind_param('ssssddii', $nama, $jenis, $alamat, $kontak, $lat, $lng, $radius, $id);
if (!$stmt->execute()) {
throw new RuntimeException('update failed: ' . $stmt->error);
}
$changed = $stmt->affected_rows > 0;
$stmt->close();
// Recalculate proximity for all active penduduk (radius may have changed)
if ($changed) {
$warga = $conn->query("SELECT id, lat, lng FROM penduduk_miskin WHERE is_active=1 AND deleted_at IS NULL");
if (!$warga) {
throw new RuntimeException('read penduduk failed: ' . $conn->error);
}
while ($w = $warga->fetch_assoc()) {
if ($w['lat'] === null || $w['lng'] === null) continue;
$p = calc_proximity($conn, (float)$w['lat'], (float)$w['lng']);
$s = $conn->prepare("UPDATE penduduk_miskin SET ibadah_id=?, jarak_m=?, is_blank_spot=? WHERE id=?");
if (!$s) {
throw new RuntimeException('prepare recalc failed: ' . $conn->error);
}
$s->bind_param('idii', $p['ibadah_id'], $p['jarak_m'], $p['is_blank_spot'], $w['id']);
if (!$s->execute()) {
throw new RuntimeException('recalc update failed: ' . $s->error);
}
$s->close();
}
}
$conn->commit();
echo json_encode(['status' => 'success', 'message' => 'Rumah ibadah berhasil diperbarui']);
} catch (Throwable $e) {
$conn->rollback();
error_log('ibadah/update transaction failed: ' . $e->getMessage());
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Gagal memproses perubahan rumah ibadah.']);
}
$conn->close();
@@ -0,0 +1,44 @@
<?php
// api/ibadah/update_kontak.php — Update kontak rumah ibadah
header('Content-Type: application/json');
require_once '../../config.php';
require_once '../../auth/helper.php';
require_once '../../koneksi.php';
require_auth('administrator');
require_csrf();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => 'error', 'message' => 'Method not allowed']);
exit;
}
$id = (int) ($_POST['id'] ?? 0);
$kontak = trim($_POST['kontak'] ?? '');
if (!$id) {
echo json_encode(['status' => 'error', 'message' => 'ID tidak valid']);
exit;
}
$active_stmt = $conn->prepare("SELECT id FROM rumah_ibadah WHERE id = ? AND deleted_at IS NULL LIMIT 1");
$active_stmt->bind_param('i', $id);
$active_stmt->execute();
$active_row = $active_stmt->get_result()->fetch_assoc();
$active_stmt->close();
if (!$active_row) {
http_response_code(404);
echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan atau sudah dihapus']);
exit;
}
$stmt = $conn->prepare("UPDATE rumah_ibadah SET kontak = ? WHERE id = ? AND deleted_at IS NULL");
$stmt->bind_param('si', $kontak, $id);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Kontak berhasil diperbarui']);
} else {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengupdate kontak: ' . $stmt->error]);
}
$stmt->close();
$conn->close();
@@ -0,0 +1,84 @@
<?php
header('Content-Type: application/json');
require_once '../../config.php';
require_once '../../auth/helper.php';
require_once '../../includes/validation.php';
require_once '../../koneksi.php';
require_auth('administrator');
require_csrf();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => 'error', 'message' => 'Method not allowed']);
exit;
}
$id = (int) ($_POST['id'] ?? 0);
$coord = validate_lat_lng($_POST['lat'] ?? null, $_POST['lng'] ?? null);
if (!$coord['ok']) {
echo json_encode(['status' => 'error', 'message' => $coord['message']]);
exit;
}
$lat = $coord['lat'];
$lng = $coord['lng'];
if (!$id) {
echo json_encode(['status' => 'error', 'message' => 'ID tidak valid']);
exit;
}
$active_stmt = $conn->prepare("SELECT id FROM rumah_ibadah WHERE id = ? AND deleted_at IS NULL LIMIT 1");
$active_stmt->bind_param('i', $id);
$active_stmt->execute();
$active_row = $active_stmt->get_result()->fetch_assoc();
$active_stmt->close();
if (!$active_row) {
http_response_code(404);
echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan atau sudah dihapus']);
exit;
}
$conn->begin_transaction();
try {
$stmt = $conn->prepare("UPDATE rumah_ibadah SET lat = ?, lng = ? WHERE id = ? AND deleted_at IS NULL");
if (!$stmt) {
throw new RuntimeException('prepare update failed: ' . $conn->error);
}
$stmt->bind_param('ddi', $lat, $lng, $id);
if (!$stmt->execute()) {
throw new RuntimeException('update failed: ' . $stmt->error);
}
$changed = $stmt->affected_rows > 0;
$stmt->close();
// Recalculate proximity for all active penduduk
if ($changed) {
$warga_list = $conn->query(
"SELECT id, lat, lng FROM penduduk_miskin WHERE is_active=1 AND deleted_at IS NULL"
);
if (!$warga_list) {
throw new RuntimeException('read penduduk failed: ' . $conn->error);
}
while ($warga = $warga_list->fetch_assoc()) {
$p = calc_proximity($conn, (float)$warga['lat'], (float)$warga['lng']);
$s = $conn->prepare("UPDATE penduduk_miskin SET ibadah_id=?, jarak_m=?, is_blank_spot=? WHERE id=?");
if (!$s) {
throw new RuntimeException('prepare recalc failed: ' . $conn->error);
}
$s->bind_param('idii', $p['ibadah_id'], $p['jarak_m'], $p['is_blank_spot'], $warga['id']);
if (!$s->execute()) {
throw new RuntimeException('recalc update failed: ' . $s->error);
}
$s->close();
}
}
$conn->commit();
echo json_encode(['status' => 'success', 'message' => 'Posisi berhasil diperbarui']);
} catch (Throwable $e) {
$conn->rollback();
error_log('ibadah/update_posisi transaction failed: ' . $e->getMessage());
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Gagal memproses perubahan posisi.']);
}
$conn->close();
@@ -0,0 +1,77 @@
<?php
header('Content-Type: application/json');
require_once '../../config.php';
require_once '../../auth/helper.php';
require_once '../../koneksi.php';
require_auth('administrator');
require_csrf();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => 'error', 'message' => 'Method not allowed']); exit;
}
$id = (int) ($_POST['id'] ?? 0);
$radius = (int) ($_POST['radius_m'] ?? 500);
if (!$id) { echo json_encode(['status' => 'error', 'message' => 'ID tidak valid']); exit; }
if ($radius < 100 || $radius > 5000) {
echo json_encode(['status' => 'error', 'message' => 'Radius minimum 100 meter, maksimum 5.000 meter']); exit;
}
$active_stmt = $conn->prepare("SELECT id FROM rumah_ibadah WHERE id = ? AND deleted_at IS NULL LIMIT 1");
$active_stmt->bind_param('i', $id);
$active_stmt->execute();
$active_row = $active_stmt->get_result()->fetch_assoc();
$active_stmt->close();
if (!$active_row) {
http_response_code(404);
echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan atau sudah dihapus']);
exit;
}
$conn->begin_transaction();
try {
$stmt = $conn->prepare("UPDATE rumah_ibadah SET radius_m = ? WHERE id = ? AND deleted_at IS NULL");
if (!$stmt) {
throw new RuntimeException('prepare update failed: ' . $conn->error);
}
$stmt->bind_param('ii', $radius, $id);
if (!$stmt->execute()) {
throw new RuntimeException('update failed: ' . $stmt->error);
}
$changed = $stmt->affected_rows > 0;
$stmt->close();
// Recalculate proximity for all active penduduk
if ($changed) {
$warga_list = $conn->query(
"SELECT id, lat, lng FROM penduduk_miskin WHERE is_active=1 AND deleted_at IS NULL"
);
if (!$warga_list) {
throw new RuntimeException('read penduduk failed: ' . $conn->error);
}
while ($warga = $warga_list->fetch_assoc()) {
$p = calc_proximity($conn, (float)$warga['lat'], (float)$warga['lng']);
$s = $conn->prepare("UPDATE penduduk_miskin SET ibadah_id=?, jarak_m=?, is_blank_spot=? WHERE id=?");
if (!$s) {
throw new RuntimeException('prepare recalc failed: ' . $conn->error);
}
$s->bind_param('idii', $p['ibadah_id'], $p['jarak_m'], $p['is_blank_spot'], $warga['id']);
if (!$s->execute()) {
throw new RuntimeException('recalc update failed: ' . $s->error);
}
$s->close();
}
}
$conn->commit();
echo json_encode(['status' => 'success', 'message' => 'Radius berhasil diperbarui', 'radius_m' => $radius]);
} catch (Throwable $e) {
$conn->rollback();
error_log('ibadah/update_radius transaction failed: ' . $e->getMessage());
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Gagal memproses perubahan radius.']);
}
$conn->close();