diff --git a/index.php b/index.php index 0a55d66..2ca2ceb 100644 --- a/index.php +++ b/index.php @@ -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'] ?? '');
+
+ +
Description
+ +
@@ -208,15 +243,15 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');