Back-Button verwendet eine History
Bernd Wurst

Bernd Wurst commited on 2024-09-20 07:40:29
Zeige 1 geänderte Dateien mit 26 Einfügungen und 11 Löschungen.

... ...
@@ -3,19 +3,34 @@
3 3
 $pages = array(
4 4
     1 => 'index.php',
5 5
     2 => 'address.php',
6
-    3 => 'gitterbox.php',
7
-    4 => 'obstart.php',
8
-    5 => 'gebrauchte.php',
9
-    6 => 'auftrag.php',
10
-    7 => 'frischsaft.php',
11
-    8 => 'summary.php');
6
+    3 => 'notification.php',
7
+    4 => 'gitterbox.php',
8
+    5 => 'obstart.php',
9
+    6 => 'gebrauchte.php',
10
+    7 => 'auftrag.php',
11
+    8 => 'frischsaft.php',
12
+    9 => 'summary.php');
12 13
 
13
-$previous = array_search(basename($_SERVER['PHP_SELF']), $pages) - 1;
14
-if ($previous > 0) {
15
-    $previous = $pages[$previous];
16
-} else {
17 14
 $previous = null;
15
+$history_pos = 0;
16
+if (!isset($_SESSION['page_history'])) {
17
+    $_SESSION['page_history'] = [];
18
+}
19
+if (isset($_REQUEST['history_pos']) && $_REQUEST['history_pos'] >= 0) {
20
+    if ($_REQUEST['history_pos'] > 0) {
21
+        $previous = $_SESSION['page_history'][$_REQUEST['history_pos']-1];
18 22
     } 
23
+    $history_pos = $_REQUEST['history_pos'];
24
+    // Das tötet einen eventuellen Forward-Button
25
+    // Wenn man zurück gedrückt hat, ist 
26
+    array_pop($_SESSION['page_history']);
27
+} else {
28
+    $previous = end($_SESSION['page_history']);
29
+    $_SESSION['page_history'][] = $_SERVER['PHP_SELF'];
30
+    // Index ist count()-1
31
+    $history_pos = count($_SESSION['page_history'])-1;
32
+} 
33
+
19 34
 
20 35
 ?><!DOCTYPE html>
21 36
 <html lang="de">
... ...
@@ -45,7 +60,7 @@ if ($previous > 0) {
45 60
     <div id="banner" class="mb-3">
46 61
         <div id="banner-back">
47 62
 <?php if ($previous) { ?>
48
-       <a href="<?= $previous ?>"><img src="assets/images/back.svg" width="65" height="65" alt="<"></a>
63
+       <a href="<?= $previous.'?history_pos='.($history_pos-1) ?>"><img src="assets/images/back.svg" width="65" height="65" alt="<"></a>
49 64
 <?php } ?>
50 65
         </div>
51 66
         <div id="banner-logo"><img src="assets/images/banner.svg" width="244" height="65" alt="Mosterei Wurst - Murrhardt-Köchersberg - 07192-936436"></div>
52 67