64 lines
3.0 KiB
PHP
64 lines
3.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/auth.php';
|
|
require_login(true);
|
|
require_post();
|
|
require_role('super_admin', true);
|
|
|
|
$id = (int) post('id', 0);
|
|
$status = post('status_pengajuan', post('status', ''));
|
|
$ket = clean_text(post('keterangan', post('alasan', '')), 1000);
|
|
if (!valid_enum($status, ['menunggu','diterima','ditolak','hapus_disetujui','hapus_ditolak'])) json_response('err', 'Status rumah ibadah tidak valid.');
|
|
|
|
$rumah = get_rumah_ibadah_by_id($id);
|
|
if (!$rumah) json_response('err', 'Rumah ibadah tidak ditemukan.', [], 404);
|
|
|
|
$jumlahSinkron = 0;
|
|
$jumlahLepas = 0;
|
|
|
|
if ($status === 'hapus_disetujui' || $status === 'hapus_ditolak') {
|
|
$catatan = $ket ?: ($status === 'hapus_disetujui' ? 'Pengajuan hapus marker rumah ibadah disetujui.' : 'Pengajuan hapus marker rumah ibadah ditolak.');
|
|
if ($status === 'hapus_disetujui') {
|
|
$statusPengajuan = 'ditolak';
|
|
$statusHapus = 'disetujui';
|
|
$stmt = $koneksi->prepare("UPDATE rumah_ibadah SET status_pengajuan=?, status_hapus=?, alasan_hapus=?, keterangan=? WHERE id=?");
|
|
$stmt->bind_param('ssssi', $statusPengajuan, $statusHapus, $catatan, $catatan, $id);
|
|
if (!$stmt->execute()) json_response('err', 'Gagal menyetujui hapus rumah ibadah: ' . $koneksi->error);
|
|
$jumlahLepas = detach_penerima_from_rumah_ibadah($id);
|
|
} else {
|
|
$statusHapus = 'ditolak';
|
|
$stmt = $koneksi->prepare("UPDATE rumah_ibadah SET status_hapus=?, alasan_hapus=? WHERE id=?");
|
|
$stmt->bind_param('ssi', $statusHapus, $catatan, $id);
|
|
if (!$stmt->execute()) json_response('err', 'Gagal menolak hapus rumah ibadah: ' . $koneksi->error);
|
|
}
|
|
|
|
$row = get_rumah_ibadah_by_id($id);
|
|
$row['jumlah_penerima_tersinkron'] = 0;
|
|
$row['jumlah_penerima_dilepas'] = $jumlahLepas;
|
|
json_response('ok', 'Persetujuan hapus marker rumah ibadah berhasil diproses.', $row);
|
|
}
|
|
|
|
// Update status pengajuan rumah ibadah biasa.
|
|
$statusHapus = 'normal';
|
|
$stmt = $koneksi->prepare("UPDATE rumah_ibadah SET status_pengajuan=?, status_hapus=?, keterangan=? WHERE id=?");
|
|
$stmt->bind_param('sssi', $status, $statusHapus, $ket, $id);
|
|
if (!$stmt->execute()) json_response('err', 'Gagal update status rumah ibadah: ' . $koneksi->error);
|
|
|
|
if ($status === 'diterima') {
|
|
// Saat rumah ibadah disetujui, penerima yang dibuat lebih dulu otomatis masuk area jika radius <= 300 meter.
|
|
$jumlahSinkron = sync_penerima_area_by_rumah_ibadah($id);
|
|
} elseif ($status === 'ditolak') {
|
|
// Jika rumah ibadah ditolak, penerima yang sebelumnya terkait dilepas agar tidak mengarah ke pemberi bantuan tidak aktif.
|
|
$jumlahLepas = detach_penerima_from_rumah_ibadah($id);
|
|
}
|
|
|
|
$row = get_rumah_ibadah_by_id($id);
|
|
if ($row) {
|
|
$row['jumlah_penerima_tersinkron'] = $jumlahSinkron;
|
|
$row['jumlah_penerima_dilepas'] = $jumlahLepas;
|
|
}
|
|
$msg = 'Status rumah ibadah berhasil diubah.';
|
|
if ($jumlahSinkron) $msg .= " $jumlahSinkron penerima otomatis masuk area tanggung jawab.";
|
|
if ($jumlahLepas) $msg .= " $jumlahLepas penerima dilepas dari rumah ibadah ini.";
|
|
json_response('ok', $msg, $row);
|
|
?>
|