| 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 : /bpkd_29052026/admin/ |
Upload File : |
<?php
/**
* File: admin/lelang.php
* Halaman Kelola Lelang (Backend)
*/
require_once 'config/database.php';
require_once 'includes/init.php';
// Cek login
requireLogin();
$page_title = 'Kelola Lelang - ' . ($settings['site_title'] ?? 'Website Instansi');
// Pagination
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
// Filter
$status_filter = isset($_GET['status']) ? sanitize($_GET['status']) : '';
$kategori_filter = isset($_GET['kategori']) ? sanitize($_GET['kategori']) : '';
$search = isset($_GET['search']) ? sanitize($_GET['search']) : '';
// =====================================================
// BUILD QUERY DENGAN PREPARED STATEMENT
// =====================================================
$where = [];
$params = [];
$types = "";
if (!empty($status_filter)) {
$where[] = "status = ?";
$params[] = $status_filter;
$types .= "s";
}
if (!empty($kategori_filter)) {
$where[] = "kategori = ?";
$params[] = $kategori_filter;
$types .= "s";
}
if (!empty($search)) {
$where[] = "(judul LIKE ? OR no_lelang LIKE ?)";
$params[] = "%$search%";
$params[] = "%$search%";
$types .= "ss";
}
$where_clause = !empty($where) ? "WHERE " . implode(" AND ", $where) : "";
// Get total records
$total_sql = "SELECT COUNT(*) as total FROM lelang $where_clause";
if (!empty($params)) {
$stmt = $conn->prepare($total_sql);
$stmt->bind_param($types, ...$params);
$stmt->execute();
$total_result = $stmt->get_result();
$total_records = $total_result->fetch_assoc()['total'];
$stmt->close();
} else {
$total_result = $conn->query($total_sql);
$total_records = $total_result->fetch_assoc()['total'];
}
$total_pages = ceil($total_records / $limit);
// Get data
$sql = "SELECT * FROM lelang $where_clause ORDER BY created_at DESC LIMIT ? OFFSET ?";
$params[] = $limit;
$params[] = $offset;
$types .= "ii";
$stmt = $conn->prepare($sql);
$stmt->bind_param($types, ...$params);
$stmt->execute();
$lelangs = $stmt->get_result();
// Ambil daftar kategori unik untuk filter
$kategori_list = $conn->query("SELECT DISTINCT kategori FROM lelang WHERE kategori IS NOT NULL AND kategori != '' ORDER BY kategori");
include 'includes/header.php';
?>
<style>
/* ============================================
ADMIN LELANG STYLES
Prefix: admin-
============================================ */
/* Status Badge */
.status-badge {
display: inline-block;
padding: 4px 12px;
border-radius: 20px;
font-size: 0.7rem;
font-weight: 600;
text-align: center;
min-width: 70px;
}
.status-draft {
background: #fef3c7;
color: #b45309;
}
.status-publish {
background: #dcfce7;
color: #15803d;
}
.status-closed {
background: #fee2e2;
color: #dc2626;
}
.status-canceled {
background: #f1f5f9;
color: #475569;
}
/* Table Image Preview */
.table-img-preview {
width: 45px;
height: 45px;
object-fit: cover;
border-radius: 8px;
background: #f1f5f9;
}
/* Filter Section */
.filter-section {
background: #f8fafc;
padding: 20px;
border-radius: 12px;
margin-bottom: 24px;
}
.filter-label {
font-weight: 600;
font-size: 0.8rem;
margin-bottom: 6px;
color: #475569;
}
/* Button Group */
.btn-group-action {
display: flex;
gap: 5px;
flex-wrap: wrap;
}
/* Card Header */
.card-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.card-header h3 {
color: white;
}
.card-header .btn-light {
color: #667eea;
}
/* Responsive Table */
@media (max-width: 768px) {
.table-responsive {
font-size: 0.85rem;
}
.btn-group-action {
flex-direction: column;
gap: 4px;
}
.filter-section .row {
flex-direction: column;
gap: 10px;
}
}
</style>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card shadow-sm">
<div class="card-header">
<h3 class="mb-0">
<i class="fas fa-gavel me-2"></i> Kelola Lelang
<a href="lelang_add.php" class="btn btn-light btn-sm float-end">
<i class="fas fa-plus me-1"></i> Tambah Lelang
</a>
</h3>
</div>
<div class="card-body">
<!-- ===================================================== -->
<!-- FILTER SECTION -->
<!-- ===================================================== -->
<div class="filter-section">
<form method="GET" class="row g-3 align-items-end">
<div class="col-md-3">
<label class="filter-label">Status</label>
<select name="status" class="form-select">
<option value="">Semua Status</option>
<option value="draft" <?php echo $status_filter == 'draft' ? 'selected' : ''; ?>>Draft</option>
<option value="publish" <?php echo $status_filter == 'publish' ? 'selected' : ''; ?>>Publish</option>
<option value="closed" <?php echo $status_filter == 'closed' ? 'selected' : ''; ?>>Closed</option>
<option value="canceled" <?php echo $status_filter == 'canceled' ? 'selected' : ''; ?>>Canceled</option>
</select>
</div>
<div class="col-md-3">
<label class="filter-label">Kategori</label>
<select name="kategori" class="form-select">
<option value="">Semua Kategori</option>
<?php if ($kategori_list && $kategori_list->num_rows > 0): ?>
<?php while($kat = $kategori_list->fetch_assoc()): ?>
<option value="<?php echo htmlspecialchars($kat['kategori']); ?>"
<?php echo $kategori_filter == $kat['kategori'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($kat['kategori']); ?>
</option>
<?php endwhile; ?>
<?php else: ?>
<option value="Kendaraan">Kendaraan</option>
<option value="Peralatan">Peralatan dan Mesin</option>
<option value="Tanah">Tanah</option>
<option value="Properti">Properti</option>
<option value="Campuran">Campuran</option>
<option value="Lainnya">Lainnya</option>
<?php endif; ?>
</select>
</div>
<div class="col-md-4">
<label class="filter-label">Cari</label>
<input type="text" name="search" class="form-control"
placeholder="Judul atau No. Lelang..."
value="<?php echo htmlspecialchars($search); ?>">
</div>
<div class="col-md-2">
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary w-100">
<i class="fas fa-search me-1"></i> Filter
</button>
<a href="lelang.php" class="btn btn-secondary w-100">
<i class="fas fa-undo me-1"></i> Reset
</a>
</div>
</div>
</form>
</div>
<!-- Info Hasil Pencarian -->
<?php if (!empty($search) || !empty($status_filter) || !empty($kategori_filter)): ?>
<div class="alert alert-info alert-dismissible fade show mb-3" role="alert">
<i class="fas fa-filter me-2"></i>
Menampilkan <?php echo $total_records; ?> hasil
<?php if (!empty($search)): ?>
untuk pencarian "<?php echo htmlspecialchars($search); ?>"
<?php endif; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<!-- ===================================================== -->
<!-- TABLE DATA -->
<!-- ===================================================== -->
<div class="table-responsive">
<table class="table table-hover table-striped align-middle">
<thead class="table-dark">
<tr>
<th width="50">ID</th>
<th width="70">Gambar</th>
<th>Judul</th>
<th>No. Lelang</th>
<th>Kategori</th>
<th>Harga Awal</th>
<th>Tanggal Mulai</th>
<th>Tanggal Selesai</th>
<th width="100">Status</th>
<th width="120">Aksi</th>
</tr>
</thead>
<tbody>
<?php if ($lelangs && $lelangs->num_rows > 0): ?>
<?php while($row = $lelangs->fetch_assoc()): ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td>
<?php if(!empty($row['gambar_utama'])):
$gambar_path = '';
if (file_exists("../uploads/lelang/" . $row['gambar_utama'])) {
$gambar_path = "../uploads/lelang/" . $row['gambar_utama'];
} elseif (file_exists("../uploads/lelang/" . $row['gambar_utama'])) {
$gambar_path = "../uploads/lelang/" . $row['gambar_utama'];
}
?>
<img src="<?php echo $gambar_path; ?>"
class="table-img-preview"
alt="<?php echo htmlspecialchars($row['judul']); ?>"
onerror="this.src='../assets/images/lelangdef.jpeg'">
<?php else: ?>
<div class="text-center text-muted">
<i class="fas fa-image fa-2x"></i>
</div>
<?php endif; ?>
</td>
<td>
<strong><?php echo htmlspecialchars($row['judul']); ?></strong>
<?php if(!empty($row['slug'])): ?>
<br>
<small class="text-muted">slug: <?php echo htmlspecialchars($row['slug']); ?></small>
<?php endif; ?>
</td>
<td><?php echo htmlspecialchars($row['no_lelang'] ?? '-'); ?></td>
<td>
<span class="badge bg-secondary"><?php echo htmlspecialchars($row['kategori'] ?? 'Umum'); ?></span>
</td>
<td class="fw-bold text-primary">
Rp <?php echo number_format($row['harga_awal'], 0, ',', '.'); ?>
</td>
<td>
<i class="fas fa-calendar-alt text-muted me-1"></i>
<?php echo date('d/m/Y H:i', strtotime($row['tanggal_mulai'])); ?>
</td>
<td>
<i class="fas fa-calendar-check text-muted me-1"></i>
<?php echo date('d/m/Y H:i', strtotime($row['tanggal_selesai'])); ?>
</td>
<td>
<span class="status-badge status-<?php echo $row['status']; ?>">
<?php
$status_label = [
'draft' => 'Draft',
'publish' => 'Publish',
'closed' => 'Closed',
'canceled' => 'Canceled'
];
echo $status_label[$row['status']] ?? ucfirst($row['status']);
?>
</span>
</td>
<td>
<div class="btn-group-action">
<a href="lelang_edit.php?id=<?php echo $row['id']; ?>"
class="btn btn-sm btn-warning"
title="Edit">
<i class="fas fa-edit"></i>
</a>
<a href="lelang_delete.php?id=<?php echo $row['id']; ?>"
class="btn btn-sm btn-danger"
title="Hapus"
onclick="return confirm('Yakin ingin menghapus lelang ini? Tindakan ini tidak dapat dibatalkan.')">
<i class="fas fa-trash"></i>
</a>
<a href="../lelang/<?php echo $row['slug']; ?>"
target="_blank"
class="btn btn-sm btn-info"
title="Lihat di Frontend">
<i class="fas fa-eye"></i>
</a>
</div>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="10" class="text-center py-5">
<i class="fas fa-gavel fa-3x text-muted mb-3"></i>
<h5 class="text-muted">Belum ada data lelang</h5>
<p class="text-muted small">Silakan tambah lelang baru dengan klik tombol "Tambah Lelang"</p>
</td>
</tr>
<?php endif; ?>
</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 $page <= 1 ? 'disabled' : ''; ?>">
<a class="page-link" href="?page=<?php echo $page-1; ?>&status=<?php echo urlencode($status_filter); ?>&kategori=<?php echo urlencode($kategori_filter); ?>&search=<?php echo urlencode($search); ?>">
<i class="fas fa-chevron-left"></i>
</a>
</li>
<?php
$start_page = max(1, $page - 2);
$end_page = min($total_pages, $page + 2);
if ($start_page > 1): ?>
<li class="page-item">
<a class="page-link" href="?page=1&status=<?php echo urlencode($status_filter); ?>&kategori=<?php echo urlencode($kategori_filter); ?>&search=<?php echo urlencode($search); ?>">1</a>
</li>
<?php if ($start_page > 2): ?>
<li class="page-item disabled"><span class="page-link">...</span></li>
<?php endif; ?>
<?php endif; ?>
<?php for($i = $start_page; $i <= $end_page; $i++): ?>
<li class="page-item <?php echo $i == $page ? 'active' : ''; ?>">
<a class="page-link" href="?page=<?php echo $i; ?>&status=<?php echo urlencode($status_filter); ?>&kategori=<?php echo urlencode($kategori_filter); ?>&search=<?php echo urlencode($search); ?>">
<?php echo $i; ?>
</a>
</li>
<?php endfor; ?>
<?php if ($end_page < $total_pages): ?>
<?php if ($end_page < $total_pages - 1): ?>
<li class="page-item disabled"><span class="page-link">...</span></li>
<?php endif; ?>
<li class="page-item">
<a class="page-link" href="?page=<?php echo $total_pages; ?>&status=<?php echo urlencode($status_filter); ?>&kategori=<?php echo urlencode($kategori_filter); ?>&search=<?php echo urlencode($search); ?>">
<?php echo $total_pages; ?>
</a>
</li>
<?php endif; ?>
<li class="page-item <?php echo $page >= $total_pages ? 'disabled' : ''; ?>">
<a class="page-link" href="?page=<?php echo $page+1; ?>&status=<?php echo urlencode($status_filter); ?>&kategori=<?php echo urlencode($kategori_filter); ?>&search=<?php echo urlencode($search); ?>">
<i class="fas fa-chevron-right"></i>
</a>
</li>
</ul>
</nav>
<?php endif; ?>
<!-- Info Data -->
<div class="text-center text-muted small mt-3">
<i class="fas fa-database me-1"></i>
Total <?php echo $total_records; ?> data lelang
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Konfirmasi delete dengan Sweet Alert style
document.querySelectorAll('.btn-danger').forEach(btn => {
btn.addEventListener('click', function(e) {
if (!confirm('Yakin ingin menghapus lelang ini? Tindakan ini tidak dapat dibatalkan.')) {
e.preventDefault();
}
});
});
</script>
<?php require_once 'includes/footer.php'; ?>