From 37a38d1c42cb516dd7622856bdcac379ecdbd387 Mon Sep 17 00:00:00 2001 From: metacube2 Date: Sun, 4 Aug 2024 08:47:30 +0200 Subject: [PATCH] Update index.html finish --- index.html | 257 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 216 insertions(+), 41 deletions(-) diff --git a/index.html b/index.html index 862cfb6..a5e2321 100644 --- a/index.html +++ b/index.html @@ -105,6 +105,17 @@ class GuestbookManager { ]; } + public function deleteEntry($index) { + if (isset($this->entries[$index])) { + unset($this->entries[$index]); + $this->entries = array_values($this->entries); // Re-index the array + $this->saveEntries(); + return true; + } + return false; + } + + private function saveEntries() { file_put_contents($this->dbFile, json_encode($this->entries)); } @@ -120,20 +131,27 @@ class GuestbookManager { '; } - - public function displayEntries() { - $output = '
'; - foreach ($this->entries as $entry) { - $output .= " -
-

{$entry['name']}

-

{$entry['message']}

- {$entry['date']} -
"; +public function displayEntries($isAdmin = false) { + $output = '
'; + foreach ($this->entries as $index => $entry) { + $output .= " +
+

{$entry['name']}

+

{$entry['message']}

+ {$entry['date']}"; + if ($isAdmin) { + $output .= "
+ + +
"; } - $output .= '
'; - return $output; + $output .= "
"; } + $output .= '
'; + return $output; +} + + } class ContactManager { @@ -181,8 +199,7 @@ class AdminManager { if (!$this->isAdmin()) { return false; // Nur Admins dürfen Bilder hochladen } - - // Überprüfen Sie, ob eine Datei hochgeladen wurde + if (!isset($file['tmp_name']) || empty($file['tmp_name'])) { echo "Keine Datei hochgeladen."; return false; @@ -333,6 +350,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $adminManager->handleLogin($_POST['username'], $_POST['password']); } elseif (isset($_POST['update-social-media'])) { $adminManager->handleSocialMediaUpdate($_POST['social-platform'], $_POST['social-url']); + + if (isset($_POST['delete_entry']) && $adminManager->isAdmin()) { + $index = $_POST['delete_entry']; + if ($guestbookManager->deleteEntry($index)) { + // Optionally set a success message + $_SESSION['message'] = "Eintrag erfolgreich gelöscht."; + } else { + // Optionally set an error message + $_SESSION['error'] = "Fehler beim Löschen des Eintrags."; + } + // Redirect to prevent form resubmission + header("Location: " . $_SERVER['PHP_SELF'] . "#guestbook"); + exit(); + } + } elseif (isset($_FILES["fileToUpload"]) && $adminManager->isAdmin()) { $adminManager->handleImageUpload($_FILES["fileToUpload"]); }} @@ -346,7 +378,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { - Aurora Wetter Lifecam - Einzigartige Live-Webcam und Wetter + <h2>Aurora Wetter Lifecam - Einzigartige Live-Webcam und Wetter></h2> +