Files
UAS_WEBGIS_MichelleOlivia_D…/sig-kemiskinan/api/update_radius.php
T
2026-06-10 21:46:56 +07:00

30 lines
912 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// api/update_radius.php
// Update radius satu rumah ibadah + reassign penduduk
require_once __DIR__ . '/../includes/config.php';
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') exit;
$input = getInput();
$id = $input['id'] ?? null;
$radius = $input['radius'] ?? null;
if (!$id || !$radius) {
jsonResponse(['success' => false, 'error' => 'id dan radius diperlukan'], 400);
}
$radius = max(100, min(5000, (int)$radius)); // clamp 1005000m
$db = getDB();
$db->prepare("UPDATE rumah_ibadah SET radius = ? WHERE id = ?")->execute([$radius, $id]);
reassignAll();
jsonResponse(['success' => true, 'radius' => $radius, 'message' => "Radius diubah ke {$radius}m, penduduk di-reassign"]);