|
Server IP : 217.21.85.138 / Your IP : 216.73.216.103 Web Server : LiteSpeed System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64 User : u915722082 ( 915722082) PHP Version : 7.4.33 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF Directory (0755) : /home/u915722082/public_html/apitodshut/../projects/admin/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
session_start();
if (!isset($_SESSION['admin_id'])) {
header("Location: login.php");
exit;
}
// ADMIN/MANAGER ONLY ACCESS
if ($_SESSION['role'] === 'Employee') {
header("Location: employee.php");
exit;
}
require_once '../config/config.php';
require_once '../config/db.php';
$current_user_role = $_SESSION['role'] ?? 'Manager';
$current_user_id = $_SESSION['admin_id'];
$current_user_name = $_SESSION['user_name'] ?? 'Admin';
// ==================== PAGINATION SETUP ====================
$records_per_page = 10;
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? intval($_GET['page']) : 1;
$offset = ($page - 1) * $records_per_page;
// Get total number of categories
$total_query = "SELECT COUNT(DISTINCT category_name) as total FROM tbl_categories";
$total_result = mysqli_query($con, $total_query);
$total_row = mysqli_fetch_assoc($total_result);
$total_records = $total_row['total'];
$total_pages = ceil($total_records / $records_per_page);
// Get categories with pagination
$categories_query = "SELECT category_name, category_description,
GROUP_CONCAT(subcategory_name ORDER BY subcategory_name ASC SEPARATOR ', ') as subcategories,
MIN(created_at) as created_at,
(SELECT u.fname FROM tbl_user u WHERE u.uid = MIN(tbl_categories.created_by)) as created_by_name
FROM tbl_categories
GROUP BY category_name, category_description
ORDER BY MIN(created_at) DESC
LIMIT $records_per_page OFFSET $offset";
$categories_result = mysqli_query($con, $categories_query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="../" />
<title>Categories - TDS Admin Hub</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700" />
<link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css" />
<link href="assets/css/style.bundle.css" rel="stylesheet" type="text/css" />
</head>
<body id="kt_app_body" data-kt-app-layout="dark-sidebar" data-kt-app-header-fixed="true"
data-kt-app-sidebar-enabled="true" data-kt-app-sidebar-fixed="true"
data-kt-app-sidebar-hoverable="true" data-kt-app-sidebar-push-header="true"
data-kt-app-sidebar-push-toolbar="true" data-kt-app-sidebar-push-footer="true"
data-kt-app-toolbar-enabled="true" class="app-default">
<script>
var defaultThemeMode = "light";
var themeMode;
if (document.documentElement) {
if (document.documentElement.hasAttribute("data-bs-theme-mode")) {
themeMode = document.documentElement.getAttribute("data-bs-theme-mode");
} else {
if (localStorage.getItem("data-bs-theme") !== null) {
themeMode = localStorage.getItem("data-bs-theme");
} else {
themeMode = defaultThemeMode;
}
}
if (themeMode === "system") {
themeMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
document.documentElement.setAttribute("data-bs-theme", themeMode);
}
</script>
<div class="d-flex flex-column flex-root app-root" id="kt_app_root">
<div class="app-page flex-column flex-column-fluid" id="kt_app_page">
<?php include 'includes/header.php'; ?>
<div class="app-wrapper flex-column flex-row-fluid" id="kt_app_wrapper">
<?php include 'includes/sidebar.php'; ?>
<div class="app-main flex-column flex-row-fluid" id="kt_app_main">
<div class="d-flex flex-column flex-column-fluid">
<div id="kt_app_toolbar" class="app-toolbar py-3 py-lg-6">
<div id="kt_app_toolbar_container" class="app-container container-xxl d-flex flex-stack">
<div class="page-title d-flex flex-column justify-content-center flex-wrap me-3">
<h1 class="page-heading d-flex text-gray-900 fw-bold fs-3 flex-column my-0">
📂 Categories Management
</h1>
<ul class="breadcrumb breadcrumb-separatorless fw-semibold fs-7 my-0 pt-1">
<li class="breadcrumb-item text-muted">
<a href="admin/dashboard.php" class="text-muted text-hover-primary">Home</a>
</li>
<li class="breadcrumb-item">
<span class="bullet bg-gray-500 w-5px h-2px"></span>
</li>
<li class="breadcrumb-item text-muted">Categories</li>
</ul>
</div>
</div>
</div>
<div id="kt_app_content" class="app-content flex-column-fluid">
<div id="kt_app_content_container" class="app-container container-xxl">
<div class="card">
<div class="card-header border-0 pt-6">
<div class="card-title">
<div class="d-flex align-items-center position-relative my-1">
<i class="ki-duotone ki-magnifier fs-3 position-absolute ms-5">
<span class="path1"></span>
<span class="path2"></span>
</i>
<input type="text" id="searchCategory"
class="form-control form-control-solid w-250px ps-13"
placeholder="Search categories..." />
</div>
</div>
<div class="card-toolbar">
<a href="admin/add-category.php" class="btn btn-primary">
<i class="ki-duotone ki-plus fs-2"></i>
Add Category
</a>
</div>
</div>
<div class="card-body py-4">
<div class="table-responsive">
<table class="table align-middle table-row-dashed fs-6 gy-5" id="categoriesTable">
<thead>
<tr class="text-start text-muted fw-bold fs-7 text-uppercase gs-0">
<th class="min-w-200px">Category Name</th>
<th class="min-w-300px">Description</th>
<th class="min-w-400px">Subcategories</th>
<th class="min-w-125px">Created By</th>
<th class="text-end min-w-100px">Actions</th>
</tr>
</thead>
<tbody class="text-gray-600 fw-semibold">
<?php if(mysqli_num_rows($categories_result) > 0): ?>
<?php while ($category = mysqli_fetch_assoc($categories_result)): ?>
<tr>
<td>
<span class="text-gray-800 fw-bold fs-5">
<?php echo htmlspecialchars($category['category_name']); ?>
</span>
</td>
<td>
<span class="text-muted fs-7">
<?php echo htmlspecialchars($category['category_description']); ?>
</span>
</td>
<td>
<div class="d-flex flex-wrap gap-2">
<?php
$subcategories = explode(', ', $category['subcategories']);
$display_count = 5; // Show only first 5
$remaining = count($subcategories) - $display_count;
for ($i = 0; $i < min($display_count, count($subcategories)); $i++):
?>
<span class="badge badge-light-primary fs-7">
<?php echo htmlspecialchars($subcategories[$i]); ?>
</span>
<?php endfor; ?>
<?php if ($remaining > 0): ?>
<span class="badge badge-light-info fs-7">
+<?php echo $remaining; ?> more
</span>
<?php endif; ?>
</div>
</td>
<td><?php echo htmlspecialchars($category['created_by_name']); ?></td>
<td class="text-end">
<a href="admin/add-category.php?category=<?php echo urlencode($category['category_name']); ?>"
class="btn btn-icon btn-light btn-active-light-primary btn-sm me-1"
title="Edit">
<i class="ki-duotone ki-pencil fs-3">
<span class="path1"></span>
<span class="path2"></span>
</i>
</a>
<button class="btn btn-icon btn-light btn-active-light-danger btn-sm"
onclick="deleteCategory('<?php echo htmlspecialchars($category['category_name'], ENT_QUOTES); ?>')"
title="Delete">
<i class="ki-duotone ki-trash fs-3">
<span class="path1"></span>
<span class="path2"></span>
<span class="path3"></span>
<span class="path4"></span>
<span class="path5"></span>
</i>
</button>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="5" class="text-center py-10">
<div class="d-flex flex-column align-items-center">
<i class="ki-duotone ki-folder fs-3x text-gray-400 mb-3">
<span class="path1"></span>
<span class="path2"></span>
</i>
<span class="text-gray-600 fs-5">No categories found</span>
<span class="text-muted fs-7">Click "Add Category" to create your first category</span>
</div>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<?php if ($total_pages > 1): ?>
<!--begin::Pagination-->
<div class="d-flex flex-stack flex-wrap pt-10">
<div class="fs-6 fw-semibold text-gray-700">
Showing <?php echo $offset + 1; ?> to <?php echo min($offset + $records_per_page, $total_records); ?> of <?php echo $total_records; ?> entries
</div>
<ul class="pagination">
<!-- Previous Button -->
<li class="page-item <?php echo ($page <= 1) ? 'disabled' : ''; ?>">
<a href="<?php echo ($page > 1) ? 'admin/categories.php?page=' . ($page - 1) : '#'; ?>"
class="page-link">
<i class="previous"></i>
</a>
</li>
<?php
// Calculate page range to display
$range = 2; // Show 2 pages before and after current page
$start_page = max(1, $page - $range);
$end_page = min($total_pages, $page + $range);
// First page
if ($start_page > 1) {
echo '<li class="page-item"><a href="admin/categories.php?page=1" class="page-link">1</a></li>';
if ($start_page > 2) {
echo '<li class="page-item disabled"><span class="page-link">...</span></li>';
}
}
// Page numbers
for ($i = $start_page; $i <= $end_page; $i++):
?>
<li class="page-item <?php echo ($page == $i) ? 'active' : ''; ?>">
<a href="admin/categories.php?page=<?php echo $i; ?>" class="page-link">
<?php echo $i; ?>
</a>
</li>
<?php
endfor;
// Last page
if ($end_page < $total_pages) {
if ($end_page < $total_pages - 1) {
echo '<li class="page-item disabled"><span class="page-link">...</span></li>';
}
echo '<li class="page-item"><a href="admin/categories.php?page=' . $total_pages . '" class="page-link">' . $total_pages . '</a></li>';
}
?>
<!-- Next Button -->
<li class="page-item <?php echo ($page >= $total_pages) ? 'disabled' : ''; ?>">
<a href="<?php echo ($page < $total_pages) ? 'admin/categories.php?page=' . ($page + 1) : '#'; ?>"
class="page-link">
<i class="next"></i>
</a>
</li>
</ul>
</div>
<!--end::Pagination-->
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="assets/plugins/global/plugins.bundle.js"></script>
<script src="assets/js/scripts.bundle.js"></script>
<script>
// Search functionality
document.getElementById('searchCategory').addEventListener('keyup', function() {
const searchValue = this.value.toLowerCase();
const tableRows = document.querySelectorAll('#categoriesTable tbody tr');
tableRows.forEach(row => {
const text = row.textContent.toLowerCase();
row.style.display = text.includes(searchValue) ? '' : 'none';
});
});
// Delete category
function deleteCategory(categoryName) {
Swal.fire({
title: 'Are you sure?',
html: `Do you want to delete the category<br><strong>"${categoryName}"</strong>?<br><small class="text-muted">This will delete all its subcategories as well.</small>`,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#3085d6',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'Cancel'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: 'admin/category_actions.php',
type: 'POST',
data: {
action: 'delete',
category_name: categoryName
},
dataType: 'json',
success: function(response) {
if (response.success) {
Swal.fire({
icon: 'success',
title: 'Deleted!',
text: response.message,
timer: 2000,
showConfirmButton: false
}).then(() => {
location.reload();
});
} else {
Swal.fire({
icon: 'error',
title: 'Error!',
text: response.message
});
}
},
error: function() {
Swal.fire({
icon: 'error',
title: 'Error!',
text: 'Something went wrong. Please try again.'
});
}
});
}
});
}
</script>
<?php include 'includes/chat_widget.php'; ?>
</body>
</html>