This commit is contained in:
Flatlogic Bot 2026-01-02 12:01:56 +00:00
parent c6e4994eb6
commit 6785f05d29

View File

@ -11,6 +11,22 @@ $processes = [];
$search_query = $_GET['search'] ?? '';
$total_processes = 0;
// Sorting settings
$allowed_sort_columns = ['name', 'created_at'];
$sort_by = $_GET['sort_by'] ?? 'created_at';
$sort_order = $_GET['sort_order'] ?? 'DESC';
// Validate sort_by column
if (!in_array($sort_by, $allowed_sort_columns)) {
$sort_by = 'created_at'; // Default to created_at if invalid
}
// Validate sort_order
$sort_order = strtoupper($sort_order);
if (!in_array($sort_order, ['ASC', 'DESC'])) {
$sort_order = 'DESC'; // Default to DESC if invalid
}
try {
$pdo = db();
@ -31,7 +47,7 @@ try {
if (!empty($search_query)) {
$sql .= " WHERE name LIKE :search_query OR description LIKE :search_query";
}
$sql .= " ORDER BY created_at DESC LIMIT :limit OFFSET :offset";
$sql .= " ORDER BY ".$sort_by." ".$sort_order." LIMIT :limit OFFSET :offset";
$stmt = $pdo->prepare($sql);
if (!empty($search_query)) {
@ -178,6 +194,25 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
</div>
<?php else: ?>
<div class="list-group list-group-flush">
<div class="list-group-item px-0 d-flex justify-content-between align-items-center bg-light fw-bold">
<div class="col-4">
<a href="?<?php echo http_build_query(array_merge($_GET, ['sort_by' => 'name', 'sort_order' => ($sort_by == 'name' && $sort_order == 'ASC') ? 'DESC' : 'ASC'])); ?>" class="text-decoration-none text-dark">
Process Name
<?php if ($sort_by == 'name'): ?>
<i data-feather="<?php echo ($sort_order == 'ASC') ? 'arrow-up' : 'arrow-down'; ?>" style="width: 14px; height: 14px;"></i>
<?php endif; ?>
</a>
</div>
<div class="col-5">Description</div>
<div class="col-3 text-end">
<a href="?<?php echo http_build_query(array_merge($_GET, ['sort_by' => 'created_at', 'sort_order' => ($sort_by == 'created_at' && $sort_order == 'ASC') ? 'DESC' : 'ASC'])); ?>" class="text-decoration-none text-dark">
Created At
<?php if ($sort_by == 'created_at'): ?>
<i data-feather="<?php echo ($sort_order == 'ASC') ? 'arrow-up' : 'arrow-down'; ?>" style="width: 14px; height: 14px;"></i>
<?php endif; ?>
</a>
</div>
</div>
<?php foreach ($processes as $process): ?>
<div class="list-group-item px-0">
<div class="d-flex w-100 justify-content-between align-items-start">
@ -208,15 +243,15 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center mt-4">
<li class="page-item <?php echo ($current_page <= 1) ? 'disabled' : ''; ?>">
<a class="page-link" href="?page=<?php echo $current_page - 1; ?><?php echo (!empty($search_query) ? '&search=' . urlencode($search_query) : ''); ?>" tabindex="-1" aria-disabled="true">Previous</a>
<a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $current_page - 1])); ?>" tabindex="-1" aria-disabled="true">Previous</a>
</li>
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<li class="page-item <?php echo ($current_page == $i) ? 'active' : ''; ?>">
<a class="page-link" href="?page=<?php echo $i; ?><?php echo (!empty($search_query) ? '&search=' . urlencode($search_query) : ''); ?>"><?php echo $i; ?></a>
<a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $i])); ?>"><?php echo $i; ?></a>
</li>
<?php endfor; ?>
<li class="page-item <?php echo ($current_page >= $total_pages) ? 'disabled' : ''; ?>">
<a class="page-link" href="?page=<?php echo $current_page + 1; ?><?php echo (!empty($search_query) ? '&search=' . urlencode($search_query) : ''); ?>">Next</a>
<a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $current_page + 1])); ?>">Next</a>
</li>
</ul>
</nav>