Login works and Reservation works
This commit is contained in:
242
index.php
242
index.php
@@ -1,9 +1,98 @@
|
||||
<?php
|
||||
session_start();
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
include_once('include/listgenerator.php');
|
||||
include_once('config/config.php');
|
||||
|
||||
$ListID = -1;
|
||||
$loggedin = false;
|
||||
|
||||
if (isset($_GET['list'])) {
|
||||
$ListID = $_GET['list'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['listid'])) {
|
||||
if ($ListID == $_SESSION['listid']) {
|
||||
$loggedin = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['login'])) {
|
||||
$ListPassword = $_POST['ListPassword'];
|
||||
$ListID = $_POST['ListID'];
|
||||
$conn = new mysqli($servername, $username, $password, $db);
|
||||
|
||||
// Check connection
|
||||
if ($conn->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();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
@@ -17,6 +106,7 @@ include_once('config/config.php');
|
||||
<!--<link rel="stylesheet" href="css/custom.css">-->
|
||||
<link rel="stylesheet" href="css/tweaks.css">
|
||||
<script src="js/bootstrap.bundle.min.js"></script>
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="img/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png">
|
||||
@@ -41,50 +131,39 @@ include_once('config/config.php');
|
||||
<strong>Simple Wishlist</strong>
|
||||
</a>
|
||||
<div class="nav navbar-nav navbar-right">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#addItemModal">Add Item</button>
|
||||
<?php
|
||||
if ($loggedin == true) {
|
||||
echo ('
|
||||
<div class="d-grid gap-2 d-flex">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#addItemModal">Add Item</button>
|
||||
<form action="" method="POST">
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary" name= "logout">Logout</a>
|
||||
</form>
|
||||
</div>
|
||||
');
|
||||
} else {
|
||||
echo ('
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#loginModal">Login</button>
|
||||
');
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section class="py-5 text-center container">
|
||||
<div class="row py-lg-5">
|
||||
<div class="col-lg-6 col-md-8 mx-auto">
|
||||
<h1 class="fw-light">Album example</h1>
|
||||
<p class="lead text-muted">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.</p>
|
||||
</div>
|
||||
<?php
|
||||
if (isset($message)) {
|
||||
echo ('
|
||||
<div class="alert alert-' . $message['type'] . ' alert-dismissible fade show" role="alert">
|
||||
' . $message['msg'] . '
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="album py-5 bg-light">
|
||||
<div class="container">
|
||||
|
||||
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
|
||||
|
||||
<?php
|
||||
// Create connection
|
||||
$conn = new mysqli($servername, $username, $password, $db);
|
||||
|
||||
// Check connection
|
||||
if ($conn->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();
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
');
|
||||
}
|
||||
wishlistMainBuilder($ListID);
|
||||
?>
|
||||
</main>
|
||||
|
||||
<footer class="text-muted py-5">
|
||||
@@ -97,18 +176,21 @@ include_once('config/config.php');
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- Modal addItem-->
|
||||
<div class="modal fade" id="addItemModal" tabindex="-1" aria-labelledby="addItemModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addItemModalLabel">Add new Item</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form action="add_item.php" method="POST">
|
||||
<div class="modal-body">
|
||||
<?php
|
||||
if ($loggedin == true) {
|
||||
echo ('
|
||||
<!-- Modal addItem-->
|
||||
<div class="modal fade" id="addItemModal" tabindex="-1" aria-labelledby="addItemModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addItemModalLabel">Add new Item</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form action="add_item.php" method="POST">
|
||||
<div class="modal-body">
|
||||
|
||||
<label for="ItemTitle" class="form-label">Titel</label>
|
||||
<label for="ItemTitle" class="form-label">Titel</label>
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control" id="ItemTitle" name="ItemTitle" rows="3" required>
|
||||
</div>
|
||||
@@ -143,6 +225,40 @@ include_once('config/config.php');
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
');
|
||||
}
|
||||
|
||||
if ($loggedin != true) {
|
||||
echo ('
|
||||
<!-- Modal Login-->
|
||||
<div class="modal fade" id="loginModal" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="loginModalLabel">Login</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form action="" method="POST">
|
||||
<div class="modal-body">
|
||||
|
||||
<label for="ListPassword" class="form-label">Passwort</label>
|
||||
<div class="input-group mb-3">
|
||||
<input type="password" class="form-control" id="ListPassword" name="ListPassword" rows="3" required>
|
||||
<input type="hidden" id="ListID" name="ListID" value="' . $ListID . '">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="submit" name="login" class="btn btn-primary">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
');
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- Modal Reservation-->
|
||||
<div class="modal fade" id="reservationModal" tabindex="-1" aria-labelledby="reservationModalLabel" aria-hidden="true">
|
||||
@@ -153,16 +269,42 @@ include_once('config/config.php');
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
...
|
||||
<form action="" method="POST">
|
||||
<label for="ListPassword" class="form-label">Passwort</label>
|
||||
<div class="input-group mb-3">
|
||||
<input type="password" class="form-control" id="WishPassword" name="WishPassword" rows="3" required>
|
||||
<input type="hidden" name="wishid" id="modal-wishid" value="">
|
||||
<input type="hidden" name="reservedstat" id="modal-reservedstat" value="">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary">Reservieren</button>
|
||||
<button type="submit" id="reservation-submit" name="reservation" class="btn btn-primary">Reservieren</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
$('#reservationModal').on('show.bs.modal', function(event) {
|
||||
var resTr = $(event.relatedTarget)
|
||||
var wishid = resTr.data('wishid')
|
||||
var reserved = resTr.data('reserved')
|
||||
var modal = $(this)
|
||||
modal.find('#modal-wishid').val(wishid)
|
||||
modal.find('#modal-reservedstat').val(reserved)
|
||||
if (reserved == 1) {
|
||||
modal.find('#reservation-submit').text('Reservierung aufheben')
|
||||
modal.find('#reservationModalLabel').text('Reservierung aufheben')
|
||||
} else {
|
||||
modal.find('#reservation-submit').text('Reservieren')
|
||||
modal.find('#reservationModalLabel').text('Wunsch reservieren')
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user