add files and folders
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
function is_logged_in() {
|
||||
return isset($_SESSION['user']) && is_array($_SESSION['user']);
|
||||
}
|
||||
|
||||
function require_login() {
|
||||
if (!is_logged_in()) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function current_user() {
|
||||
return $_SESSION['user'] ?? null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../php/koneksi.php';
|
||||
require_once __DIR__ . '/_auth.php';
|
||||
|
||||
function h($v) { return htmlspecialchars((string)($v ?? ''), ENT_QUOTES, 'UTF-8'); }
|
||||
|
||||
function render_header($title) {
|
||||
$u = current_user();
|
||||
$name = $u ? h($u['name'] ?? $u['username'] ?? '') : '';
|
||||
echo '<!doctype html><html lang="id"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">';
|
||||
echo '<title>' . h($title) . '</title>';
|
||||
echo '<link rel="stylesheet" href="../css/style.css">';
|
||||
echo '<style>
|
||||
body{background:#0b1220;margin:0}
|
||||
.admin-shell{max-width:1100px;margin:0 auto;padding:22px}
|
||||
.admin-top{display:flex;align-items:center;justify-content:space-between;color:#e5e7eb;margin-bottom:16px}
|
||||
.admin-card{background:#fff;border-radius:18px;box-shadow:0 18px 45px rgba(0,0,0,.25);padding:18px}
|
||||
.admin-nav a{color:#e5e7eb;text-decoration:none;margin-right:12px;font-weight:800}
|
||||
.admin-nav a:hover{text-decoration:underline}
|
||||
table{width:100%;border-collapse:collapse}
|
||||
th,td{padding:10px 10px;border-bottom:1px solid #e2e8f0;font-size:14px;text-align:left;vertical-align:top}
|
||||
th{font-weight:900}
|
||||
.tag{display:inline-block;padding:4px 8px;border-radius:999px;background:#eef2ff;color:#1d4ed8;font-weight:900;font-size:12px}
|
||||
.actions{display:flex;gap:8px;flex-wrap:wrap}
|
||||
.actions a,.actions button{border:0;border-radius:12px;padding:8px 10px;font-weight:900;cursor:pointer}
|
||||
.actions a{background:#0f172a;color:#fff;text-decoration:none}
|
||||
.actions button.danger{background:#dc2626;color:#fff}
|
||||
.actions a.secondary{background:#e2e8f0;color:#0f172a}
|
||||
</style></head><body>';
|
||||
echo '<div class="admin-shell">';
|
||||
echo '<div class="admin-top"><div><div style="font-size:22px;font-weight:900;color:#fff">Admin Panel</div><div class="admin-nav">';
|
||||
echo '<a href="index.php">Dashboard</a><a href="rumah_ibadah.php">Rumah Ibadah</a><a href="penduduk_miskin.php">Penduduk Miskin</a>';
|
||||
echo '</div></div><div style="color:#cbd5e1;font-weight:800">' . $name . ' <a href="logout.php" style="color:#93c5fd;text-decoration:none">Logout</a></div></div>';
|
||||
}
|
||||
|
||||
function render_footer() {
|
||||
echo '</div></body></html>';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/_layout.php';
|
||||
require_login();
|
||||
|
||||
// Stats
|
||||
$counts = [
|
||||
'rumah_ibadah' => 0,
|
||||
'penduduk' => 0,
|
||||
'dibantu' => 0,
|
||||
'belum' => 0,
|
||||
'verifikasi' => 0
|
||||
];
|
||||
|
||||
try {
|
||||
$counts['rumah_ibadah'] = (int)$pdo->query("SELECT COUNT(*) FROM rumah_ibadah_points")->fetchColumn();
|
||||
$cols = $pdo->query("SHOW COLUMNS FROM pemukiman_miskin_points")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$hasNew = in_array('status_bantuan', $cols, true);
|
||||
$counts['penduduk'] = (int)$pdo->query("SELECT COUNT(*) FROM pemukiman_miskin_points")->fetchColumn();
|
||||
if ($hasNew) {
|
||||
$counts['dibantu'] = (int)$pdo->query("SELECT COUNT(*) FROM pemukiman_miskin_points WHERE status_bantuan='Sudah dibantu'")->fetchColumn();
|
||||
$counts['belum'] = (int)$pdo->query("SELECT COUNT(*) FROM pemukiman_miskin_points WHERE status_bantuan='Belum dibantu'")->fetchColumn();
|
||||
$counts['verifikasi'] = (int)$pdo->query("SELECT COUNT(*) FROM pemukiman_miskin_points WHERE status_bantuan='Menunggu verifikasi'")->fetchColumn();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
render_header('Admin Dashboard');
|
||||
?>
|
||||
<div class="admin-card">
|
||||
<div style="display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px">
|
||||
<div style="background:#0b1220;border-radius:18px;padding:14px;color:#fff">
|
||||
<div style="font-weight:900;font-size:28px"><?= (int)$counts['rumah_ibadah'] ?></div>
|
||||
<div style="color:#cbd5e1;font-weight:800">Rumah Ibadah</div>
|
||||
</div>
|
||||
<div style="background:#0b1220;border-radius:18px;padding:14px;color:#fff">
|
||||
<div style="font-weight:900;font-size:28px"><?= (int)$counts['penduduk'] ?></div>
|
||||
<div style="color:#cbd5e1;font-weight:800">Penduduk Miskin</div>
|
||||
</div>
|
||||
<div style="background:#052e1a;border-radius:18px;padding:14px;color:#fff">
|
||||
<div style="font-weight:900;font-size:28px"><?= (int)$counts['dibantu'] ?></div>
|
||||
<div style="color:#bbf7d0;font-weight:800">Sudah dibantu</div>
|
||||
</div>
|
||||
<div style="background:#3b0a0a;border-radius:18px;padding:14px;color:#fff">
|
||||
<div style="font-weight:900;font-size:28px"><?= (int)$counts['belum'] ?></div>
|
||||
<div style="color:#fecaca;font-weight:800">Belum dibantu</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-top:14px;color:#475569;font-weight:800">
|
||||
Menu admin ini melengkapi WebGIS utama: `index.html`.
|
||||
</div>
|
||||
</div>
|
||||
<?php render_footer(); ?>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../php/koneksi.php';
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
try {
|
||||
$pdo->exec("
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
username VARCHAR(60) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
role VARCHAR(20) NOT NULL DEFAULT 'operator',
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
");
|
||||
|
||||
$count = (int)$pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
|
||||
if ($count > 0) {
|
||||
echo "Users sudah ada. Silakan login di <a href='login.php'>login.php</a>.";
|
||||
exit;
|
||||
}
|
||||
|
||||
$username = 'admin';
|
||||
$password = 'admin123';
|
||||
$hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $pdo->prepare("INSERT INTO users (name, username, password_hash, role) VALUES (:n,:u,:p,'admin')");
|
||||
$stmt->execute([':n' => 'Administrator', ':u' => $username, ':p' => $hash]);
|
||||
|
||||
echo "Admin dibuat. Username: <b>admin</b>, Password: <b>admin123</b>. Lanjut login: <a href='login.php'>login.php</a>";
|
||||
} catch (Exception $e) {
|
||||
echo "Gagal init admin: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../php/koneksi.php';
|
||||
require_once __DIR__ . '/_auth.php';
|
||||
|
||||
if (is_logged_in()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$error = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = trim($_POST['username'] ?? '');
|
||||
$password = (string)($_POST['password'] ?? '');
|
||||
try {
|
||||
$stmt = $pdo->prepare("SELECT id, name, username, password_hash, role FROM users WHERE username = :u LIMIT 1");
|
||||
$stmt->execute([':u' => $username]);
|
||||
$u = $stmt->fetch();
|
||||
if ($u && password_verify($password, $u['password_hash'])) {
|
||||
$_SESSION['user'] = ['id' => (int)$u['id'], 'name' => $u['name'], 'username' => $u['username'], 'role' => $u['role']];
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
$error = 'Username atau password salah.';
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Login Admin</title>
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
<style>
|
||||
body{background:#0b1220;margin:0;display:grid;place-items:center;min-height:100vh;padding:18px}
|
||||
.card{background:#fff;border-radius:22px;box-shadow:0 18px 45px rgba(0,0,0,.25);width:100%;max-width:420px;padding:18px}
|
||||
.title{font-weight:900;font-size:22px;margin:0 0 4px}
|
||||
.sub{color:#64748b;margin:0 0 14px;font-weight:700}
|
||||
.err{background:#fef2f2;border:1px solid #fecaca;color:#991b1b;padding:10px 12px;border-radius:14px;font-weight:800;margin-bottom:12px}
|
||||
.btnx{width:100%;margin-top:12px}
|
||||
a{color:#2563eb;text-decoration:none;font-weight:900}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<div class="title">Login Admin</div>
|
||||
<div class="sub">Jika belum ada user, jalankan <a href="init_admin.php">init_admin.php</a>.</div>
|
||||
<?php if ($error): ?><div class="err"><?= htmlspecialchars($error, ENT_QUOTES, 'UTF-8') ?></div><?php endif; ?>
|
||||
<form method="post">
|
||||
<label>Username</label>
|
||||
<input name="username" required>
|
||||
<label style="margin-top:10px;display:block;">Password</label>
|
||||
<input name="password" type="password" required>
|
||||
<button class="btn btn-primary btnx" type="submit">Masuk</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/_auth.php';
|
||||
session_destroy();
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/_layout.php';
|
||||
require_login();
|
||||
|
||||
function csv_cell($v) {
|
||||
$s = (string)($v ?? '');
|
||||
$s = str_replace('"', '""', $s);
|
||||
return '"' . $s . '"';
|
||||
}
|
||||
|
||||
// Export CSV
|
||||
if (isset($_GET['export'])) {
|
||||
header('Content-Type: text/csv; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename="penduduk_miskin.csv"');
|
||||
$cols = $pdo->query("SHOW COLUMNS FROM pemukiman_miskin_points")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$hasNew = in_array('kk_nama', $cols, true);
|
||||
$out = fopen('php://output', 'w');
|
||||
if ($hasNew) {
|
||||
fputcsv($out, ['id','kk_nama','nik','jumlah_anggota','lat','lng','alamat','kelurahan','kecamatan','status_bantuan','jenis_bantuan','tanggal_bantuan','rumah_ibadah_id','jarak_meter']);
|
||||
$rows = $pdo->query("SELECT id, kk_nama, nik, jumlah_anggota, latitude, longitude, address, kelurahan, kecamatan, status_bantuan, jenis_bantuan, tanggal_bantuan, rumah_ibadah_id, jarak_meter FROM pemukiman_miskin_points ORDER BY id ASC")->fetchAll();
|
||||
foreach ($rows as $r) {
|
||||
fputcsv($out, [
|
||||
$r['id'], $r['kk_nama'], $r['nik'], $r['jumlah_anggota'],
|
||||
$r['latitude'], $r['longitude'], $r['address'], $r['kelurahan'], $r['kecamatan'],
|
||||
$r['status_bantuan'], $r['jenis_bantuan'], $r['tanggal_bantuan'],
|
||||
$r['rumah_ibadah_id'], $r['jarak_meter']
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
fputcsv($out, ['id','nama','lat','lng','alamat','rumah_ibadah_id']);
|
||||
$rows = $pdo->query("SELECT id, nama, latitude, longitude, address, rumah_ibadah_id FROM pemukiman_miskin_points ORDER BY id ASC")->fetchAll();
|
||||
foreach ($rows as $r) fputcsv($out, [$r['id'],$r['nama'],$r['latitude'],$r['longitude'],$r['address'],$r['rumah_ibadah_id']]);
|
||||
}
|
||||
fclose($out);
|
||||
exit;
|
||||
}
|
||||
|
||||
$msg = '';
|
||||
$err = '';
|
||||
|
||||
// Delete
|
||||
if (isset($_GET['delete'])) {
|
||||
$id = (int)$_GET['delete'];
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM pemukiman_miskin_points WHERE id=:id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$msg = 'Berhasil dihapus.';
|
||||
} catch (Exception $e) {
|
||||
$err = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Import CSV (minimal)
|
||||
if (isset($_POST['import_csv'])) {
|
||||
if (!isset($_FILES['csv_file']) || ($_FILES['csv_file']['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
|
||||
$err = 'CSV tidak ditemukan.';
|
||||
} else {
|
||||
try {
|
||||
$cols = $pdo->query("SHOW COLUMNS FROM pemukiman_miskin_points")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$hasNew = in_array('kk_nama', $cols, true);
|
||||
$fp = fopen($_FILES['csv_file']['tmp_name'], 'r');
|
||||
$header = fgetcsv($fp);
|
||||
if (!$header) throw new Exception('Header CSV kosong.');
|
||||
$map = [];
|
||||
foreach ($header as $i => $hcol) $map[strtolower(trim($hcol))] = $i;
|
||||
$pdo->beginTransaction();
|
||||
$ins = $hasNew
|
||||
? $pdo->prepare("INSERT INTO pemukiman_miskin_points (kk_nama, nik, jumlah_anggota, latitude, longitude, address, kelurahan, kecamatan, status_bantuan, jenis_bantuan, tanggal_bantuan) VALUES (:kk,:nik,:j,:lat,:lng,:a,:kel,:kec,:s,:jb,:tb)")
|
||||
: $pdo->prepare("INSERT INTO pemukiman_miskin_points (nama, latitude, longitude, address) VALUES (:kk,:lat,:lng,:a)");
|
||||
$n = 0;
|
||||
while (($row = fgetcsv($fp)) !== false) {
|
||||
$kk = $row[$map['kk_nama'] ?? $map['nama'] ?? -1] ?? '';
|
||||
$lat = $row[$map['lat'] ?? $map['latitude'] ?? -1] ?? '';
|
||||
$lng = $row[$map['lng'] ?? $map['longitude'] ?? -1] ?? '';
|
||||
if (trim($kk) === '' || trim($lat) === '' || trim($lng) === '') continue;
|
||||
if ($hasNew) {
|
||||
$ins->execute([
|
||||
':kk' => $kk,
|
||||
':nik' => ($row[$map['nik'] ?? -1] ?? '') ?: null,
|
||||
':j' => (int)($row[$map['jumlah_anggota'] ?? -1] ?? 0),
|
||||
':lat' => $lat,
|
||||
':lng' => $lng,
|
||||
':a' => ($row[$map['alamat'] ?? $map['address'] ?? -1] ?? '') ?: null,
|
||||
':kel' => ($row[$map['kelurahan'] ?? -1] ?? '') ?: null,
|
||||
':kec' => ($row[$map['kecamatan'] ?? -1] ?? '') ?: null,
|
||||
':s' => ($row[$map['status_bantuan'] ?? -1] ?? 'Belum dibantu') ?: 'Belum dibantu',
|
||||
':jb' => ($row[$map['jenis_bantuan'] ?? -1] ?? '') ?: null,
|
||||
':tb' => ($row[$map['tanggal_bantuan'] ?? -1] ?? '') ?: null
|
||||
]);
|
||||
} else {
|
||||
$ins->execute([
|
||||
':kk' => $kk,
|
||||
':lat' => $lat,
|
||||
':lng' => $lng,
|
||||
':a' => ($row[$map['alamat'] ?? $map['address'] ?? -1] ?? '') ?: null
|
||||
]);
|
||||
}
|
||||
$n++;
|
||||
}
|
||||
$pdo->commit();
|
||||
fclose($fp);
|
||||
$msg = "Import selesai: $n baris.";
|
||||
} catch (Exception $e) {
|
||||
if ($pdo->inTransaction()) $pdo->rollBack();
|
||||
$err = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Simple edit/create (without anggota details)
|
||||
if (isset($_POST['save_penduduk'])) {
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$kk = trim($_POST['kk_nama'] ?? '');
|
||||
$nik = trim($_POST['nik'] ?? '');
|
||||
$jml = (int)($_POST['jumlah_anggota'] ?? 0);
|
||||
$lat = $_POST['latitude'] ?? null;
|
||||
$lng = $_POST['longitude'] ?? null;
|
||||
$addr = trim($_POST['address'] ?? '');
|
||||
$kel = trim($_POST['kelurahan'] ?? '');
|
||||
$kec = trim($_POST['kecamatan'] ?? '');
|
||||
$status = trim($_POST['status_bantuan'] ?? 'Belum dibantu');
|
||||
$jb = trim($_POST['jenis_bantuan'] ?? '');
|
||||
$tb = trim($_POST['tanggal_bantuan'] ?? '');
|
||||
|
||||
if ($kk === '' || $lat === null || $lng === null) $err = 'Data belum lengkap (nama/lat/lng).';
|
||||
else {
|
||||
try {
|
||||
$cols = $pdo->query("SHOW COLUMNS FROM pemukiman_miskin_points")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$hasNew = in_array('kk_nama', $cols, true);
|
||||
if (!$hasNew) throw new Exception('Schema belum mendukung fitur penduduk detail. Jalankan schema terbaru.');
|
||||
|
||||
if ($id > 0) {
|
||||
$stmt = $pdo->prepare("UPDATE pemukiman_miskin_points SET kk_nama=:kk, nik=:nik, jumlah_anggota=:j, latitude=:lat, longitude=:lng, address=:a, kelurahan=:kel, kecamatan=:kec, status_bantuan=:s, jenis_bantuan=:jb, tanggal_bantuan=:tb WHERE id=:id");
|
||||
$stmt->execute([':kk'=>$kk,':nik'=>$nik ?: null,':j'=>$jml,':lat'=>$lat,':lng'=>$lng,':a'=>$addr ?: null,':kel'=>$kel ?: null,':kec'=>$kec ?: null,':s'=>$status ?: 'Belum dibantu',':jb'=>$jb ?: null,':tb'=>$tb ?: null,':id'=>$id]);
|
||||
$msg = 'Berhasil diupdate.';
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO pemukiman_miskin_points (kk_nama, nik, jumlah_anggota, latitude, longitude, address, kelurahan, kecamatan, status_bantuan, jenis_bantuan, tanggal_bantuan) VALUES (:kk,:nik,:j,:lat,:lng,:a,:kel,:kec,:s,:jb,:tb)");
|
||||
$stmt->execute([':kk'=>$kk,':nik'=>$nik ?: null,':j'=>$jml,':lat'=>$lat,':lng'=>$lng,':a'=>$addr ?: null,':kel'=>$kel ?: null,':kec'=>$kec ?: null,':s'=>$status ?: 'Belum dibantu',':jb'=>$jb ?: null,':tb'=>$tb ?: null]);
|
||||
$msg = 'Berhasil ditambahkan.';
|
||||
}
|
||||
} catch (Exception $e) { $err = $e->getMessage(); }
|
||||
}
|
||||
}
|
||||
|
||||
$edit = null;
|
||||
if (isset($_GET['edit'])) {
|
||||
$id = (int)$_GET['edit'];
|
||||
$stmt = $pdo->prepare("SELECT * FROM pemukiman_miskin_points WHERE id=:id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$edit = $stmt->fetch() ?: null;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
try {
|
||||
$cols = $pdo->query("SHOW COLUMNS FROM pemukiman_miskin_points")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$hasNew = in_array('kk_nama', $cols, true);
|
||||
if ($hasNew) {
|
||||
$rows = $pdo->query("
|
||||
SELECT p.*, r.nama AS rumah_ibadah_nama
|
||||
FROM pemukiman_miskin_points p
|
||||
LEFT JOIN rumah_ibadah_points r ON r.id=p.rumah_ibadah_id
|
||||
ORDER BY p.id ASC
|
||||
")->fetchAll();
|
||||
} else {
|
||||
$rows = $pdo->query("SELECT * FROM pemukiman_miskin_points ORDER BY id ASC")->fetchAll();
|
||||
}
|
||||
} catch (Exception $e) {}
|
||||
|
||||
render_header('Admin Penduduk Miskin');
|
||||
?>
|
||||
<div class="admin-card">
|
||||
<div style="display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap">
|
||||
<div style="font-weight:900;font-size:18px"><?= $edit ? 'Edit' : 'Tambah' ?> Penduduk Miskin</div>
|
||||
<div class="actions">
|
||||
<a class="secondary" href="penduduk_miskin.php">Reset</a>
|
||||
<a href="penduduk_miskin.php?export=1">Export CSV</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($msg): ?><div class="notice" style="margin-top:12px;border-color:#bbf7d0;background:#f0fdf4;color:#166534"><?= h($msg) ?></div><?php endif; ?>
|
||||
<?php if ($err): ?><div class="notice" style="margin-top:12px;border-color:#fecaca;background:#fef2f2;color:#991b1b"><?= h($err) ?></div><?php endif; ?>
|
||||
|
||||
<form method="post" style="margin-top:12px">
|
||||
<input type="hidden" name="id" value="<?= h($edit['id'] ?? 0) ?>">
|
||||
<div class="grid-2">
|
||||
<div>
|
||||
<label>Nama Kepala Keluarga</label>
|
||||
<input name="kk_nama" required value="<?= h($edit['kk_nama'] ?? '') ?>">
|
||||
</div>
|
||||
<div>
|
||||
<label>NIK (opsional)</label>
|
||||
<input name="nik" value="<?= h($edit['nik'] ?? '') ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid-2" style="margin-top:10px">
|
||||
<div>
|
||||
<label>Jumlah Anggota</label>
|
||||
<input name="jumlah_anggota" type="number" min="0" step="1" value="<?= h($edit['jumlah_anggota'] ?? 0) ?>">
|
||||
</div>
|
||||
<div>
|
||||
<label>Status Bantuan</label>
|
||||
<select name="status_bantuan">
|
||||
<?php foreach (['Belum dibantu','Menunggu verifikasi','Sudah dibantu'] as $s): ?>
|
||||
<option value="<?= h($s) ?>" <?= (($edit['status_bantuan'] ?? 'Belum dibantu') === $s ? 'selected' : '') ?>><?= h($s) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid-2" style="margin-top:10px">
|
||||
<div>
|
||||
<label>Jenis Bantuan</label>
|
||||
<input name="jenis_bantuan" value="<?= h($edit['jenis_bantuan'] ?? '') ?>">
|
||||
</div>
|
||||
<div>
|
||||
<label>Tanggal Bantuan</label>
|
||||
<input name="tanggal_bantuan" type="date" value="<?= h($edit['tanggal_bantuan'] ?? '') ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label style="margin-top:10px;display:block;">Alamat</label>
|
||||
<input name="address" value="<?= h($edit['address'] ?? '') ?>">
|
||||
|
||||
<div class="grid-2" style="margin-top:10px">
|
||||
<div>
|
||||
<label>Kelurahan</label>
|
||||
<input name="kelurahan" value="<?= h($edit['kelurahan'] ?? '') ?>">
|
||||
</div>
|
||||
<div>
|
||||
<label>Kecamatan</label>
|
||||
<input name="kecamatan" value="<?= h($edit['kecamatan'] ?? '') ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid-2" style="margin-top:10px">
|
||||
<div>
|
||||
<label>Latitude</label>
|
||||
<input name="latitude" required value="<?= h($edit['latitude'] ?? '') ?>">
|
||||
</div>
|
||||
<div>
|
||||
<label>Longitude</label>
|
||||
<input name="longitude" required value="<?= h($edit['longitude'] ?? '') ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-actions" style="margin-top:12px">
|
||||
<button class="btn btn-primary" name="save_penduduk" value="1" type="submit"><?= $edit ? 'Update' : 'Tambah' ?></button>
|
||||
<a class="btn btn-secondary" href="../index.html" style="text-align:center;line-height:38px;text-decoration:none">Kembali ke WebGIS</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="admin-card" style="margin-top:14px">
|
||||
<div style="font-weight:900;font-size:18px;margin-bottom:8px">Import CSV</div>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="csv_file" accept=".csv" required>
|
||||
<button class="btn btn-secondary" name="import_csv" value="1" type="submit" style="margin-top:10px">Import</button>
|
||||
<div style="margin-top:8px;color:#475569;font-weight:800">Kolom minimal: `kk_nama`/`nama`, `lat`, `lng`.</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="admin-card" style="margin-top:14px">
|
||||
<div style="font-weight:900;font-size:18px;margin-bottom:8px">Daftar Penduduk Miskin</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th><th>Kepala Keluarga</th><th>Status</th><th>Rumah Ibadah</th><th>Koordinat</th><th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($rows as $r): ?>
|
||||
<tr>
|
||||
<td><?= (int)$r['id'] ?></td>
|
||||
<td><?= h($r['kk_nama'] ?? $r['nama'] ?? '') ?></td>
|
||||
<td><span class="tag"><?= h($r['status_bantuan'] ?? '-') ?></span></td>
|
||||
<td><?= h($r['rumah_ibadah_nama'] ?? '-') ?></td>
|
||||
<td><?= h(($r['latitude'] ?? '') . ', ' . ($r['longitude'] ?? '')) ?></td>
|
||||
<td class="actions">
|
||||
<a class="secondary" href="penduduk_miskin.php?edit=<?= (int)$r['id'] ?>">Edit</a>
|
||||
<a href="penduduk_miskin.php?delete=<?= (int)$r['id'] ?>" onclick="return confirm('Hapus data ini?')">Hapus</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php render_footer(); ?>
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/_layout.php';
|
||||
require_login();
|
||||
|
||||
$msg = '';
|
||||
$err = '';
|
||||
|
||||
// Delete
|
||||
if (isset($_GET['delete'])) {
|
||||
$id = (int)$_GET['delete'];
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM rumah_ibadah_points WHERE id=:id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$msg = 'Berhasil dihapus.';
|
||||
} catch (Exception $e) {
|
||||
$err = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Save (create/update)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$nama = trim($_POST['nama'] ?? '');
|
||||
$jenis = trim($_POST['jenis'] ?? 'Lainnya');
|
||||
$kontak = trim($_POST['kontak'] ?? '');
|
||||
$radius = (float)($_POST['radius_meter'] ?? 300);
|
||||
$lat = $_POST['latitude'] ?? null;
|
||||
$lng = $_POST['longitude'] ?? null;
|
||||
$address = trim($_POST['address'] ?? '');
|
||||
|
||||
if ($nama === '' || $radius <= 0 || $lat === null || $lng === null) {
|
||||
$err = 'Data belum lengkap (nama/radius/lat/lng).';
|
||||
} else {
|
||||
try {
|
||||
$cols = $pdo->query("SHOW COLUMNS FROM rumah_ibadah_points")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$hasJenis = in_array('jenis', $cols, true);
|
||||
$hasKontak = in_array('kontak', $cols, true);
|
||||
|
||||
if ($id > 0) {
|
||||
if ($hasJenis && $hasKontak) {
|
||||
$stmt = $pdo->prepare("UPDATE rumah_ibadah_points SET nama=:n, jenis=:j, kontak=:k, radius_meter=:r, latitude=:lat, longitude=:lng, address=:a WHERE id=:id");
|
||||
$stmt->execute([':n'=>$nama,':j'=>$jenis ?: 'Lainnya',':k'=>$kontak ?: null,':r'=>$radius,':lat'=>$lat,':lng'=>$lng,':a'=>$address ?: null,':id'=>$id]);
|
||||
} else {
|
||||
$stmt = $pdo->prepare("UPDATE rumah_ibadah_points SET nama=:n, radius_meter=:r, latitude=:lat, longitude=:lng, address=:a WHERE id=:id");
|
||||
$stmt->execute([':n'=>$nama,':r'=>$radius,':lat'=>$lat,':lng'=>$lng,':a'=>$address ?: null,':id'=>$id]);
|
||||
}
|
||||
$msg = 'Berhasil diupdate.';
|
||||
} else {
|
||||
if ($hasJenis && $hasKontak) {
|
||||
$stmt = $pdo->prepare("INSERT INTO rumah_ibadah_points (nama, jenis, kontak, radius_meter, latitude, longitude, address) VALUES (:n,:j,:k,:r,:lat,:lng,:a)");
|
||||
$stmt->execute([':n'=>$nama,':j'=>$jenis ?: 'Lainnya',':k'=>$kontak ?: null,':r'=>$radius,':lat'=>$lat,':lng'=>$lng,':a'=>$address ?: null]);
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO rumah_ibadah_points (nama, radius_meter, latitude, longitude, address) VALUES (:n,:r,:lat,:lng,:a)");
|
||||
$stmt->execute([':n'=>$nama,':r'=>$radius,':lat'=>$lat,':lng'=>$lng,':a'=>$address ?: null]);
|
||||
}
|
||||
$msg = 'Berhasil ditambahkan.';
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$err = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$edit = null;
|
||||
if (isset($_GET['edit'])) {
|
||||
$id = (int)$_GET['edit'];
|
||||
$stmt = $pdo->prepare("SELECT * FROM rumah_ibadah_points WHERE id=:id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$edit = $stmt->fetch() ?: null;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
try {
|
||||
$rows = $pdo->query("
|
||||
SELECT r.*,
|
||||
(SELECT COUNT(*) FROM pemukiman_miskin_points p WHERE p.rumah_ibadah_id=r.id) AS binaan_count
|
||||
FROM rumah_ibadah_points r
|
||||
ORDER BY r.id ASC
|
||||
")->fetchAll();
|
||||
} catch (Exception $e) {}
|
||||
|
||||
render_header('Admin Rumah Ibadah');
|
||||
?>
|
||||
<div class="admin-card">
|
||||
<div style="display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap">
|
||||
<div style="font-weight:900;font-size:18px"><?= $edit ? 'Edit' : 'Tambah' ?> Rumah Ibadah</div>
|
||||
<a class="actions a secondary" href="rumah_ibadah.php" style="background:#e2e8f0;color:#0f172a;border-radius:12px;padding:8px 10px;font-weight:900;text-decoration:none">Reset</a>
|
||||
</div>
|
||||
<?php if ($msg): ?><div class="notice" style="margin-top:12px;border-color:#bbf7d0;background:#f0fdf4;color:#166534"><?= h($msg) ?></div><?php endif; ?>
|
||||
<?php if ($err): ?><div class="notice" style="margin-top:12px;border-color:#fecaca;background:#fef2f2;color:#991b1b"><?= h($err) ?></div><?php endif; ?>
|
||||
|
||||
<form method="post" style="margin-top:12px">
|
||||
<input type="hidden" name="id" value="<?= h($edit['id'] ?? 0) ?>">
|
||||
<div class="grid-2">
|
||||
<div>
|
||||
<label>Nama</label>
|
||||
<input name="nama" required value="<?= h($edit['nama'] ?? '') ?>">
|
||||
</div>
|
||||
<div>
|
||||
<label>Jenis</label>
|
||||
<select name="jenis">
|
||||
<?php foreach (['Masjid','Musholla','Gereja','Katolik','Pura','Vihara','Klenteng','Lainnya'] as $j): ?>
|
||||
<option value="<?= h($j) ?>" <?= (($edit['jenis'] ?? 'Lainnya') === $j ? 'selected' : '') ?>><?= h($j) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<label style="margin-top:10px;display:block;">Kontak</label>
|
||||
<input name="kontak" value="<?= h($edit['kontak'] ?? '') ?>">
|
||||
|
||||
<div class="grid-2" style="margin-top:10px">
|
||||
<div>
|
||||
<label>Radius (meter)</label>
|
||||
<input name="radius_meter" type="number" min="1" step="1" required value="<?= h($edit['radius_meter'] ?? 300) ?>">
|
||||
</div>
|
||||
<div>
|
||||
<label>Alamat</label>
|
||||
<input name="address" value="<?= h($edit['address'] ?? '') ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid-2" style="margin-top:10px">
|
||||
<div>
|
||||
<label>Latitude</label>
|
||||
<input name="latitude" required value="<?= h($edit['latitude'] ?? '') ?>">
|
||||
</div>
|
||||
<div>
|
||||
<label>Longitude</label>
|
||||
<input name="longitude" required value="<?= h($edit['longitude'] ?? '') ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-actions" style="margin-top:12px">
|
||||
<button class="btn btn-primary" type="submit"><?= $edit ? 'Update' : 'Tambah' ?></button>
|
||||
<a class="btn btn-secondary" href="../index.html" style="text-align:center;line-height:38px;text-decoration:none">Kembali ke WebGIS</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="admin-card" style="margin-top:14px">
|
||||
<div style="font-weight:900;font-size:18px;margin-bottom:8px">Daftar Rumah Ibadah</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th><th>Nama</th><th>Jenis</th><th>Radius</th><th>Binaan</th><th>Koordinat</th><th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($rows as $r): ?>
|
||||
<tr>
|
||||
<td><?= (int)$r['id'] ?></td>
|
||||
<td><?= h($r['nama'] ?? '') ?></td>
|
||||
<td><span class="tag"><?= h($r['jenis'] ?? 'Lainnya') ?></span></td>
|
||||
<td><?= (int)($r['radius_meter'] ?? 0) ?> m</td>
|
||||
<td><?= (int)($r['binaan_count'] ?? 0) ?></td>
|
||||
<td><?= h(($r['latitude'] ?? '') . ', ' . ($r['longitude'] ?? '')) ?></td>
|
||||
<td class="actions">
|
||||
<a class="secondary" href="rumah_ibadah.php?edit=<?= (int)$r['id'] ?>">Edit</a>
|
||||
<a href="rumah_ibadah.php?delete=<?= (int)$r['id'] ?>" onclick="return confirm('Hapus data ini?')">Hapus</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php render_footer(); ?>
|
||||
|
||||
Reference in New Issue
Block a user