Fix resident aid saving bug and implement Bantuan Darurat status
This commit is contained in:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user