| 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/admin/ |
Upload File : |
<?php
$page_title = 'Manajemen Halaman';
require_once 'config/database.php';
require_once '../includes/config.php'; // Load BASE_URL
require_once 'includes/header.php';
require_once 'includes/init.php';
// Cek apakah user adalah admin
if (!in_array($_SESSION['role'], ['superadmin','admin'])) {
redirect(BASE_URL . '/admin/dashboard.php');
}
// =====================================================
// HANDLE DELETE
// =====================================================
if (isset($_GET['delete'])) {
$id = (int)$_GET['delete'];
// Ambil gambar untuk dihapus
$page = $conn->query("SELECT featured_image FROM pages WHERE id = $id")->fetch_assoc();
if ($page && !empty($page['featured_image']) && file_exists(dirname(__DIR__) . "/" . $page['featured_image'])) {
unlink(dirname(__DIR__) . "/" . $page['featured_image']);
}
$conn->query("DELETE FROM pages WHERE id = $id");
redirect(BASE_URL . '/admin/pages.php?msg=deleted');
}
// =====================================================
// PAGINATION SETUP
// =====================================================
$limit = 10;
$current_page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
if ($current_page < 1) $current_page = 1;
$offset = ($current_page - 1) * $limit;
// =====================================================
// SEARCH & FILTER
// =====================================================
$search = isset($_GET['search']) ? sanitize($_GET['search']) : '';
$template_filter = isset($_GET['template']) ? sanitize($_GET['template']) : '';
$status_filter = isset($_GET['status']) ? sanitize($_GET['status']) : '';
// Build WHERE clause
$where = ["1=1"];
if (!empty($search)) {
$where[] = "(title LIKE '%$search%' OR content LIKE '%$search%' OR excerpt LIKE '%$search%')";
}
if (!empty($template_filter)) {
$where[] = "template = '$template_filter'";
}
if (!empty($status_filter)) {
$where[] = "status = '$status_filter'";
}
$where_clause = implode(' AND ', $where);
// =====================================================
// GET TOTAL RECORDS FOR PAGINATION
// =====================================================
$total_query = "SELECT COUNT(*) as total FROM pages WHERE $where_clause";
$total_result = $conn->query($total_query);
$total_records = $total_result->fetch_assoc()['total'];
$total_pages = ceil($total_records / $limit);
// =====================================================
// GET PAGES WITH PAGINATION
// =====================================================
$pages = $conn->query("
SELECT p.*, u.full_name as author_name,
(SELECT title FROM pages WHERE id = p.parent_id) as parent_title
FROM pages p
LEFT JOIN users u ON p.author_id = u.id
WHERE $where_clause
ORDER BY p.menu_order ASC, p.title ASC
LIMIT $offset, $limit
");
// =====================================================
// GET FILTER DATA
// =====================================================
$templates = $conn->query("SELECT DISTINCT template FROM pages WHERE template IS NOT NULL AND template != ''");
// =====================================================
// MESSAGES
// =====================================================
$msg = '';
if (isset($_GET['msg'])) {
if ($_GET['msg'] == 'added') $msg = '<div class="alert alert-success">Halaman berhasil ditambahkan!</div>';
if ($_GET['msg'] == 'updated') $msg = '<div class="alert alert-success">Halaman berhasil diupdate!</div>';
if ($_GET['msg'] == 'deleted') $msg = '<div class="alert alert-success">Halaman berhasil dihapus!</div>';
}
?>
<div class="container-fluid">
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Manajemen Halaman</h1>
<a href="<?php echo BASE_URL; ?>/admin/page-add.php" class="btn btn-primary">
<i class="fas fa-plus me-2"></i>Tambah Halaman Baru
</a>
</div>
<?php echo $msg; ?>
<!-- Search and Filter Card -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-white">
<i class="fas fa-filter me-2"></i>Filter Pencarian
</h6>
</div>
<div class="card-body">
<form method="GET" class="row g-3" action="<?php echo BASE_URL; ?>/admin/pages.php">
<div class="col-md-4">
<label class="form-label">Kata Kunci</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-search"></i></span>
<input type="text" class="form-control" name="search" placeholder="Cari judul atau konten..." value="<?php echo htmlspecialchars($search); ?>">
</div>
</div>
<div class="col-md-3">
<label class="form-label">Template</label>
<select class="form-control" name="template">
<option value="">Semua Template</option>
<?php
if ($templates && $templates->num_rows > 0) {
$templates->data_seek(0);
while($template = $templates->fetch_assoc()):
?>
<option value="<?php echo $template['template']; ?>" <?php echo $template_filter == $template['template'] ? 'selected' : ''; ?>>
<?php echo ucfirst($template['template']); ?>
</option>
<?php
endwhile;
}
?>
</select>
</div>
<div class="col-md-3">
<label class="form-label">Status</label>
<select class="form-control" name="status">
<option value="">Semua Status</option>
<option value="published" <?php echo $status_filter == 'published' ? 'selected' : ''; ?>>Published</option>
<option value="draft" <?php echo $status_filter == 'draft' ? 'selected' : ''; ?>>Draft</option>
</select>
</div>
<div class="col-md-2">
<label class="form-label">Aksi</label>
<div class="d-flex">
<button type="submit" class="btn btn-primary me-2">
<i class="fas fa-filter me-2"></i>Filter
</button>
<a href="<?php echo BASE_URL; ?>/admin/pages.php" class="btn btn-secondary">
<i class="fas fa-sync-alt"></i>
</a>
</div>
</div>
</form>
</div>
</div>
<!-- Pages Table Card -->
<div class="card shadow mb-4">
<div class="card-header py-3 d-flex justify-content-between align-items-center">
<h6 class="m-0 font-weight-bold text-white">
<i class="fas fa-file-alt me-2"></i>Daftar Halaman
<span class="badge bg-primary ms-2"><?php echo $total_records; ?> Total</span>
</h6>
</div>
<div class="card-body">
<?php if ($pages && $pages->num_rows > 0): ?>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Judul</th>
<th>URL</th>
<th>Induk</th>
<th>Template</th>
<th>Status</th>
<th>Penulis</th>
<th>Tanggal</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php while($page = $pages->fetch_assoc()):
$url_prefix = !empty($page['url_prefix']) ? $page['url_prefix'] : 'halaman';
$full_url = BASE_URL . '/' . $url_prefix . '/' . $page['slug'];
?>
<tr>
<td>
<strong><?php echo htmlspecialchars($page['title']); ?></strong>
<?php if(!empty($page['featured_image'])): ?>
<i class="fas fa-image text-primary ms-1" title="Memiliki gambar"></i>
<?php endif; ?>
<?php if($page['parent_id'] > 0): ?>
<span class="badge bg-info ms-1">Sub Halaman</span>
<?php endif; ?>
</div>
<td>
<code><a href="<?php echo $full_url; ?>" target="_blank"><?php echo htmlspecialchars($full_url); ?></a></code>
</div>
<td><?php echo $page['parent_title'] ?: '-'; ?> </div>
<td><span class="badge bg-secondary"><?php echo ucfirst($page['template'] ?: 'default'); ?></span> </div>
<td>
<span class="badge bg-<?php echo $page['status'] == 'published' ? 'success' : 'secondary'; ?>">
<?php echo $page['status'] == 'published' ? 'Published' : 'Draft'; ?>
</span>
</div>
<td><?php echo $page['author_name']; ?> </div>
<td>
<small>
<i class="far fa-calendar-alt me-1"></i><?php echo date('d/m/Y', strtotime($page['created_at'])); ?>
</small>
</div>
<td>
<div class="btn-group" role="group">
<a href="<?php echo $full_url; ?>" target="_blank" class="btn btn-sm btn-info" title="Lihat">
<i class="fas fa-eye"></i>
</a>
<a href="<?php echo BASE_URL; ?>/admin/page-edit.php?id=<?php echo $page['id']; ?>" class="btn btn-sm btn-warning" title="Edit">
<i class="fas fa-edit"></i>
</a>
<a href="<?php echo BASE_URL; ?>/admin/pages.php?delete=<?php echo $page['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Yakin ingin menghapus halaman ini?')" title="Hapus">
<i class="fas fa-trash"></i>
</a>
</div>
</div>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<nav aria-label="Page navigation" class="mt-4">
<ul class="pagination justify-content-center">
<li class="page-item <?php echo $current_page <= 1 ? 'disabled' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/pages.php?page=1&search=<?php echo urlencode($search); ?>&template=<?php echo urlencode($template_filter); ?>&status=<?php echo urlencode($status_filter); ?>">
<i class="fas fa-angle-double-left"></i>
</a>
</li>
<li class="page-item <?php echo $current_page <= 1 ? 'disabled' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/pages.php?page=<?php echo $current_page-1; ?>&search=<?php echo urlencode($search); ?>&template=<?php echo urlencode($template_filter); ?>&status=<?php echo urlencode($status_filter); ?>">
<i class="fas fa-angle-left"></i>
</a>
</li>
<?php
$start = max(1, $current_page - 2);
$end = min($total_pages, $current_page + 2);
if ($start > 1) {
echo '<li class="page-item disabled"><span class="page-link">...</span></li>';
}
for ($i = $start; $i <= $end; $i++):
?>
<li class="page-item <?php echo $i == $current_page ? 'active' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/pages.php?page=<?php echo $i; ?>&search=<?php echo urlencode($search); ?>&template=<?php echo urlencode($template_filter); ?>&status=<?php echo urlencode($status_filter); ?>">
<?php echo $i; ?>
</a>
</li>
<?php endfor;
if ($end < $total_pages) {
echo '<li class="page-item disabled"><span class="page-link">...</span></li>';
}
?>
<li class="page-item <?php echo $current_page >= $total_pages ? 'disabled' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/pages.php?page=<?php echo $current_page+1; ?>&search=<?php echo urlencode($search); ?>&template=<?php echo urlencode($template_filter); ?>&status=<?php echo urlencode($status_filter); ?>">
<i class="fas fa-angle-right"></i>
</a>
</li>
<li class="page-item <?php echo $current_page >= $total_pages ? 'disabled' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/pages.php?page=<?php echo $total_pages; ?>&search=<?php echo urlencode($search); ?>&template=<?php echo urlencode($template_filter); ?>&status=<?php echo urlencode($status_filter); ?>">
<i class="fas fa-angle-double-right"></i>
</a>
</li>
</ul>
</nav>
<div class="text-center text-muted mt-2">
Menampilkan <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $total_records); ?> dari <?php echo $total_records; ?> halaman
</div>
<?php endif; ?>
<?php else: ?>
<div class="text-center py-5">
<i class="fas fa-file-alt fa-4x text-muted mb-3"></i>
<h5>Tidak ada halaman</h5>
<p class="text-muted">Belum ada halaman yang ditemukan dengan filter yang dipilih.</p>
<a href="<?php echo BASE_URL; ?>/admin/page-add.php" class="btn btn-primary">
<i class="fas fa-plus me-2"></i>Tambah Halaman Baru
</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
<script>
// Pass BASE_URL ke JavaScript
const BASE_URL = '<?php echo BASE_URL; ?>';
</script>
<?php
require_once 'includes/footer.php';
?>