| 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 Laporan';
require_once 'config/database.php';
require_once '../includes/config.php'; // Load BASE_URL
require_once 'includes/init.php';
requireLogin();
// =====================================================
// HANDLE ADD CATEGORY
// =====================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_category'])) {
$name = sanitize($_POST['category_name']);
$slug = createSlug($name);
$description = sanitize($_POST['category_description']);
// Cek slug duplikat
$check = $conn->query("SELECT id FROM report_categories WHERE slug = '$slug'");
if ($check->num_rows > 0) {
$slug = $slug . '-' . rand(100, 999);
}
$query = "INSERT INTO report_categories (name, slug, description) VALUES ('$name', '$slug', '$description')";
if ($conn->query($query)) {
$msg = '<div class="alert alert-success">Kategori berhasil ditambahkan!</div>';
} else {
$error = "Error: " . $conn->error;
}
}
// =====================================================
// HANDLE EDIT CATEGORY
// =====================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit_category'])) {
$id = (int)$_POST['category_id'];
$name = sanitize($_POST['category_name']);
$slug = createSlug($name);
$description = sanitize($_POST['category_description']);
$query = "UPDATE report_categories SET name = '$name', slug = '$slug', description = '$description' WHERE id = $id";
if ($conn->query($query)) {
$msg = '<div class="alert alert-success">Kategori berhasil diupdate!</div>';
} else {
$error = "Error: " . $conn->error;
}
}
// =====================================================
// HANDLE DELETE CATEGORY
// =====================================================
if (isset($_GET['delete_category'])) {
$id = (int)$_GET['delete_category'];
// Cek apakah kategori sedang digunakan
$check = $conn->query("SELECT id FROM reports WHERE category_id = $id");
if ($check->num_rows > 0) {
$error = "Kategori tidak dapat dihapus karena masih digunakan oleh laporan!";
} else {
$conn->query("DELETE FROM report_categories WHERE id = $id");
$msg = '<div class="alert alert-success">Kategori berhasil dihapus!</div>';
}
}
// =====================================================
// HANDLE ADD REPORT
// =====================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_report'])) {
$title = sanitize($_POST['title']);
$description = sanitize($_POST['description']);
$file_id = (int)$_POST['file_id'];
$category_id = (int)$_POST['category_id'];
$status = sanitize($_POST['status']);
$report_order = (int)$_POST['report_order'];
// Ambil info file dari media
$file = $conn->query("SELECT filepath, filesize FROM media WHERE id = $file_id")->fetch_assoc();
$file_size = $file ? formatBytes($file['filesize']) : '';
$query = "INSERT INTO reports (title, description, file_id, category_id, file_size, status, report_order)
VALUES ('$title', '$description', $file_id, $category_id, '$file_size', '$status', $report_order)";
if ($conn->query($query)) {
redirect(BASE_URL . '/admin/reports.php?msg=added');
} else {
$error = "Error: " . $conn->error;
}
}
// =====================================================
// HANDLE EDIT REPORT
// =====================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit_report'])) {
$id = (int)$_POST['id'];
$title = sanitize($_POST['title']);
$description = sanitize($_POST['description']);
$file_id = (int)$_POST['file_id'];
$category_id = (int)$_POST['category_id'];
$status = sanitize($_POST['status']);
$report_order = (int)$_POST['report_order'];
// format menjadi timestamp
$created_at = date('Y-m-d H:i:s', strtotime($_POST['created_at']));
$file = $conn->query("SELECT filepath, filesize FROM media WHERE id = $file_id")->fetch_assoc();
$file_size = $file ? formatBytes($file['filesize']) : '';
$query = "UPDATE reports SET
title = '$title',
description = '$description',
file_id = $file_id,
category_id = $category_id,
file_size = '$file_size',
status = '$status',
report_order = $report_order,
created_at = '$created_at'
WHERE id = $id";
if ($conn->query($query)) {
redirect(BASE_URL . '/admin/reports.php?msg=updated');
} else {
$error = "Error: " . $conn->error;
}
}
// =====================================================
// HANDLE DELETE REPORT
// =====================================================
if (isset($_GET['delete_report'])) {
$id = (int)$_GET['delete_report'];
$conn->query("DELETE FROM reports WHERE id = $id");
redirect(BASE_URL . '/admin/reports.php?msg=deleted');
}
// =====================================================
// HANDLE RESET DOWNLOAD COUNT
// =====================================================
if (isset($_GET['reset_count'])) {
$id = (int)$_GET['reset_count'];
$conn->query("UPDATE reports SET download_count = 0 WHERE id = $id");
redirect(BASE_URL . '/admin/reports.php?msg=reset');
}
// =====================================================
// PAGINATION
// =====================================================
$limit = 10;
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$offset = ($page - 1) * $limit;
// Search
$search = isset($_GET['search']) ? sanitize($_GET['search']) : '';
$where = '';
if ($search) {
$where = "WHERE r.title LIKE '%$search%' OR r.description LIKE '%$search%' OR rc.name LIKE '%$search%'";
}
// Total records
$total = $conn->query("SELECT COUNT(*) as total FROM reports r LEFT JOIN report_categories rc ON r.category_id = rc.id $where")->fetch_assoc()['total'];
$total_pages = ceil($total / $limit);
// Get reports
$reports = $conn->query("
SELECT r.*, m.filename, m.filepath, rc.name as category_name, rc.id as category_id_ref
FROM reports r
LEFT JOIN media m ON r.file_id = m.id
LEFT JOIN report_categories rc ON r.category_id = rc.id
$where
ORDER BY r.report_order ASC, r.created_at DESC
LIMIT $offset, $limit
");
// Get media files for dropdown
$media_files = $conn->query("SELECT id, filename, filepath FROM media ORDER BY created_at DESC");
// Get categories for dropdown
$categories = $conn->query("SELECT * FROM report_categories WHERE status = 'active' ORDER BY name");
// Get for edit
$edit_report = null;
if (isset($_GET['edit'])) {
$id = (int)$_GET['edit'];
$result = $conn->query("SELECT * FROM reports WHERE id = $id");
$edit_report = $result->fetch_assoc();
}
// Get for edit category
$edit_category = null;
if (isset($_GET['edit_category'])) {
$id = (int)$_GET['edit_category'];
$result = $conn->query("SELECT * FROM report_categories WHERE id = $id");
$edit_category = $result->fetch_assoc();
}
$msg = '';
if (isset($_GET['msg'])) {
if ($_GET['msg'] == 'added') $msg = '<div class="alert alert-success">Laporan berhasil ditambahkan!</div>';
if ($_GET['msg'] == 'updated') $msg = '<div class="alert alert-success">Laporan berhasil diupdate!</div>';
if ($_GET['msg'] == 'deleted') $msg = '<div class="alert alert-success">Laporan berhasil dihapus!</div>';
if ($_GET['msg'] == 'reset') $msg = '<div class="alert alert-success">Jumlah download berhasil direset!</div>';
}
require_once 'includes/header.php';
?>
<style>
/* Modal styles */
.modal-lg {
max-width: 800px;
}
.category-badge {
background: #e9ecef;
color: #495057;
padding: 5px 10px;
border-radius: 5px;
font-size: 0.8rem;
display: inline-block;
}
.category-badge i {
margin-right: 5px;
}
/* Category list styles */
.category-list-item {
transition: all 0.2s;
}
.category-list-item:hover {
background: #f8f9fc;
transform: translateX(5px);
}
.category-stats {
font-size: 0.7rem;
}
</style>
<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">
<i class="fas fa-download me-2"></i>Manajemen Laporan
</h1>
<div>
<button type="button" class="btn btn-info me-2" data-bs-toggle="modal" data-bs-target="#categoryModal">
<i class="fas fa-tags me-2"></i>Kelola Kategori
</button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addReportModal">
<i class="fas fa-plus me-2"></i>Tambah Laporan
</button>
</div>
</div>
<?php echo $msg; ?>
<?php if (isset($error)) echo '<div class="alert alert-danger">' . $error . '</div>'; ?>
<!-- Search -->
<div class="card shadow mb-4">
<div class="card-body">
<form method="GET" class="row g-3" action="<?php echo BASE_URL; ?>/admin/reports.php">
<div class="col-md-10">
<input type="text" class="form-control" name="search" placeholder="Cari laporan..." value="<?php echo htmlspecialchars($search); ?>">
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary w-100">
<i class="fas fa-search me-2"></i>Cari
</button>
</div>
</form>
</div>
</div>
<!-- Add Report Modal -->
<div class="modal fade" id="addReportModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" action="<?php echo BASE_URL; ?>/admin/reports.php">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-plus-circle me-2"></i>Tambah Laporan Baru
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label">Judul Laporan <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="title" required>
</div>
<div class="mb-3">
<label class="form-label">Deskripsi</label>
<textarea class="form-control" name="description" rows="3"></textarea>
</div>
<div class="mb-3">
<label class="form-label">File <span class="text-danger">*</span></label>
<select class="form-control" name="file_id" required>
<option value="">Pilih File</option>
<?php
if ($media_files && $media_files->num_rows > 0) {
$media_files->data_seek(0);
while($file = $media_files->fetch_assoc()):
?>
<option value="<?php echo $file['id']; ?>">
<?php echo htmlspecialchars($file['filename']); ?>
</option>
<?php
endwhile;
}
?>
</select>
<small class="text-muted">
<a href="<?php echo BASE_URL; ?>/admin/media_manager.php" target="_blank">Upload file baru</a> jika belum ada
</small>
</div>
<div class="mb-3">
<label class="form-label">Kategori</label>
<div class="input-group">
<select class="form-control" name="category_id" id="categorySelect">
<option value="0">-- Pilih Kategori --</option>
<?php
if ($categories && $categories->num_rows > 0) {
$categories->data_seek(0);
while($cat = $categories->fetch_assoc()):
?>
<option value="<?php echo $cat['id']; ?>"><?php echo htmlspecialchars($cat['name']); ?></option>
<?php
endwhile;
}
?>
</select>
<button type="button" class="btn btn-outline-primary" onclick="openQuickAddCategory()">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Urutan</label>
<input type="number" class="form-control" name="report_order" value="0">
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Status</label>
<select class="form-control" name="status">
<option value="active">Aktif</option>
<option value="inactive">Tidak Aktif</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
<button type="submit" name="add_report" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Simpan
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Report Modal -->
<?php if ($edit_report): ?>
<div class="modal fade" id="editReportModal" tabindex="-1" data-bs-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" action="<?php echo BASE_URL; ?>/admin/reports.php">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-edit me-2"></i>Edit Laporan
</h5>
<a href="<?php echo BASE_URL; ?>/admin/reports.php" class="btn-close"></a>
</div>
<div class="modal-body">
<input type="hidden" name="id" value="<?php echo $edit_report['id']; ?>">
<div class="mb-3">
<label class="form-label">Judul Laporan <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="title" value="<?php echo htmlspecialchars($edit_report['title']); ?>" required>
</div>
<div class="mb-3">
<label class="form-label">Deskripsi</label>
<textarea class="form-control" name="description" rows="3"><?php echo htmlspecialchars($edit_report['description']); ?></textarea>
</div>
<div class="mb-3">
<label class="form-label">File <span class="text-danger">*</span></label>
<select class="form-control" name="file_id" required>
<option value="">Pilih File</option>
<?php
if ($media_files && $media_files->num_rows > 0) {
$media_files->data_seek(0);
while($file = $media_files->fetch_assoc()):
?>
<option value="<?php echo $file['id']; ?>" <?php echo $file['id'] == $edit_report['file_id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($file['filename']); ?>
</option>
<?php
endwhile;
}
?>
</select>
</div>
<div class="mb-3">
<label class="form-label">TglUpload <span class="text-danger">*</span></label>
<input type="date" class="form-control" name="created_at" value="<?php echo date('Y-m-d', strtotime($edit_report['created_at'])); ?>">
</div>
<div class="mb-3">
<label class="form-label">Kategori</label>
<div class="input-group">
<select class="form-control" name="category_id" id="editCategorySelect">
<option value="0">-- Pilih Kategori --</option>
<?php
if ($categories && $categories->num_rows > 0) {
$categories->data_seek(0);
while($cat = $categories->fetch_assoc()):
?>
<option value="<?php echo $cat['id']; ?>" <?php echo $cat['id'] == $edit_report['category_id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($cat['name']); ?>
</option>
<?php
endwhile;
}
?>
</select>
<button type="button" class="btn btn-outline-primary" onclick="openQuickAddCategoryEdit()">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Urutan</label>
<input type="number" class="form-control" name="report_order" value="<?php echo $edit_report['report_order']; ?>">
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Status</label>
<select class="form-control" name="status">
<option value="active" <?php echo $edit_report['status'] == 'active' ? 'selected' : ''; ?>>Aktif</option>
<option value="inactive" <?php echo $edit_report['status'] == 'inactive' ? 'selected' : ''; ?>>Tidak Aktif</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<a href="<?php echo BASE_URL; ?>/admin/reports.php" class="btn btn-secondary">Batal</a>
<button type="submit" name="edit_report" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Update
</button>
</div>
</form>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
new bootstrap.Modal(document.getElementById('editReportModal')).show();
});
</script>
<?php endif; ?>
<!-- Category Management Modal -->
<div class="modal fade" id="categoryModal" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-tags me-2"></i>Manajemen Kategori Laporan
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<!-- Quick Add Category -->
<div class="card mb-4">
<div class="card-header bg-light">
<strong><i class="fas fa-plus-circle me-2"></i>Tambah Kategori Baru</strong>
</div>
<div class="card-body">
<form method="POST" class="row g-3" action="<?php echo BASE_URL; ?>/admin/reports.php">
<div class="col-md-5">
<input type="text" class="form-control" name="category_name" placeholder="Nama Kategori" required>
</div>
<div class="col-md-5">
<input type="text" class="form-control" name="category_description" placeholder="Deskripsi (opsional)">
</div>
<div class="col-md-2">
<button type="submit" name="add_category" class="btn btn-primary w-100">
<i class="fas fa-save me-1"></i>Simpan
</button>
</div>
</form>
</div>
</div>
<!-- Category List -->
<div class="card">
<div class="card-header bg-light">
<strong><i class="fas fa-list me-2"></i>Daftar Kategori</strong>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Nama Kategori</th>
<th>Slug</th>
<th>Deskripsi</th>
<th>Jumlah Laporan</th>
<th>Aksi</th>
</thead>
<tbody>
<?php
$all_categories = $conn->query("
SELECT c.*, COUNT(r.id) as report_count
FROM report_categories c
LEFT JOIN reports r ON c.id = r.category_id
GROUP BY c.id
ORDER BY c.name
");
if ($all_categories && $all_categories->num_rows > 0):
while($cat = $all_categories->fetch_assoc()):
?>
<tr class="category-list-item">
<td>
<strong><?php echo htmlspecialchars($cat['name']); ?></strong>
</div>
<td><code><?php echo $cat['slug']; ?></code> </div>
<td><?php echo htmlspecialchars($cat['description']) ?: '-'; ?> </div>
<td>
<span class="badge bg-primary"><?php echo $cat['report_count']; ?> laporan</span>
</div>
<td>
<button class="btn btn-sm btn-info" onclick="editCategory(<?php echo $cat['id']; ?>, '<?php echo addslashes($cat['name']); ?>', '<?php echo addslashes($cat['description']); ?>')">
<i class="fas fa-edit"></i>
</button>
<?php if($cat['report_count'] == 0): ?>
<a href="<?php echo BASE_URL; ?>/admin/reports.php?delete_category=<?php echo $cat['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Yakin ingin menghapus kategori ini?')">
<i class="fas fa-trash"></i>
</a>
<?php else: ?>
<button class="btn btn-sm btn-secondary" disabled title="Kategori memiliki laporan, tidak dapat dihapus">
<i class="fas fa-trash"></i>
</button>
<?php endif; ?>
</div>
</tr>
<?php
endwhile;
else:
?>
<tr>
<td colspan="5" class="text-center py-4">Belum ada kategori</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
</div>
</div>
</div>
</div>
<!-- Edit Category Modal -->
<div class="modal fade" id="editCategoryModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" action="<?php echo BASE_URL; ?>/admin/reports.php">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-edit me-2"></i>Edit Kategori
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<input type="hidden" name="category_id" id="editCategoryId">
<div class="mb-3">
<label class="form-label">Nama Kategori <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="category_name" id="editCategoryName" required>
</div>
<div class="mb-3">
<label class="form-label">Deskripsi</label>
<textarea class="form-control" name="category_description" id="editCategoryDesc" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
<button type="submit" name="edit_category" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Update
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Reports List -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-white">Daftar Laporan</h6>
</div>
<div class="card-body">
<?php if ($reports && $reports->num_rows > 0): ?>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>No</th>
<th>Judul</th>
<th>Kategori</th>
<th>File</th>
<th>TglUpload</th>
<th>Ukuran</th>
<th>Download</th>
<th>Status</th>
<th>Urutan</th>
<th>Aksi</th>
</thead>
<tbody>
<?php
$no = $offset + 1;
while($report = $reports->fetch_assoc()):
?>
<tr>
<td><?php echo $no++; ?> </div>
<td>
<strong><?php echo htmlspecialchars($report['title']); ?></strong>
<?php if(!empty($report['description'])): ?>
<br><small class="text-muted"><?php echo substr(htmlspecialchars($report['description']), 0, 50); ?></small>
<?php endif; ?>
</div>
<td>
<?php if($report['category_name']): ?>
<span class="category-badge">
<i class="fas fa-tag me-1"></i><?php echo htmlspecialchars($report['category_name']); ?>
</span>
<?php else: ?>
<span class="text-muted">-</span>
<?php endif; ?>
</div>
<td>
<a href="<?php echo BASE_URL; ?>/<?php echo $report['filepath']; ?>" target="_blank">
<i class="fas fa-file-alt me-1"></i><?php echo $report['filename']; ?>
</a>
</div>
<td><?php echo date('d-m-Y', strtotime($report['created_at'])); ?> </div>
<td><?php echo $report['file_size']; ?> </div>
<td>
<span class="badge bg-primary"><?php echo number_format($report['download_count']); ?> kali</span>
<br>
<a href="<?php echo BASE_URL; ?>/admin/reports.php?reset_count=<?php echo $report['id']; ?>" class="small" onclick="return confirm('Reset jumlah download?')">
<i class="fas fa-sync-alt"></i> Reset
</a>
</div>
<td>
<span class="badge bg-<?php echo $report['status'] == 'active' ? 'success' : 'secondary'; ?>">
<?php echo $report['status'] == 'active' ? 'Aktif' : 'Tidak Aktif'; ?>
</span>
</div>
<td><?php echo $report['report_order']; ?> </div>
<td>
<div class="btn-group">
<a href="<?php echo BASE_URL; ?>/admin/reports.php?edit=<?php echo $report['id']; ?>" class="btn btn-sm btn-info">
<i class="fas fa-edit"></i>
</a>
<a href="<?php echo BASE_URL; ?>/admin/reports.php?delete_report=<?php echo $report['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Yakin ingin menghapus?')">
<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">
<ul class="pagination justify-content-center">
<?php for($i = 1; $i <= $total_pages; $i++): ?>
<li class="page-item <?php echo $i == $page ? 'active' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/reports.php?page=<?php echo $i; ?>&search=<?php echo urlencode($search); ?>">
<?php echo $i; ?>
</a>
</li>
<?php endfor; ?>
</ul>
</nav>
<?php endif; ?>
<?php else: ?>
<div class="text-center py-5">
<i class="fas fa-download fa-4x text-muted mb-3"></i>
<h5>Belum ada laporan</h5>
<p class="text-muted">Klik tombol "Tambah Laporan" untuk menambahkan laporan pertama.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- Quick Add Category Scripts -->
<script>
const BASE_URL = '<?php echo BASE_URL; ?>';
function openQuickAddCategory() {
const categoryModal = new bootstrap.Modal(document.getElementById('categoryModal'));
categoryModal.show();
// Set callback after category added
const observer = new MutationObserver(function(mutations) {
if (!document.getElementById('categoryModal').classList.contains('show')) {
location.reload();
observer.disconnect();
}
});
observer.observe(document.getElementById('categoryModal'), {attributes: true});
}
function openQuickAddCategoryEdit() {
const categoryModal = new bootstrap.Modal(document.getElementById('categoryModal'));
categoryModal.show();
const observer = new MutationObserver(function(mutations) {
if (!document.getElementById('categoryModal').classList.contains('show')) {
location.reload();
observer.disconnect();
}
});
observer.observe(document.getElementById('categoryModal'), {attributes: true});
}
function editCategory(id, name, desc) {
document.getElementById('editCategoryId').value = id;
document.getElementById('editCategoryName').value = name;
document.getElementById('editCategoryDesc').value = desc;
new bootstrap.Modal(document.getElementById('editCategoryModal')).show();
}
</script>
<?php require_once 'includes/footer.php'; ?>