Add List Functions working and changed image-URL
This commit is contained in:
@@ -10,6 +10,13 @@ $ItemPrice = $_POST['ItemPrice'];
|
|||||||
$ItemLink = $_POST['ItemLink'];
|
$ItemLink = $_POST['ItemLink'];
|
||||||
$ItemImage = $_POST['ItemImage'];
|
$ItemImage = $_POST['ItemImage'];
|
||||||
|
|
||||||
|
#--- check if the provided Link is a valid URL
|
||||||
|
|
||||||
|
if (filter_var($ItemLink, FILTER_VALIDATE_URL) === FALSE) {
|
||||||
|
die('Not a valid URL');
|
||||||
|
}
|
||||||
|
|
||||||
|
#---
|
||||||
|
|
||||||
#--- check if the provided Image-Link is a real image:
|
#--- check if the provided Image-Link is a real image:
|
||||||
|
|
||||||
@@ -17,7 +24,7 @@ $headers = array_change_key_case(get_headers($ItemImage, 1), CASE_LOWER);
|
|||||||
|
|
||||||
if (strpos($headers['content-type'], 'image/') !== false) {
|
if (strpos($headers['content-type'], 'image/') !== false) {
|
||||||
$strippedimagepath = strtok($ItemImage, '?');
|
$strippedimagepath = strtok($ItemImage, '?');
|
||||||
$imageLocalLink = 'data/images/' . uniqid() . '.' . pathinfo($strippedimagepath, PATHINFO_EXTENSION);
|
$imageLocalLink = $imagedir . '/' . uniqid() . '.' . pathinfo($strippedimagepath, PATHINFO_EXTENSION);
|
||||||
echo "ImageLink: " . $imageLocalLink;
|
echo "ImageLink: " . $imageLocalLink;
|
||||||
file_put_contents($imageLocalLink, fopen($strippedimagepath, 'r'));
|
file_put_contents($imageLocalLink, fopen($strippedimagepath, 'r'));
|
||||||
} else {
|
} else {
|
||||||
|
@@ -4,5 +4,6 @@ $servername = 'localhost';
|
|||||||
$username = 'wishlist';
|
$username = 'wishlist';
|
||||||
$db = 'wishlist';
|
$db = 'wishlist';
|
||||||
$password = 'R!6CIb-KxM96EC]6';
|
$password = 'R!6CIb-KxM96EC]6';
|
||||||
|
$imagedir = 'data/images';
|
||||||
|
|
||||||
?>
|
?>
|
32
include/delete_unused.php
Normal file
32
include/delete_unused.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once('../config/config.php');
|
||||||
|
$dir = new DirectoryIterator('../' . $imagedir);
|
||||||
|
|
||||||
|
$conn = new mysqli($servername, $username, $password, $db);
|
||||||
|
|
||||||
|
if ($conn->connect_error)
|
||||||
|
die('Connection failed: ' . $conn->connect_error);
|
||||||
|
|
||||||
|
$sql = 'SELECT image FROM whishes';
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
|
||||||
|
if ($result !== false && $result->num_rows > 0)
|
||||||
|
{
|
||||||
|
if ($rows = $result->fetch_all())
|
||||||
|
{
|
||||||
|
foreach ($dir as $fileinfo) {
|
||||||
|
if (!$fileinfo->isDot()) {
|
||||||
|
$filename = $fileinfo->getFilename();
|
||||||
|
|
||||||
|
if (!in_array($filename, $rows))
|
||||||
|
{
|
||||||
|
$deletepath = '../' . $imagedir . '/' . $filename;
|
||||||
|
unset($deletepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn->close();
|
@@ -4,7 +4,7 @@ include 'config/config.php';
|
|||||||
|
|
||||||
function generateListItem($ListItemID, $ItemImage, $ItemTitle, $ItemLink, $ItemPrice, $ItemComment, $ItemReserved, $ItemDate)
|
function generateListItem($ListItemID, $ItemImage, $ItemTitle, $ItemLink, $ItemPrice, $ItemComment, $ItemReserved, $ItemDate)
|
||||||
{
|
{
|
||||||
global $loggedin;
|
global $loggedin, $imagedir;
|
||||||
|
|
||||||
$formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
|
$formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ function generateListItem($ListItemID, $ItemImage, $ItemTitle, $ItemLink, $ItemP
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="card-title">' . $ItemTitle . '</h5>
|
<h5 class="card-title">' . $ItemTitle . '</h5>
|
||||||
</div>
|
</div>
|
||||||
<img src="' . $ItemImage . '" class="card-img-top">
|
<img src="' . $imagedir . '/' . $ItemImage . '" class="card-img-top">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="card-text">' . $ItemComment . '</p>
|
<p class="card-text">' . $ItemComment . '</p>
|
||||||
<div class="row justify-content-end">
|
<div class="row justify-content-end">
|
||||||
@@ -81,8 +81,31 @@ function wishlistMainBuilder($ListID, $sortby)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo ('
|
echo ('
|
||||||
<h1 class="fw-light">Das tut mir leid...</h1>
|
<div class="modal-dialog" role="document">
|
||||||
<p class="lead text-muted">Diese Liste gibt es nicht mehr</p>
|
<div class="modal-content rounded-4 shadow">
|
||||||
|
<div class="modal-header p-5 pb-4 border-bottom-0">
|
||||||
|
<h1 class="fw-bold mb-0 fs-2">Das tut mir leid...</h1>
|
||||||
|
<p class="modal-title fs-5" >..aber diese Liste exisiert nicht. Möchten Sie eine neue anlegen ?</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body p-5 pt-0">
|
||||||
|
<form action="" method="POST">
|
||||||
|
<div class="form-floating mb-3">
|
||||||
|
<input type="text" class="form-control rounded-3" id="listName" name="listName" placeholder="Name der Liste">
|
||||||
|
<label for="listName">Name der Liste</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating mb-3">
|
||||||
|
<input type="password" class="form-control rounded-3" id="listPassword" name="listPassword" placeholder="Password">
|
||||||
|
<label for="listPassword">Password</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating mb-3">
|
||||||
|
<input type="text" class="form-control rounded-3" id="listDescription" name="listDescription" placeholder="Beschreibung">
|
||||||
|
<label for="listDescription">Beschreibung</label>
|
||||||
|
</div>
|
||||||
|
<button class="w-100 mb-2 btn btn-lg rounded-3 btn-primary" name="listadd" type="submit">Absenden</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
index.php
58
index.php
@@ -51,6 +51,36 @@ if (isset($_POST['login'])) {
|
|||||||
$conn->close();
|
$conn->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['listadd'])) {
|
||||||
|
$listName = $_POST['listName'];
|
||||||
|
$listPassword = password_hash($_POST['listPassword'], PASSWORD_DEFAULT);
|
||||||
|
$listDescription = $_POST['listDescription'];
|
||||||
|
$conn = new mysqli($servername, $username, $password, $db);
|
||||||
|
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die('Connection failed: ' . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'INSERT INTO lists (title, description, edit_pw) VALUES ("' . $listName . '", "' .$listDescription. '","' . $listPassword . '")';
|
||||||
|
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
|
||||||
|
if ($conn->query($sql) === TRUE) {
|
||||||
|
$last_id = $conn->insert_id;
|
||||||
|
|
||||||
|
$_SESSION['listid'] = $last_id;
|
||||||
|
$loggedin = true;
|
||||||
|
$actual_link = 'http://' . $_SERVER['HTTP_HOST'] . '/?list=' . $last_id;
|
||||||
|
header('Location: ' . $actual_link);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$message = array('msg' => 'Error: ' . $sql . '<br>' . $conn->error, 'type' => 'error');
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_POST['logout'])) {
|
if (isset($_POST['logout'])) {
|
||||||
session_destroy();
|
session_destroy();
|
||||||
$loggedin = false;
|
$loggedin = false;
|
||||||
@@ -334,6 +364,7 @@ if (isset($_POST['delete']) && $loggedin == true) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- END OF Modal Delete-->
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -364,7 +395,7 @@ if (isset($_POST['delete']) && $loggedin == true) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- END OF Modal Reservation-->
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$('#reservationModal').on('show.bs.modal', function(event) {
|
$('#reservationModal').on('show.bs.modal', function(event) {
|
||||||
@@ -384,21 +415,28 @@ if (isset($_POST['delete']) && $loggedin == true) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#deleteModal').on('show.bs.modal', function(event) {
|
<?php
|
||||||
var resTr = $(event.relatedTarget)
|
if ($loggedin == true) {
|
||||||
var whishcard = resTr.parents().closest('.card');
|
echo ('
|
||||||
var whishtitle = whishcard.find('.card-title').text();
|
$(\'#deleteModal\').on(\'show.bs.modal\', function(event) \{
|
||||||
var wishid = resTr.data('wishid')
|
var resTr = $(event.relatedTarget)
|
||||||
var modal = $(this)
|
var whishcard = resTr.parents().closest(\'.card\');
|
||||||
modal.find('#WhishID').val(wishid)
|
var whishtitle = whishcard.find(\'.card-title\').text();
|
||||||
modal.find('#whish-title').text(whishtitle)
|
var wishid = resTr.data(\'wishid\')
|
||||||
});
|
var modal = $(this)
|
||||||
|
modal.find(\'#WhishID\').val(wishid)
|
||||||
|
modal.find(\'#whish-title\').text(whishtitle)
|
||||||
|
});
|
||||||
|
');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#sortby').on('change', function() {
|
$('#sortby').on('change', function() {
|
||||||
this.form.submit();
|
this.form.submit();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Reference in New Issue
Block a user