| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/bpkd/ |
Upload File : |
<?php
/**
* Halaman Laporan & Dokumen - Dengan Filter Kategori via URL
* URL: /laporan (semua) atau /laporan/calk (filter kategori)
*/
require_once 'includes/init.php';
// =====================================================
// DETEKSI KATEGORI DARI URL
// =====================================================
// Contoh: laporan/calk → $category_slug = 'calk'
$category_slug = isset($_GET['kategori']) ? sanitize($_GET['kategori']) : '';
// Jika ada slug kategori, cari di database
$selected_category_id = 0;
$selected_category_name = '';
if (!empty($category_slug)) {
$cat_query = $conn->query("SELECT id, name FROM report_categories WHERE slug = '$category_slug' LIMIT 1");
if ($cat_query && $cat_query->num_rows > 0) {
$cat_data = $cat_query->fetch_assoc();
$selected_category_id = $cat_data['id'];
$selected_category_name = $cat_data['name'];
}
}
// =====================================================
// SET PAGE VARIABLES
// =====================================================
$page_title = 'Laporan & Dokumen';
if (!empty($selected_category_name)) {
$page_title .= ' - ' . $selected_category_name;
}
$page_title .= ' - ' . ($settings['site_title'] ?? 'Website Instansi');
$meta_description = 'Unduh berbagai laporan dan dokumen resmi instansi.';
global $conn;
// =====================================================
// AMBIL DATA LAPORAN (DENGAN FILTER KATEGORI)
// =====================================================
$where_clause = "r.status = 'active'";
if ($selected_category_id > 0) {
$where_clause .= " AND r.category_id = $selected_category_id";
}
$reports = $conn->query("
SELECT r.*, rc.name as category_name, rc.slug as category_slug, m.filename, m.filepath
FROM reports r
LEFT JOIN report_categories rc ON r.category_id = rc.id
LEFT JOIN media m ON r.file_id = m.id
WHERE $where_clause
ORDER BY r.created_at DESC
");
// =====================================================
// AMBIL SEMUA KATEGORI UNTUK FILTER
// =====================================================
$categories = [];
$all_reports = [];
while ($row = $reports->fetch_assoc()) {
$all_reports[] = $row;
if (!empty($row['category_name']) && !in_array($row['category_name'], $categories)) {
$categories[] = $row['category_name'];
}
}
sort($categories);
// =====================================================
// AMBIL DATA KATEGORI UNTUK MENU NAVIGASI
// =====================================================
$all_categories = $conn->query("SELECT id, name, slug FROM report_categories ORDER BY name");
include 'includes/header.php';
?>
<!-- =====================================================
PAGE HEADER
===================================================== -->
<section class="page-header text-white py-4">
<div class="container">
<div class="row align-items-center">
<div class="col-md-8">
<h2 class="mb-2">
<i class="fas fa-file-alt me-2"></i>
Publikasi Keuangan Daerah
<?php if (!empty($selected_category_name)): ?>
<small class="text-light">/ <?php echo htmlspecialchars($selected_category_name); ?></small>
<?php endif; ?>
</h2>
<p class="mb-0">Unduh berbagai laporan dan dokumen resmi instansi.</p>
</div>
<div class="col-md-4 text-md-end mt-3 mt-md-0">
<?php if (!empty($selected_category_name)): ?>
<a href="<?php echo BASE_URL; ?>/laporan" class="btn btn-light btn-sm">
<i class="fas fa-arrow-left me-1"></i> Semua Laporan
</a>
<?php endif; ?>
</div>
</div>
</div>
</section>
<div class="container">
<!-- =====================================================
ALERT ERROR
===================================================== -->
<div class="row">
<?php if (isset($_SESSION['download_error'])): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-triangle me-2"></i>
<?php
echo $_SESSION['download_error'];
unset($_SESSION['download_error']);
?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
</div>
<!-- =====================================================
MAIN CONTENT
===================================================== -->
<div class="row">
<div class="sidebar col-lg-10 mx-auto">
<div class="card mb-3 py-3 mt-3">
<div class="card-body p-4">
<h4 class="text-center">
PUBLIKASI KEUANGAN DAERAH
<?php if (!empty($selected_category_name)): ?>
<small class="text-muted d-block" style="font-size: 0.7rem;">
Kategori: <?php echo htmlspecialchars($selected_category_name); ?>
</small>
<?php endif; ?>
</h4>
<br/>
<div class="row" style="overflow: auto">
<div class="card-body">
<!-- Laporan Section -->
<section class="laporan-section py-2">
<div class="container">
<!-- Filter Bar -->
<div class="card shadow-sm mb-4">
<div class="card-body">
<div class="row g-3 align-items-end">
<div class="col-md-4">
<label class="form-label fw-semibold mb-1">Kategori Laporan</label>
<select id="categoryFilter" class="form-select">
<option value="all">-- Semua Kategori --</option>
<?php foreach ($categories as $cat): ?>
<option value="<?php echo htmlspecialchars($cat); ?>"
<?php echo ($selected_category_name == $cat) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($cat); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-5">
<label class="form-label fw-semibold mb-1">Cari Laporan</label>
<div class="input-group">
<input type="text" id="searchInput" class="form-control" placeholder="Cari judul laporan...">
<button class="btn btn-primary" id="searchBtn" type="button">
<i class="fas fa-search"></i>
</button>
</div>
</div>
<div class="col-md-3">
<button id="resetBtn" class="btn btn-outline-secondary w-100">
<i class="fas fa-sync-alt me-2"></i>Reset Filter
</button>
</div>
</div>
</div>
</div>
<!-- Data Table -->
<div class="card shadow-sm">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0" id="reportsTable">
<thead class="table-light">
<tr>
<th width="5%">No</th>
<th width="40%">Judul Laporan</th>
<th width="15%">Kategori</th>
<th width="15%">Tgl Upload</th>
<th width="10%">Hits</th>
<th width="15%">Aksi</th>
</tr>
</thead>
<tbody id="tableBody">
<?php
$no = 1;
foreach ($all_reports as $report):
?>
<tr data-category="<?php echo htmlspecialchars($report['category_name'] ?? ''); ?>"
data-title="<?php echo htmlspecialchars(strtolower($report['title'])); ?>"
data-date="<?php echo $report['created_at']; ?>">
<td class="text-center"><?php echo $no++; ?></td>
<td>
<strong><?php echo htmlspecialchars($report['title']); ?></strong>
<?php if(!empty($report['description'])): ?>
<br><small class="text-muted"><?php echo htmlspecialchars(substr($report['description'], 0, 80)); ?>...</small>
<?php endif; ?>
</td>
<td>
<?php if(!empty($report['category_name'])): ?>
<span class="badge bg-info"><?php echo htmlspecialchars($report['category_name']); ?></span>
<?php else: ?>
<span class="badge bg-secondary">-</span>
<?php endif; ?>
</td>
<td><?php echo date('d-m-Y', strtotime($report['created_at'])); ?></td>
<td><?php echo $report['download_count'] ?? 0; ?></td>
<td>
<a href="<?php echo BASE_URL; ?>/download.php?id=<?php echo $report['id']; ?>">
<img src="<?php echo BASE_URL; ?>/uploads/statis/pdf1.png" height="40px" width="40px" alt="Download PDF">
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Pagination -->
<div class="card-footer bg-white">
<div class="d-flex justify-content-between align-items-center flex-wrap">
<div class="mb-2 mb-md-0">
<select id="pageSize" class="form-select form-select-sm" style="width: auto; display: inline-block;">
<option value="10">10 per halaman</option>
<option value="15" selected>15 per halaman</option>
<option value="25">25 per halaman</option>
<option value="50">50 per halaman</option>
<option value="all">Semua</option>
</select>
</div>
<div>
<nav>
<ul class="pagination pagination-sm mb-0" id="pagination">
<!-- Pagination akan di-generate oleh JavaScript -->
</ul>
</nav>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<!-- =====================================================
KATEGORI NAVIGASI (TABS/BUTTONS)
===================================================== -->
<div class="row mt-4">
<div class="col-12">
<div class="category-nav mb-4">
<div class="d-flex flex-wrap gap-2">
<a href="<?php echo BASE_URL; ?>/laporan"
class="btn <?php echo empty($category_slug) ? 'btn-primary' : 'btn-outline-primary'; ?>">
<i class="fas fa-th-list me-1"></i> Semua
</a>
<?php while ($cat = $all_categories->fetch_assoc()): ?>
<a href="<?php echo BASE_URL; ?>/laporan/<?php echo $cat['slug']; ?>"
class="btn <?php echo ($category_slug == $cat['slug']) ? 'btn-primary' : 'btn-outline-primary'; ?>">
<?php echo htmlspecialchars($cat['name']); ?>
</a>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- =====================================================
JAVASCRIPT
===================================================== -->
<script>
// Data dari PHP
const BASE_URL = '<?php echo BASE_URL; ?>';
const allReports = <?php echo json_encode($all_reports); ?>;
let currentPage = 1;
let pageSize = 15;
let filteredReports = [...allReports];
// Fungsi untuk merender tabel
function renderTable() {
const tbody = document.getElementById('tableBody');
tbody.innerHTML = '';
let displayReports = filteredReports;
let totalPages = 1;
if (pageSize !== 'all') {
totalPages = Math.ceil(filteredReports.length / pageSize);
const start = (currentPage - 1) * pageSize;
const end = start + pageSize;
displayReports = filteredReports.slice(start, end);
}
let no = (pageSize !== 'all') ? (currentPage - 1) * pageSize + 1 : 1;
displayReports.forEach((report, index) => {
const row = tbody.insertRow();
const cellNo = row.insertCell(0);
cellNo.className = 'text-center';
cellNo.textContent = no++;
const cellTitle = row.insertCell(1);
let titleHtml = `<strong>${escapeHtml(report.title)}</strong>`;
if (report.description) {
titleHtml += `<br><small class="text-muted">${escapeHtml(report.description.substring(0, 80))}${report.description.length > 80 ? '...' : ''}</small>`;
}
cellTitle.innerHTML = titleHtml;
const cellCategory = row.insertCell(2);
if (report.category_name) {
cellCategory.innerHTML = `<span class="badge bg-info">${escapeHtml(report.category_name)}</span>`;
} else {
cellCategory.innerHTML = `<span class="badge bg-secondary">-</span>`;
}
const cellDate = row.insertCell(3);
if (report.created_at) {
const date = new Date(report.created_at);
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();
cellDate.textContent = `${day}-${month}-${year}`;
} else {
cellDate.textContent = '-';
}
const cellHits = row.insertCell(4);
cellHits.textContent = report.download_count ? report.download_count : '-';
const cellAction = row.insertCell(5);
cellAction.innerHTML = `<a href="${BASE_URL}/download.php?id=${report.id}">
<img src="${BASE_URL}/uploads/statis/pdf1.png" height="40px" width="40px" alt="Download PDF"/>
</a>`;
});
if (pageSize !== 'all') {
renderPagination(totalPages);
} else {
document.getElementById('pagination').innerHTML = '';
}
updateInfo();
}
function renderPagination(totalPages) {
const paginationUl = document.getElementById('pagination');
paginationUl.innerHTML = '';
const prevLi = document.createElement('li');
prevLi.className = `page-item ${currentPage === 1 ? 'disabled' : ''}`;
prevLi.innerHTML = `<a class="page-link" href="#" data-page="${currentPage - 1}">«</a>`;
paginationUl.appendChild(prevLi);
let startPage = Math.max(1, currentPage - 2);
let endPage = Math.min(totalPages, currentPage + 2);
if (startPage > 1) {
const firstLi = document.createElement('li');
firstLi.className = 'page-item';
firstLi.innerHTML = `<a class="page-link" href="#" data-page="1">1</a>`;
paginationUl.appendChild(firstLi);
if (startPage > 2) {
const dotsLi = document.createElement('li');
dotsLi.className = 'page-item disabled';
dotsLi.innerHTML = '<span class="page-link">...</span>';
paginationUl.appendChild(dotsLi);
}
}
for (let i = startPage; i <= endPage; i++) {
const li = document.createElement('li');
li.className = `page-item ${i === currentPage ? 'active' : ''}`;
li.innerHTML = `<a class="page-link" href="#" data-page="${i}">${i}</a>`;
paginationUl.appendChild(li);
}
if (endPage < totalPages) {
if (endPage < totalPages - 1) {
const dotsLi = document.createElement('li');
dotsLi.className = 'page-item disabled';
dotsLi.innerHTML = '<span class="page-link">...</span>';
paginationUl.appendChild(dotsLi);
}
const lastLi = document.createElement('li');
lastLi.className = 'page-item';
lastLi.innerHTML = `<a class="page-link" href="#" data-page="${totalPages}">${totalPages}</a>`;
paginationUl.appendChild(lastLi);
}
const nextLi = document.createElement('li');
nextLi.className = `page-item ${currentPage === totalPages ? 'disabled' : ''}`;
nextLi.innerHTML = `<a class="page-link" href="#" data-page="${currentPage + 1}">»</a>`;
paginationUl.appendChild(nextLi);
document.querySelectorAll('#pagination .page-link').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const page = parseInt(this.dataset.page);
if (!isNaN(page) && page >= 1 && page <= totalPages && page !== currentPage) {
currentPage = page;
renderTable();
}
});
});
}
function updateInfo() {
let infoContainer = document.querySelector('.dataTables_info');
if (!infoContainer) {
infoContainer = document.createElement('div');
infoContainer.className = 'dataTables_info small text-muted mt-2';
const footer = document.querySelector('.card-footer .d-flex');
if (footer) footer.prepend(infoContainer);
}
const start = (pageSize !== 'all') ? (currentPage - 1) * pageSize + 1 : 1;
const end = (pageSize !== 'all') ? Math.min(currentPage * pageSize, filteredReports.length) : filteredReports.length;
infoContainer.innerHTML = `Menampilkan ${start} sampai ${end} dari ${filteredReports.length} data`;
}
function escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function applyFilters() {
const selectedCategory = document.getElementById('categoryFilter').value;
const searchText = document.getElementById('searchInput').value.toLowerCase();
filteredReports = allReports.filter(report => {
if (selectedCategory !== 'all' && report.category_name !== selectedCategory) {
return false;
}
if (searchText && !report.title.toLowerCase().includes(searchText)) {
return false;
}
return true;
});
currentPage = 1;
renderTable();
}
// Event listeners
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('categoryFilter').addEventListener('change', applyFilters);
document.getElementById('searchBtn').addEventListener('click', applyFilters);
document.getElementById('searchInput').addEventListener('keyup', function(e) {
if (e.key === 'Enter') applyFilters();
});
document.getElementById('resetBtn').addEventListener('click', function() {
document.getElementById('categoryFilter').value = 'all';
document.getElementById('searchInput').value = '';
filteredReports = [...allReports];
currentPage = 1;
renderTable();
// Redirect ke laporan (tanpa filter)
window.location.href = BASE_URL + '/laporan';
});
document.getElementById('pageSize').addEventListener('change', function() {
pageSize = this.value === 'all' ? 'all' : parseInt(this.value);
currentPage = 1;
renderTable();
});
// Initial render
renderTable();
});
</script>
<style>
/* Table Styles */
.table th {
background-color: #f8f9fc;
border-bottom: 2px solid #e3e6f0;
}
.table td {
vertical-align: middle;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
transition: all 0.3s;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102,126,234,0.3);
}
.badge {
font-weight: 500;
padding: 5px 10px;
}
.pagination .page-item.active .page-link {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-color: #4e73df;
color: white;
}
.pagination .page-link {
color: #4e73df;
cursor: pointer;
}
.pagination .page-link:hover {
background: #e9ecef;
color: #224abe;
}
.dataTables_info {
padding-top: 0.5rem;
}
.category-nav .btn {
border-radius: 20px;
padding: 6px 18px;
font-size: 0.85rem;
}
.page-header {
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
padding: 30px 0;
}
</style>
<?php include 'includes/footer.php'; ?>