Fix resident aid saving bug and implement Bantuan Darurat status

This commit is contained in:
fananazril
2026-06-13 13:06:30 +07:00
parent bd95f5581d
commit ac5fbeb72e
14 changed files with 55 additions and 20 deletions
+9 -3
View File
@@ -20,6 +20,11 @@ $db = getDB();
$method = $_SERVER['REQUEST_METHOD'];
$id = isset($_GET['id']) ? (int)$_GET['id'] : null;
// Override method if it's a POST request with an ID, to support multipart/form-data in updates (PUT)
if ($method === 'POST' && $id !== null) {
$method = 'PUT';
}
// ── GET ────────────────────────────────────────────────────────
if ($method === 'GET') {
if ($id) {
@@ -155,9 +160,10 @@ if ($method === 'POST') {
if ($method === 'PUT') {
if (!$id) jsonResponse(['success' => false, 'message' => 'ID wajib disertakan'], 400);
// Cek apakah multipart (ada file) atau JSON
$isMultipart = str_contains($_SERVER['CONTENT_TYPE'] ?? '', 'multipart/form-data');
$body = $isMultipart ? $_POST : (json_decode(file_get_contents('php://input'), true) ?? []);
// Cek apakah form-data (ada file / urlencoded) atau JSON
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
$isForm = str_contains($contentType, 'multipart/form-data') || str_contains($contentType, 'application/x-www-form-urlencoded');
$body = $isForm ? $_POST : (json_decode(file_get_contents('php://input'), true) ?? []);
$current = $db->prepare("SELECT * FROM penduduk_miskin WHERE id = ?");
$current->execute([$id]);