diff --git a/assets/pasted-20251211-195118-48f4531d.png b/assets/pasted-20251211-195118-48f4531d.png new file mode 100644 index 0000000..8ae6d99 Binary files /dev/null and b/assets/pasted-20251211-195118-48f4531d.png differ diff --git a/dashboard.php b/dashboard.php index aadeca6..a331d8f 100644 --- a/dashboard.php +++ b/dashboard.php @@ -1,4 +1,6 @@ prepare($query); + $stmt->execute($query_params); + $items_to_export = $stmt->fetchAll(PDO::FETCH_ASSOC); + + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="my_listings.csv"'); + + $output = fopen('php://output', 'w'); + if (!empty($items_to_export)) { + fputcsv($output, array_keys($items_to_export[0])); // CSV Header + foreach ($items_to_export as $row) { + fputcsv($output, $row); + } + } + fclose($output); + exit(); +} + // Pagination constants $items_per_page = isset($_GET['items_per_page']) ? (int)$_GET['items_per_page'] : 6; // Validate $items_per_page to be a positive integer, e.g., 6, 12, 24, 48 @@ -152,8 +217,45 @@ $items = []; // Initialize an empty array to hold items Clear Filters + + ' . htmlspecialchars($_GET['search']) . ''; + } + if (!empty($_GET['status'])) { + $statusText = [ + 'available' => 'Available', + 'rented' => 'Rented', + 'unavailable' => 'Unavailable' + ][$_GET['status']] ?? ucfirst($_GET['status']); + $activeFilters[] = 'Status: ' . htmlspecialchars($statusText) . ''; + } + if (!empty($_GET['sort'])) { + $sortText = [ + 'name_asc' => 'Name (A-Z)', + 'name_desc' => 'Name (Z-A)', + 'price_asc' => 'Price (Low to High)', + 'price_desc' => 'Price (High to Low)', + 'date_desc' => 'Date Added (Newest)', + 'date_asc' => 'Date Added (Oldest)' + ][$_GET['sort']] ?? ''; + if (!empty($sortText)) { + $activeFilters[] = 'Sort By: ' . htmlspecialchars($sortText) . ''; + } + } + if (!empty($_GET['items_per_page']) && (int)$_GET['items_per_page'] !== 6) { // Assume 6 is default + $activeFilters[] = 'Items per page: ' . htmlspecialchars($_GET['items_per_page']) . ''; + } + + if (!empty($activeFilters)): + ?> + +

You have not listed any items yet. Add a new item.