%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: daftar & kelola dokumen informasi publik.
*
* Query string:
* ?kategori=slug Filter satu kategori KIP.
* ?tipe=regulasi Filter seluruh kategori bertipe regulasi.
* ?q=kata Pencarian judul.
*/
require_once dirname(__DIR__) . '/config/config.php';
require_once dirname(__DIR__) . '/includes/auth.php';
require_once dirname(__DIR__) . '/includes/queries.php';
require_admin();
$slug = get_param('kategori');
$tipe = get_param('tipe');
$keyword = get_param('q');
$activeKat = $slug ? get_kategori_by_slug($slug) : null;
$activeSlug = $activeKat ? $activeKat['slug'] : ($tipe === 'regulasi' ? 'regulasi' : '');
// Scope UPD: admin UPD hanya boleh melihat & mengelola dokumen UPD-nya.
// Admin pusat dapat memfilter berdasarkan UPD (?upd=utama | id).
$scopeUpd = is_upd_admin() ? current_upd_id() : null;
$updParam = $scopeUpd === null ? get_param('upd') : '';
$updListFilter = $scopeUpd === null ? get_upd_list() : [];
$where = [];
$params = [];
if ($activeKat) {
$where[] = 'd.kategori_id = :kat';
$params[':kat'] = $activeKat['id'];
} elseif ($tipe === 'regulasi') {
$where[] = "k.tipe = 'regulasi'";
}
if ($scopeUpd !== null) {
$where[] = 'd.upd_id = :scopeupd';
$params[':scopeupd'] = $scopeUpd;
} elseif ($updParam === 'utama') {
$where[] = 'd.upd_id IS NULL';
} elseif (ctype_digit($updParam) && (int) $updParam > 0) {
$where[] = 'd.upd_id = :updf';
$params[':updf'] = (int) $updParam;
}
if ($keyword !== '') {
$where[] = '(d.judul LIKE :kw1 OR d.unit_kerja LIKE :kw2)';
$like = '%' . $keyword . '%';
$params[':kw1'] = $like;
$params[':kw2'] = $like;
}
$whereSql = $where ? 'WHERE ' . implode(' AND ', $where) : '';
$stmt = db()->prepare(
"SELECT d.*, k.nama AS kategori_nama, k.warna, k.icon,
u.nama AS upd_nama, u.singkatan AS upd_singkatan
FROM dokumen_informasi d
JOIN kategori_informasi k ON k.id = d.kategori_id
LEFT JOIN upd u ON u.id = d.upd_id
$whereSql
ORDER BY d.created_at DESC"
);
$stmt->execute($params);
$rows = $stmt->fetchAll();
$judulHalaman = $activeKat['nama'] ?? ($tipe === 'regulasi' ? 'Regulasi & Peraturan' : 'Semua Dokumen');
$pageTitle = $judulHalaman . ' — CMS PPID';
$activeMenu = 'dokumen';
require __DIR__ . '/partials/head.php';
?>
<div class="flex flex-col md:flex-row md:items-center justify-between mb-6 gap-4">
<div>
<h2 class="text-2xl font-bold text-slate-900"><?= e($judulHalaman) ?></h2>
<p class="text-sm text-slate-500 mt-1"><?= count($rows) ?> dokumen tersimpan.</p>
</div>
<div class="flex flex-wrap items-center gap-3">
<form method="get" class="flex items-center gap-2">
<?php if ($slug): ?><input type="hidden" name="kategori" value="<?= e($slug) ?>"><?php endif; ?>
<?php if ($tipe): ?><input type="hidden" name="tipe" value="<?= e($tipe) ?>"><?php endif; ?>
<?php if ($scopeUpd === null): ?>
<select name="upd" onchange="this.form.submit()" class="bg-white border border-slate-200 rounded-lg px-3 py-2.5 text-sm text-slate-700 outline-none focus:border-mateng-blue cursor-pointer">
<option value="">Semua Unit</option>
<option value="utama" <?= $updParam === 'utama' ? 'selected' : '' ?>>PPID Utama (Pusat)</option>
<?php foreach ($updListFilter as $u): ?>
<option value="<?= (int) $u['id'] ?>" <?= $updParam === (string) $u['id'] ? 'selected' : '' ?>><?= e($u['singkatan'] ?: $u['nama']) ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
<div class="flex items-center bg-white px-4 py-2 rounded-lg border border-slate-200 focus-within:border-mateng-blue transition-colors">
<i class="fas fa-search text-slate-400 mr-2"></i>
<input type="text" name="q" value="<?= e($keyword) ?>" placeholder="Cari judul..." class="bg-transparent outline-none text-sm w-36 lg:w-52 text-slate-700">
</div>
</form>
<a href="<?= e(url('admin/dokumen-form.php' . ($activeKat ? '?kategori=' . $activeKat['id'] : ''))) ?>" class="bg-mateng-blue hover:bg-sky-700 text-white px-4 py-2.5 rounded-lg text-sm font-semibold transition-colors flex items-center gap-2 shrink-0">
<i class="fas fa-plus"></i> <span class="hidden sm:inline">Tambah</span> Dokumen
</a>
</div>
</div>
<div class="bg-white border border-slate-100 rounded-xl shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-left border-collapse">
<thead>
<tr class="bg-slate-50 text-slate-500 text-xs uppercase tracking-wider">
<th class="px-6 py-4 font-semibold">Judul Dokumen</th>
<th class="px-6 py-4 font-semibold">Kategori</th>
<?php if ($scopeUpd === null): ?><th class="px-6 py-4 font-semibold">Unit (UPD)</th><?php endif; ?>
<th class="px-6 py-4 font-semibold">Tahun</th>
<th class="px-6 py-4 font-semibold text-center">Unduhan</th>
<th class="px-6 py-4 font-semibold">Status</th>
<th class="px-6 py-4 font-semibold text-center">Aksi</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-slate-100 text-slate-700">
<?php if (empty($rows)): ?>
<tr><td colspan="<?= $scopeUpd === null ? 7 : 6 ?>" class="px-6 py-12 text-center text-slate-400"><i class="fas fa-folder-open text-3xl mb-2 block"></i>Belum ada dokumen.</td></tr>
<?php else: foreach ($rows as $d):
$adaFile = !empty($d['file_name']) && is_file(UPLOAD_PATH . '/dokumen/' . $d['file_name']); ?>
<tr class="hover:bg-slate-50/50 transition-colors">
<td class="px-6 py-4">
<div class="flex items-center gap-3">
<i class="fas <?= $adaFile ? e(file_icon($d['file_original'] ?? '')) : 'fa-file-circle-xmark text-slate-300' ?> text-lg"></i>
<div>
<div class="font-medium text-slate-800 max-w-md truncate"><?= e($d['judul']) ?></div>
<?php if ($d['unit_kerja']): ?><div class="text-xs text-slate-400"><?= e($d['unit_kerja']) ?></div><?php endif; ?>
</div>
</div>
</td>
<td class="px-6 py-4"><span class="text-xs font-semibold text-slate-600 bg-slate-100 px-2 py-1 rounded-full"><?= e($d['kategori_nama']) ?></span></td>
<?php if ($scopeUpd === null): ?>
<td class="px-6 py-4">
<?php if (!empty($d['upd_singkatan']) || !empty($d['upd_nama'])): ?>
<span class="text-xs font-semibold text-mateng-blue bg-blue-50 px-2 py-1 rounded-full" title="<?= e($d['upd_nama']) ?>"><?= e($d['upd_singkatan'] ?: $d['upd_nama']) ?></span>
<?php else: ?>
<span class="text-xs text-slate-400">PPID Utama</span>
<?php endif; ?>
</td>
<?php endif; ?>
<td class="px-6 py-4"><?= e($d['tahun'] ?: '-') ?></td>
<td class="px-6 py-4 text-center"><?= (int) $d['downloads'] ?></td>
<td class="px-6 py-4">
<?php if ($d['status'] === 'publish'): ?>
<span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold bg-green-50 text-mateng-green border border-green-200">Terbit</span>
<?php else: ?>
<span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold bg-slate-100 text-slate-500 border border-slate-200">Draf</span>
<?php endif; ?>
</td>
<td class="px-6 py-4">
<div class="flex items-center justify-center gap-1">
<a href="<?= e(url('dokumen.php?id=' . $d['id'])) ?>" target="_blank" class="p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700 rounded-lg transition-colors" title="Lihat"><i class="fas fa-eye"></i></a>
<a href="<?= e(url('admin/dokumen-form.php?id=' . $d['id'])) ?>" class="p-2 text-mateng-blue hover:bg-blue-50 rounded-lg transition-colors" title="Edit"><i class="fas fa-pen"></i></a>
<form method="post" action="<?= e(url('admin/dokumen-hapus.php')) ?>" onsubmit="return confirm('Hapus dokumen ini secara permanen?');" class="inline">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $d['id'] ?>">
<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>
</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
</div>
<?php require __DIR__ . '/partials/foot.php'; ?>