33 lines
1.4 KiB
PHP
33 lines
1.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/auth.php';
|
|
require_login(true);
|
|
require_post();
|
|
require_role(['super_admin','admin_rumah_ibadah'], true);
|
|
|
|
$id = (int) post('id', 0);
|
|
$stmt = $koneksi->prepare("SELECT * FROM program_bantuan WHERE id=? LIMIT 1");
|
|
$stmt->bind_param('i', $id);
|
|
$program = fetch_all_stmt($stmt)[0] ?? null;
|
|
if (!$program) json_response('err', 'Program tidak ditemukan.');
|
|
if ($_SESSION['role'] === 'admin_rumah_ibadah') {
|
|
if (!is_admin_rumah_ibadah_id((int)$program['rumah_ibadah_id'], (int)$_SESSION['user_id'], true)) {
|
|
json_response('err', 'Akses ditolak. Program ini bukan milik rumah ibadah yang dikelola akun Anda.', [], 403);
|
|
}
|
|
}
|
|
|
|
$stmt = $koneksi->prepare("SELECT COUNT(*) AS jml FROM penyaluran_bantuan WHERE program_id=?");
|
|
$stmt->bind_param('i', $id);
|
|
$row = fetch_all_stmt($stmt)[0];
|
|
if ((int)$row['jml'] > 0) {
|
|
$status = 'dibatalkan';
|
|
$stmt = $koneksi->prepare("UPDATE program_bantuan SET status_program=? WHERE id=?");
|
|
$stmt->bind_param('si', $status, $id);
|
|
$stmt->execute();
|
|
json_response('ok', 'Program sudah memiliki penyaluran, maka status diubah menjadi dibatalkan.', ['id'=>$id]);
|
|
}
|
|
$stmt = $koneksi->prepare("DELETE FROM program_bantuan WHERE id=?");
|
|
$stmt->bind_param('i', $id);
|
|
if (!$stmt->execute()) json_response('err', 'Gagal menghapus program: ' . $koneksi->error);
|
|
json_response('ok', 'Program bantuan berhasil dihapus.', ['id'=>$id]);
|
|
?>
|