%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php
/**
* Admin: kelola kotak saran dari masyarakat.
*/
require_once dirname(__DIR__) . '/config/config.php';
require_once dirname(__DIR__) . '/includes/auth.php';
require_once dirname(__DIR__) . '/includes/queries.php';
require_central();
// Aksi: tandai dibaca / tandai baru / hapus.
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_verify();
$id = (int) post_param('id');
$action = post_param('action');
if ($id > 0) {
if ($action === 'dibaca') {
db()->prepare("UPDATE saran SET status = 'dibaca' WHERE id = ?")->execute([$id]);
set_flash('success', 'Saran ditandai sudah dibaca.');
} elseif ($action === 'baru') {
db()->prepare("UPDATE saran SET status = 'baru' WHERE id = ?")->execute([$id]);
set_flash('success', 'Saran ditandai sebagai baru.');
} elseif ($action === 'hapus') {
db()->prepare('DELETE FROM saran WHERE id = ?')->execute([$id]);
set_flash('success', 'Saran berhasil dihapus.');
}
}
redirect('admin/saran.php' . (get_param('status') ? '?status=' . get_param('status') : ''));
}
$status = get_param('status');
$where = '';
$params = [];
if (in_array($status, ['baru', 'dibaca'], true)) {
$where = 'WHERE status = ?';
$params[] = $status;
}
$stmt = db()->prepare("SELECT * FROM saran $where ORDER BY created_at DESC");
$stmt->execute($params);
$rows = $stmt->fetchAll();
$kategoriBadge = [
'saran' => 'bg-blue-50 text-mateng-blue border-blue-200',
'kritik' => 'bg-red-50 text-red-600 border-red-200',
'pertanyaan' => 'bg-amber-50 text-mateng-gold border-amber-200',
'apresiasi' => 'bg-green-50 text-mateng-green border-green-200',
'lainnya' => 'bg-slate-100 text-slate-600 border-slate-200',
];
$pageTitle = 'Kotak Saran — CMS PPID';
$activeMenu = 'saran';
require __DIR__ . '/partials/head.php';
?>
<div class="mb-6">
<h2 class="text-2xl font-bold text-slate-900">Kotak Saran</h2>
<p class="text-sm text-slate-500 mt-1">Saran & masukan yang disampaikan masyarakat.</p>
</div>
<div class="flex flex-wrap gap-2 mb-6">
<?php foreach (['' => 'Semua', 'baru' => 'Belum Dibaca', 'dibaca' => 'Sudah Dibaca'] as $key => $label): ?>
<a href="<?= e(url('admin/saran.php' . ($key ? '?status=' . $key : ''))) ?>" class="px-4 py-2 rounded-lg text-sm font-medium border transition-colors <?= $status === $key ? 'bg-mateng-green text-white border-mateng-green' : 'bg-white text-slate-600 border-slate-200 hover:border-mateng-green' ?>"><?= e($label) ?></a>
<?php endforeach; ?>
</div>
<?php if (empty($rows)): ?>
<div class="text-center py-16 bg-white rounded-xl border border-slate-100">
<i class="fas fa-comment-slash text-4xl text-slate-300 mb-3"></i>
<p class="text-slate-500 font-medium">Belum ada saran pada kategori ini.</p>
</div>
<?php else: ?>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-5">
<?php foreach ($rows as $s): ?>
<div class="bg-white border <?= $s['status'] === 'baru' ? 'border-mateng-green/40' : 'border-slate-100' ?> rounded-xl shadow-sm p-5 flex flex-col">
<div class="flex items-center justify-between gap-2 mb-3">
<span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold border capitalize <?= $kategoriBadge[$s['kategori']] ?? $kategoriBadge['lainnya'] ?>"><?= e($s['kategori']) ?></span>
<?php if ($s['status'] === 'baru'): ?>
<span class="inline-flex items-center gap-1 text-xs font-semibold text-mateng-green"><i class="fas fa-circle text-[8px]"></i> Baru</span>
<?php else: ?>
<span class="text-xs text-slate-400"><i class="fas fa-check mr-1"></i>Dibaca</span>
<?php endif; ?>
</div>
<p class="text-slate-700 text-sm leading-relaxed mb-4 flex-grow whitespace-pre-line"><?= e($s['isi']) ?></p>
<div class="flex items-center justify-between border-t border-slate-100 pt-3 text-xs text-slate-500">
<div>
<span class="font-semibold text-slate-700"><?= e($s['nama'] ?: 'Anonim') ?></span>
<?php if ($s['email']): ?><span class="text-slate-400"> · <?= e($s['email']) ?></span><?php endif; ?>
<div class="text-slate-400 mt-0.5"><i class="far fa-clock mr-1"></i><?= e(tanggal_id($s['created_at'], true)) ?></div>
</div>
<div class="flex items-center gap-1">
<?php if ($s['status'] === 'baru'): ?>
<form method="post" class="inline">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $s['id'] ?>">
<input type="hidden" name="action" value="dibaca">
<button type="submit" class="p-2 text-mateng-green hover:bg-green-50 rounded-lg transition-colors" title="Tandai dibaca"><i class="fas fa-check-double"></i></button>
</form>
<?php else: ?>
<form method="post" class="inline">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $s['id'] ?>">
<input type="hidden" name="action" value="baru">
<button type="submit" class="p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700 rounded-lg transition-colors" title="Tandai belum dibaca"><i class="fas fa-rotate-left"></i></button>
</form>
<?php endif; ?>
<?php if ($s['email']): ?>
<a href="mailto:<?= e($s['email']) ?>" class="p-2 text-mateng-blue hover:bg-blue-50 rounded-lg transition-colors" title="Balas via email"><i class="fas fa-reply"></i></a>
<?php endif; ?>
<form method="post" class="inline" onsubmit="return confirm('Hapus saran ini?');">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $s['id'] ?>">
<input type="hidden" name="action" value="hapus">
<button type="submit" class="p-2 text-red-500 hover:bg-red-50 rounded-lg transition-colors" title="Hapus"><i class="fas fa-trash"></i></button>
</form>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php require __DIR__ . '/partials/foot.php'; ?>