From 0e44d92baab624585443210d84473baac4aeeae4 Mon Sep 17 00:00:00 2001 From: NOrtmann1 Date: Sat, 13 Jun 2026 12:19:37 +0200 Subject: [PATCH 1/3] paginator.js --- content/search-results.php | 52 +++++++++++++++++++++++++++++++------- index.php | 4 +++ js/paginator.js | 27 ++++++++++++++++++++ 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 js/paginator.js diff --git a/content/search-results.php b/content/search-results.php index 3cfa52e..4bd5cf1 100644 --- a/content/search-results.php +++ b/content/search-results.php @@ -2,19 +2,38 @@ if (session_status() === PHP_SESSION_NONE) { session_start(); } - -$results = $_SESSION["search_results"] ?? []; + +$all_results = $_SESSION["search_results"] ?? []; $query = $_SESSION["search_query"] ?? ""; +$totalResultsCount = count($all_results); $limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10; if (!in_array($limit, [10, 20, 50, 100])) { $limit = 10; } -$results = array_slice($results, 0, $limit); +// Gesamtseitenzahl +$totalPages = max(1, ceil($totalResultsCount / $limit)); + +// Aktuelle Seite auslesen und validieren +$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1; +if ($currentPage < 1) { + $currentPage = 1; +} elseif ($currentPage > $totalPages) { + $currentPage = $totalPages; +} + +// Startpunkt im Array berechnen (Offset) +$offset = ($currentPage - 1) * $limit; + +// Nur die Ergebnisse für die aktuelle Seite ausschneiden +$results = array_slice($all_results, $offset, $limit); $resultCount = count($results); ?> +
- -
+ + + + + +

Suche anpassen

@@ -66,7 +89,7 @@ $resultCount = count($results);

Suchergebnisse

-

Treffer für Ihre Suchanfrage ""

+

Treffer für Ihre Suchanfrage ""

@@ -115,9 +138,20 @@ $resultCount = count($results);
- - - + + + + + +
diff --git a/index.php b/index.php index 175830a..1006322 100644 --- a/index.php +++ b/index.php @@ -42,6 +42,7 @@ if ($pfad === "deleteAccount") { + @@ -50,6 +51,9 @@ if ($pfad === "deleteAccount") { + + + EduForge diff --git a/js/paginator.js b/js/paginator.js new file mode 100644 index 0000000..378174b --- /dev/null +++ b/js/paginator.js @@ -0,0 +1,27 @@ +function initPaginator() { + const form = document.getElementById('search-form-id'); + const pageInput = document.getElementById('s-res-page-input'); + const pageButtons = document.querySelectorAll('.s-res-page-navigation .s-res-page-btn'); + + pageButtons.forEach(button => { + button.addEventListener('click', function() { + if (this.disabled) return; + + const targetPage = this.getAttribute('data-page'); + + if (targetPage && form && pageInput) { + pageInput.value = targetPage; + form.submit(); + } + }); + }); +} + +// ist das DOM bereits vollständig aufgebaut? +if (document.readyState === 'loading') { + // Falls noch geladen wird, auf das Event warten + document.addEventListener('DOMContentLoaded', initPaginator); +} else { + // Falls das HTML bereits komplett da ist, sofort ausführen + initPaginator(); +} \ No newline at end of file From c16bf574ce377defca1f9a9f3114b24b2fa3cd1f Mon Sep 17 00:00:00 2001 From: NOrtmann1 Date: Sat, 13 Jun 2026 12:21:38 +0200 Subject: [PATCH 2/3] Update search-results.php --- content/search-results.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/content/search-results.php b/content/search-results.php index 4bd5cf1..c7ff9e4 100644 --- a/content/search-results.php +++ b/content/search-results.php @@ -46,8 +46,6 @@ $resultCount = count($results); - - From 95251d23ad478c3e60cbab8fd1da14d0577ab52c Mon Sep 17 00:00:00 2001 From: NOrtmann1 Date: Sat, 13 Jun 2026 12:26:49 +0200 Subject: [PATCH 3/3] Update search-results-controller.php --- php/controller/search-results-controller.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/php/controller/search-results-controller.php b/php/controller/search-results-controller.php index 422f923..4d2a654 100644 --- a/php/controller/search-results-controller.php +++ b/php/controller/search-results-controller.php @@ -62,7 +62,11 @@ if ($_SERVER["REQUEST_METHOD"] === "GET" && isset($_GET["q"])) { $_SESSION["message"] = "internal_error"; } } - header("Location: ../../index.php?pfad=search-results"); + + $sort = $_GET['sort'] ?? 'alphabet'; + $limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10; + $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; + header("Location: ../../index.php?pfad=search-results&q=" . urlencode($search) . "&sort=" . urlencode($sort) . "&limit=" . $limit . "&page=" . $page); exit(); }