Sort selectable and Date added. Delete also works
This commit is contained in:
127
index.php
127
index.php
@@ -8,11 +8,18 @@ include_once('config/config.php');
|
||||
|
||||
$ListID = -1;
|
||||
$loggedin = false;
|
||||
$sortby = '';
|
||||
|
||||
if (isset($_GET['list'])) {
|
||||
$ListID = $_GET['list'];
|
||||
}
|
||||
|
||||
if (isset($_POST['sortby'])) {
|
||||
$sortby = $_POST['sortby'];
|
||||
}
|
||||
|
||||
print_r($sortby);
|
||||
|
||||
if (isset($_SESSION['listid'])) {
|
||||
if ($ListID == $_SESSION['listid']) {
|
||||
$loggedin = true;
|
||||
@@ -93,6 +100,40 @@ if (isset($_POST['reservation'])) {
|
||||
$conn->close();
|
||||
}
|
||||
|
||||
if (isset($_POST['delete']) && $loggedin == true) {
|
||||
|
||||
if (isset($_POST['WhishID'])) {
|
||||
$WhishID = $_POST['WhishID'];
|
||||
$WhishTitle = '';
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $db);
|
||||
|
||||
// Check connection
|
||||
if ($conn->connect_error) {
|
||||
die('Connection failed: ' . $conn->connect_error);
|
||||
}
|
||||
|
||||
$sql = 'SELECT image, title FROM whishes WHERE ID = ' . $WhishID;
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result !== false && $result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
unlink($row['image']);
|
||||
$WhishTitle = $row['title'];
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM whishes WHERE ID = ' . $WhishID;
|
||||
if ($conn->query($sql) === TRUE)
|
||||
$message = array('msg' => 'Wunsch <b>"' . $WhishTitle . '"</b> gelöscht', 'type' => 'success');
|
||||
else
|
||||
$message = array('msg' => 'Uups, irgendwas ist schief gegangen!', 'type' => 'danger');
|
||||
} else {
|
||||
$message = array('msg' => 'Uups, irgendwas ist schief gegangen!', 'type' => 'danger');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
@@ -131,22 +172,35 @@ if (isset($_POST['reservation'])) {
|
||||
<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>
|
||||
<div class="d-grid gap-2 d-flex">
|
||||
<?php
|
||||
if ($loggedin == true) {
|
||||
echo ('
|
||||
<form class="form-inline" action="" method="POST">
|
||||
<button type="button" class="btn btn-outline-secondary my-2 my-sm-0" data-bs-toggle="modal" data-bs-target="#addItemModal">Add Item</button>
|
||||
</form>
|
||||
<form class="form-inline" action="" method="POST">
|
||||
<button type="submit" class="btn btn-outline-secondary my-2 my-sm-0" name="logout">Logout</button>
|
||||
</form>
|
||||
</div>
|
||||
');
|
||||
} else {
|
||||
echo ('
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#loginModal">Login</button>
|
||||
} else {
|
||||
echo ('
|
||||
<form class="form-inline" action="" method="POST">
|
||||
<button type="button" class="btn btn-outline-secondary my-2 my-sm-0" data-bs-toggle="modal" data-bs-target="#loginModal">Login</button>
|
||||
</form>
|
||||
');
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
<form class="form-inline" action="" method="POST">
|
||||
<select class="form-control" name="sortby" id="sortby">
|
||||
<option <?php echo ($sortby == 'price_asc' ? 'selected="selected"' : ''); ?> value="price_asc">Preis aufsteigend</option>
|
||||
<option <?php echo ($sortby == 'price_desc' ? 'selected="selected"' : ''); ?> value="price_desc">Preis absteigend</option>
|
||||
<option <?php echo ($sortby == 'date_desc' ? 'selected="selected"' : ''); ?> value="date_desc">Datum, neu -> alt</option>
|
||||
<option <?php echo ($sortby == 'date_asc' ? 'selected="selected"' : ''); ?> value="date_asc">Datum, alt -> neu</option>
|
||||
<option <?php echo ($sortby == 'random' ? 'selected="selected"' : ''); ?> value="random">Zufall</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -162,7 +216,7 @@ if (isset($_POST['reservation'])) {
|
||||
</div>
|
||||
');
|
||||
}
|
||||
wishlistMainBuilder($ListID);
|
||||
wishlistMainBuilder($ListID, $sortby);
|
||||
?>
|
||||
</main>
|
||||
|
||||
@@ -201,7 +255,7 @@ if (isset($_POST['reservation'])) {
|
||||
|
||||
<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€" />
|
||||
<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>
|
||||
|
||||
@@ -257,6 +311,33 @@ if (isset($_POST['reservation'])) {
|
||||
</div>
|
||||
');
|
||||
}
|
||||
|
||||
if ($loggedin == true) {
|
||||
echo ('
|
||||
<!-- Modal Delete-->
|
||||
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="deleteModalLabel">Wunsch löschen</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h5 id="whish-title">WunschTitel</h5>
|
||||
<p>Soll dieser Wunsch wirklich gelöscht werden ?</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" id="WhishID" name="WhishID" value="-1">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="submit" name="delete" class="btn btn-primary">Löschen</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
');
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- Modal Reservation-->
|
||||
@@ -304,6 +385,22 @@ if (isset($_POST['reservation'])) {
|
||||
modal.find('#reservationModalLabel').text('Wunsch reservieren')
|
||||
}
|
||||
});
|
||||
|
||||
$('#deleteModal').on('show.bs.modal', function(event) {
|
||||
var resTr = $(event.relatedTarget)
|
||||
var whishcard = resTr.parents().closest('.card');
|
||||
var whishtitle = whishcard.find('.card-title').text();
|
||||
var wishid = resTr.data('wishid')
|
||||
var modal = $(this)
|
||||
modal.find('#WhishID').val(wishid)
|
||||
modal.find('#whish-title').text(whishtitle)
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#sortby').on('change', function() {
|
||||
this.form.submit();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
Reference in New Issue
Block a user