<?php
session_start();
if (!isset($_SESSION['role']) || !in_array($_SESSION['role'], ['admin', 'petugas'])) {
    header('Content-Type: application/json');
    http_response_code(403);
    echo json_encode(['status'=>'error','message'=>'Akses ditolak.']);
    exit;
}

include '../koneksi.php';
header('Content-Type: application/json');

$id = (int)($_POST['id'] ?? 0);
$status_bantuan = trim($_POST['status_bantuan'] ?? '');

if (!$id || !$status_bantuan) {
    echo json_encode(['status'=>'error','message'=>'Data tidak valid.']);
    exit;
}

try {
    $stmt = $pdo->prepare("UPDATE penduduk_miskin SET status_bantuan=? WHERE id=?");
    $stmt->execute([$status_bantuan, $id]);
    echo json_encode(['status'=>'success']);
} catch (PDOException $e) {
    echo json_encode(['status'=>'error','message'=>$e->getMessage()]);
}
?>
