40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
include 'koneksi.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$id = (int)$_POST['id'];
|
|
$tipe = $_POST['tipe'] ?? '';
|
|
|
|
if ($tipe === 'ibadah') {
|
|
$stmt = $conn->prepare("DELETE FROM rumah_ibadah WHERE id=?");
|
|
$stmt->bind_param("i", $id);
|
|
$stmt->execute()
|
|
? print json_encode(["status" => "success"])
|
|
: print json_encode(["status" => "error", "msg" => $stmt->error]);
|
|
|
|
} elseif ($tipe === 'penduduk') {
|
|
// Hapus histori & pelatihan dulu (FK)
|
|
foreach (['histori_bantuan', 'pelatihan'] as $tbl) {
|
|
$s = $conn->prepare("DELETE FROM $tbl WHERE penduduk_id=?");
|
|
$s->bind_param("i", $id);
|
|
$s->execute();
|
|
}
|
|
$stmt = $conn->prepare("DELETE FROM penduduk WHERE id=?");
|
|
$stmt->bind_param("i", $id);
|
|
$stmt->execute()
|
|
? print json_encode(["status" => "success"])
|
|
: print json_encode(["status" => "error", "msg" => $stmt->error]);
|
|
|
|
} elseif ($tipe === 'laporan') {
|
|
$stmt = $conn->prepare("DELETE FROM laporan WHERE id=?");
|
|
$stmt->bind_param("i", $id);
|
|
$stmt->execute()
|
|
? print json_encode(["status" => "success"])
|
|
: print json_encode(["status" => "error", "msg" => $stmt->error]);
|
|
|
|
} else {
|
|
http_response_code(400);
|
|
echo json_encode(["status" => "error", "msg" => "Tipe tidak dikenal"]);
|
|
}
|