chore: prepare docker webgis deployment
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require_once '../../config.php';
|
||||
require_once '../../koneksi.php';
|
||||
|
||||
// Publik — tidak perlu auth
|
||||
// Agregasi kebutuhan Belum Terpenuhi per kategori × rumah ibadah (area)
|
||||
|
||||
$rows = $conn->query("
|
||||
SELECT
|
||||
k.kategori,
|
||||
COALESCE(ri.nama, 'Di luar radius ibadah') AS area,
|
||||
COUNT(DISTINCT k.penduduk_id) AS jumlah_kk
|
||||
FROM kebutuhan k
|
||||
JOIN penduduk_miskin pm ON pm.id = k.penduduk_id
|
||||
AND pm.is_active = 1
|
||||
AND pm.deleted_at IS NULL
|
||||
AND pm.status_verifikasi = 'Terverifikasi'
|
||||
LEFT JOIN rumah_ibadah ri ON ri.id = pm.ibadah_id AND ri.deleted_at IS NULL
|
||||
WHERE k.status = 'Belum Terpenuhi'
|
||||
GROUP BY k.kategori, pm.ibadah_id, ri.nama
|
||||
ORDER BY jumlah_kk DESC, k.kategori ASC
|
||||
");
|
||||
|
||||
$data = [];
|
||||
while ($r = $rows->fetch_assoc()) {
|
||||
$data[] = [
|
||||
'kategori' => $r['kategori'],
|
||||
'area' => $r['area'],
|
||||
'jumlah_kk' => (int)$r['jumlah_kk'],
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode(['status' => 'success', 'data' => $data]);
|
||||
$conn->close();
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require_once '../../config.php';
|
||||
require_once '../../auth/helper.php';
|
||||
require_once '../../koneksi.php';
|
||||
|
||||
require_auth('administrator');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
require_csrf();
|
||||
|
||||
$action = trim($_POST['action'] ?? 'mark_all');
|
||||
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
|
||||
|
||||
if ($action === 'hapus') {
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'ID tidak valid.']);
|
||||
$conn->close(); exit;
|
||||
}
|
||||
$stmt = $conn->prepare("DELETE FROM kontak_donatur WHERE id=?");
|
||||
$stmt->bind_param('i', $id);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
echo json_encode(['status' => 'success']);
|
||||
$conn->close(); exit;
|
||||
}
|
||||
|
||||
if ($action === 'mark_one') {
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'ID tidak valid.']);
|
||||
$conn->close(); exit;
|
||||
}
|
||||
$stmt = $conn->prepare("UPDATE kontak_donatur SET is_read=1 WHERE id=?");
|
||||
$stmt->bind_param('i', $id);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
echo json_encode(['status' => 'success']);
|
||||
$conn->close(); exit;
|
||||
}
|
||||
|
||||
// mark_all — default, also handles legacy calls without action param
|
||||
$conn->query("UPDATE kontak_donatur SET is_read=1 WHERE is_read=0");
|
||||
echo json_encode(['status' => 'success', 'marked_read' => $conn->affected_rows]);
|
||||
$conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $conn->query("
|
||||
SELECT id, nama, kontak, kategori_minat, pesan, is_read, created_at
|
||||
FROM kontak_donatur
|
||||
ORDER BY is_read ASC, created_at DESC
|
||||
LIMIT 100
|
||||
");
|
||||
|
||||
$data = [];
|
||||
while ($r = $rows->fetch_assoc()) {
|
||||
$data[] = $r;
|
||||
}
|
||||
|
||||
echo json_encode(['status' => 'success', 'data' => $data]);
|
||||
$conn->close();
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require_once '../../config.php';
|
||||
require_once '../../koneksi.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Method not allowed.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$rate_window = 60;
|
||||
$client_ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
|
||||
$rate_dir = dirname(__DIR__, 2) . '/tmp/donor-rate-limit';
|
||||
if (!is_dir($rate_dir)) {
|
||||
@mkdir($rate_dir, 0775, true);
|
||||
}
|
||||
$rate_file = $rate_dir . '/' . hash('sha256', $client_ip) . '.txt';
|
||||
$last_submit = max(
|
||||
(int)($_SESSION['donor_last_submit'] ?? 0),
|
||||
is_file($rate_file) ? (int)filemtime($rate_file) : 0
|
||||
);
|
||||
if ($last_submit > 0 && ($now - $last_submit) < $rate_window) {
|
||||
http_response_code(429);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Terlalu sering mengirim. Coba lagi dalam 1 menit.',
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$nama = trim($_POST['nama'] ?? '');
|
||||
$kontak = trim($_POST['kontak'] ?? '');
|
||||
$kategori_minat = trim($_POST['kategori_minat'] ?? '');
|
||||
$pesan = trim($_POST['pesan'] ?? '');
|
||||
|
||||
if (!$nama || !$kontak) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Nama dan kontak wajib diisi.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$valid_kategori = ['Sembako','Biaya Sekolah','Biaya Kesehatan','Modal Usaha',
|
||||
'Renovasi Rumah','Perlengkapan Rumah','Pakaian','Lainnya'];
|
||||
$kat = in_array($kategori_minat, $valid_kategori, true) ? $kategori_minat : null;
|
||||
$pesan_val = $pesan !== '' ? mb_substr($pesan, 0, 1000) : null;
|
||||
$nama_safe = mb_substr($nama, 0, 150);
|
||||
$kontak_safe = mb_substr($kontak, 0, 150);
|
||||
|
||||
$stmt = $conn->prepare(
|
||||
"INSERT INTO kontak_donatur (nama, kontak, kategori_minat, pesan) VALUES (?,?,?,?)"
|
||||
);
|
||||
$stmt->bind_param('ssss', $nama_safe, $kontak_safe, $kat, $pesan_val);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$_SESSION['donor_last_submit'] = time();
|
||||
@file_put_contents($rate_file, (string)$_SESSION['donor_last_submit'], LOCK_EX);
|
||||
echo json_encode(['status' => 'success']);
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Gagal menyimpan.']);
|
||||
}
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
Reference in New Issue
Block a user