47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
include __DIR__ . '/../db_config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$id = $_POST['id'] ?? '';
|
|
|
|
if (empty($id)) {
|
|
http_response_code(400);
|
|
echo json_encode(['status' => 'error', 'message' => 'ID wajib diisi']);
|
|
exit;
|
|
}
|
|
|
|
// Ambil data gambar untuk dihapus
|
|
$stmt = $conn->prepare("SELECT gambar FROM jalan_rusak WHERE id = ?");
|
|
$stmt->bind_param("i", $id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$row = $result->fetch_assoc();
|
|
|
|
if ($row && $row['gambar'] && file_exists(__DIR__ . '/../' . $row['gambar'])) {
|
|
unlink(__DIR__ . '/../' . $row['gambar']);
|
|
}
|
|
|
|
$stmt->close();
|
|
|
|
// Hapus record
|
|
$stmt = $conn->prepare("DELETE FROM jalan_rusak WHERE id = ?");
|
|
$stmt->bind_param("i", $id);
|
|
|
|
if ($stmt->execute()) {
|
|
echo json_encode(['status' => 'success', 'message' => 'Laporan jalan rusak berhasil dihapus']);
|
|
} else {
|
|
http_response_code(500);
|
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
|
}
|
|
|
|
$stmt->close();
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
http_response_code(405);
|
|
echo json_encode(['status' => 'error', 'message' => 'Method tidak diizinkan']);
|
|
$conn->close();
|
|
?>
|