From ce3465fdba97194174a9d842b40ce1d051a5ffe1 Mon Sep 17 00:00:00 2001 From: Marcel Peterkau Date: Tue, 20 Sep 2022 22:30:10 +0200 Subject: [PATCH] Login works and Reservation works --- add_item.php | 4 +- include/listgenerator.php | 68 ++++++++++- index.php | 242 ++++++++++++++++++++++++++++++-------- js/jquery.min.js | 2 + 4 files changed, 263 insertions(+), 53 deletions(-) create mode 100644 js/jquery.min.js diff --git a/add_item.php b/add_item.php index bb1d0c3..eb9952f 100644 --- a/add_item.php +++ b/add_item.php @@ -13,9 +13,9 @@ $ItemImage = $_POST['ItemImage']; #--- check if the provided Image-Link is a real image: -$headers = get_headers($ItemImage, 1); +$headers = array_change_key_case(get_headers($ItemImage, 1), CASE_LOWER); // make all keys LowerCase -if (strpos($headers['Content-Type'], 'image/') !== false) { +if (strpos($headers['content-type'], 'image/') !== false) { $strippedimagepath = strtok($ItemImage, '?'); $imageLocalLink = 'data/images/' . uniqid() . '.' . pathinfo($strippedimagepath, PATHINFO_EXTENSION); echo "ImageLink: " . $imageLocalLink; diff --git a/include/listgenerator.php b/include/listgenerator.php index 08744d1..3107fc3 100644 --- a/include/listgenerator.php +++ b/include/listgenerator.php @@ -1,5 +1,7 @@
zum Anbieter - +
' . $formatter->formatCurrency($ItemPrice / 100, 'EUR') . ' @@ -27,3 +29,67 @@ function generateListItem($ListItemID, $ItemImage, $ItemTitle, $ItemLink, $ItemP '); } + +function wishlistMainBuilder($ListID) +{ + + global $servername, $username, $password, $db; + + // Create connection + $conn = new mysqli($servername, $username, $password, $db); + + // Check connection + if ($conn->connect_error) { + die('Connection failed: ' . $conn->connect_error); + } + + $sql = 'SELECT title, description FROM lists WHERE ID = ' . $ListID; + $result = $conn->query($sql); + + echo (' +
+
+
+ '); + + if ($result !== false && $result->num_rows > 0) { + while ($row = $result->fetch_assoc()) { + echo (' +

' . $row['title'] . '

+

' . $row['description'] . '

+ '); + } + } else { + echo (' +

Das tut mir leid...

+

Diese Liste gibt es nicht mehr

+ '); + } + + echo (' +
+ '); + + // End of Header Generator + + echo (' +
+
+
+ '); + + $sql = 'SELECT ID, title, description, link, image, reserved, price FROM whishes WHERE whislist = ' . $ListID; + $result = $conn->query($sql); + + if ($result !== false && $result->num_rows > 0) { + while ($row = $result->fetch_assoc()) { + generateListItem($row['ID'], $row['image'], $row['title'], $row['link'], $row['price'], $row['description'], $row['reserved']); + } + } + + echo (' +
+ '); + + $conn->close(); +} diff --git a/index.php b/index.php index 5190b39..58a31cd 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,98 @@ connect_error) { + die('Connection failed: ' . $conn->connect_error); + } + + $sql = 'SELECT edit_pw FROM lists WHERE ID = ' . $ListID; + $result = $conn->query($sql); + + if ($result !== false && $result->num_rows > 0) { + if ($row = $result->fetch_assoc()) { + if (password_verify($ListPassword, $row['edit_pw'])) { + $_SESSION['listid'] = $ListID; + $loggedin = true; + $message = array('msg' => 'Login erfolgreich', 'type' => 'success'); + } else { + $message = array('msg' => 'Falsches Passwort', 'type' => 'warning'); + } + } + } + $conn->close(); +} + +if (isset($_POST['logout'])) { + session_destroy(); + $loggedin = false; + $message = array('msg' => 'Logout erfolgreich', 'type' => 'success'); +} + +if (isset($_POST['reservation'])) { + + $conn = new mysqli($servername, $username, $password, $db); + + // Check connection + if ($conn->connect_error) { + die('Connection failed: ' . $conn->connect_error); + } + + if ($_POST['reservedstat'] == 1) { + + $sql = 'SELECT reserved_pw FROM whishes WHERE ID = ' . $_POST['wishid']; + $result = $conn->query($sql); + + if ($result !== false && $result->num_rows > 0) { + if ($row = $result->fetch_assoc()) { + if (password_verify($_POST['WishPassword'], $row['reserved_pw'])) { + $sql = 'UPDATE whishes SET reserved=0, reserved_pw="" WHERE ID = ' . $_POST['wishid']; + if ($conn->query($sql) === TRUE) + $message = array('msg' => 'Reservierung aufgehoben', 'type' => 'success'); + else + $message = array('msg' => 'Uups, irgendwas ist schief gegangen!', 'type' => 'danger'); + } else { + $message = array('msg' => 'Falsches Reservierungs-Passwort', 'type' => 'warning'); + } + } + } + } + + if ($_POST['reservedstat'] == 0) { + $reservedHash = password_hash($_POST['WishPassword'], PASSWORD_BCRYPT); + $sql = 'UPDATE whishes SET reserved=1, reserved_pw="' . $reservedHash . '" WHERE ID = ' . $_POST['wishid']; + if ($conn->query($sql) === TRUE) + $message = array('msg' => 'Reservierung eingetragen', 'type' => 'success'); + else + $message = array('msg' => 'Uups, irgendwas ist schief gegangen!', 'type' => 'danger'); + } + + $conn->close(); +} + ?> @@ -17,6 +106,7 @@ include_once('config/config.php'); + @@ -41,50 +131,39 @@ include_once('config/config.php'); Simple Wishlist + '); + } else { + echo (' + + '); + } + ?>
-
-
-
-

Album example

-

Something short and leading about the collection below—its contents, the creator, etc. Make it short and sweet, but not too short so folks don’t simply skip over it entirely.

-
+ + ' . $message['msg'] . ' +
-
- -
-
- -
- - connect_error) { - die('Connection failed: ' . $conn->connect_error); - } - $sql = 'SELECT ID, title, description, link, image, reserved, price FROM whishes'; - $result = $conn->query($sql); - - if ($result !== false && $result->num_rows > 0) { - while ($row = $result->fetch_assoc()) { - generateListItem($row['ID'], $row['image'], $row['title'], $row['link'], $row['price'], $row['description'], $row['reserved']); - } - $conn->close(); - } - ?> - -
-
-
- + '); + } + wishlistMainBuilder($ListID); + ?>
- -