311 lines
12 KiB
PHP
311 lines
12 KiB
PHP
<?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>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>Simple Wishlist</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="stylesheet" href="css/bootstrap.min.css">
|
|
<!--<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">
|
|
<link rel="manifest" href="img/site.webmanifest">
|
|
<link rel="mask-icon" href="img/safari-pinned-tab.svg" color="#5bbad5">
|
|
<link rel="shortcut icon" href="img/favicon.ico">
|
|
<meta name="msapplication-TileColor" content="#da532c">
|
|
<meta name="msapplication-config" content="img/browserconfig.xml">
|
|
<meta name="theme-color" content="#ffffff">
|
|
<link rel="manifest" href="img/site.webmanifest">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<header>
|
|
<div class="navbar navbar-dark bg-dark shadow-sm">
|
|
<div class="container">
|
|
<a href="#" class="navbar-brand d-flex align-items-center">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="me-2 bi bi-gift" viewBox="0 0 16 16">
|
|
<path d="M3 2.5a2.5 2.5 0 0 1 5 0 2.5 2.5 0 0 1 5 0v.006c0 .07 0 .27-.038.494H15a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1v7.5a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 1 14.5V7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h2.038A2.968 2.968 0 0 1 3 2.506V2.5zm1.068.5H7v-.5a1.5 1.5 0 1 0-3 0c0 .085.002.274.045.43a.522.522 0 0 0 .023.07zM9 3h2.932a.56.56 0 0 0 .023-.07c.043-.156.045-.345.045-.43a1.5 1.5 0 0 0-3 0V3zM1 4v2h6V4H1zm8 0v2h6V4H9zm5 3H9v8h4.5a.5.5 0 0 0 .5-.5V7zm-7 8V7H2v7.5a.5.5 0 0 0 .5.5H7z" />
|
|
</svg>
|
|
<strong>Simple Wishlist</strong>
|
|
</a>
|
|
<div class="nav navbar-nav navbar-right">
|
|
<?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>
|
|
<?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>
|
|
');
|
|
}
|
|
wishlistMainBuilder($ListID);
|
|
?>
|
|
</main>
|
|
|
|
<footer class="text-muted py-5">
|
|
<div class="container">
|
|
<p class="float-end mb-1">
|
|
<a href="#">Back to top</a>
|
|
</p>
|
|
<p class="mb-1">Simple Wishlist © by Marcel Peterkau</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<?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>
|
|
<div class="input-group mb-3">
|
|
<input type="text" class="form-control" id="ItemTitle" name="ItemTitle" rows="3" required>
|
|
</div>
|
|
|
|
<label for="ItemDescription" class="form-label">Beschreibung</label>
|
|
<div class="input-group mb-3">
|
|
<textarea class="form-control" id="ItemDescription" name="ItemDescription" rows="3"></textarea>
|
|
</div>
|
|
|
|
<label for="ItemPrice" class="form-label">Preis</label>
|
|
<div class="input-group mb-3">
|
|
<input type="text" class="form-control" id="ItemPrice" name="ItemPrice" pattern="^\d*(\.\d{2}$)?" value="" data-type="currency" placeholder="0.00€" />
|
|
<span class="input-group-text">€</span>
|
|
</div>
|
|
|
|
<label for="ItemLink" class="form-label">Link zum Angebot</label>
|
|
<div class="input-group mb-3">
|
|
<input type="url" class="form-control" id="ItemLink" name="ItemLink" pattern="https?://.+" title="Include http://" rows="3">
|
|
</div>
|
|
|
|
<label for="ItemImage" class="form-label">Link zum Bild</label>
|
|
<div class="input-group mb-3">
|
|
<input type="url" class="form-control" id="ItemImage" name="ItemImage" pattern="https?://.+" title="Include http://" rows="3">
|
|
</div>
|
|
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
<button type="submit" class="btn btn-primary">Add new Item</button>
|
|
</div>
|
|
</form>
|
|
</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">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="reservationModalLabel">Wunsch reservieren</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p id="ReservationInfoText">Bitte vergeben sie ein Passwort um diesen Wunsch zu reservieren. Nur mit diesem Passwort (oder durch den Listeneigentümer) kann die Reservierung wieder aufgehoben werden.</p>
|
|
<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="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')
|
|
modal.find('#ReservationInfoText').remove()
|
|
} else {
|
|
modal.find('#reservation-submit').text('Reservieren')
|
|
modal.find('#reservationModalLabel').text('Wunsch reservieren')
|
|
}
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|