Harden Project 01 public endpoints

This commit is contained in:
Andrie
2026-06-11 23:15:42 +07:00
parent a90748d9c1
commit 6f4488c1b8
39 changed files with 1183 additions and 612 deletions
+23 -11
View File
@@ -1,27 +1,39 @@
<?php
require_once '../../koneksi.php';
require_admin_json();
header('Content-Type: application/json');
require_once '../../auth/helper.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => 'error', 'message' => 'Method tidak valid.']); exit;
}
require_admin_post();
require_once '../../koneksi.php';
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) {
echo json_encode(['status' => 'error', 'message' => 'ID tidak valid.']); exit;
json_error('ID tidak valid.', 400);
}
$stmt = $conn->prepare("UPDATE choropleth_layers SET is_visible = 1 - is_visible WHERE id = ?");
if (!$stmt) {
error_log('Project 01 choropleth toggle prepare failed: ' . $conn->error);
json_error('Gagal mengubah visibilitas layer.', 500);
}
$stmt->bind_param('i', $id);
$stmt->execute();
if (!$stmt->execute()) {
error_log('Project 01 choropleth toggle failed: ' . $stmt->error);
json_error('Gagal mengubah visibilitas layer.', 500);
}
$stmt->close();
$stmt2 = $conn->prepare("SELECT is_visible FROM choropleth_layers WHERE id = ?");
if (!$stmt2) {
error_log('Project 01 choropleth visibility prepare failed: ' . $conn->error);
json_error('Gagal memuat status layer.', 500);
}
$stmt2->bind_param('i', $id);
$stmt2->execute();
$row = $stmt2->get_result()->fetch_assoc();
$stmt2->close();
$conn->close();
echo json_encode(['status' => 'success', 'is_visible' => (bool)$row['is_visible']]);
if (!$row) {
json_error('Layer tidak ditemukan.', 404);
}
json_success(['is_visible' => (bool)$row['is_visible']]);