Grundfunktionen implementiert

Wird noch bearbeitet, siehe TODO Liste am Anfang
master
Jasmin Weise 2023-06-13 23:02:21 +02:00
parent 75accc1cd2
commit 26db92adeb
1 changed files with 310 additions and 88 deletions

View File

@ -1,95 +1,317 @@
<!--
TODO:
- Seite ist noch nicht erreichbar
- Jetzt reservieren Button nur klickbar machen, wenn Bücher im Warenkorb liegen
- Löschbestätigung -> removeBookFromCart verschieben
- ? Artikel (totale Anzahl aller Artikel)
TODO (optional, geringe Priorität):
- 80 Zeichen
- JS Funktionen größtmöglich auslagern
- Mengenfeld bearbeitbar machen
- Layout verbessern (z.B. resize)
-->
<!DOCTYPE html> <!DOCTYPE html>
<html>
<head>
<meta lang="de"/>
<meta charset="utf-8"/>
<meta name="viewport" content="device=device-width, initial-scaling=1"/>
<link rel="Stylesheet" type="text/css" href="style.css"/>
<link rel="Stylesheet" type="text/css" href="warenkorb.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Candle Bibliothek | Warenkorb</title>
<link rel="icon" href="pictures/candle.png">
<script src="notwendiges_laden.js" defer></script>
</head>
<body>
<header id="header"></header>
<?php <!------------------------------------------------------------------------->
session_start(); <div class="hauptcontainer">
$db_link = mysqli_connect('localhost', 'web_b-3', 'een7Ao6s', 'bibliothek_candle', '3306'); <h1 id="shoppingCart_heading">Warenkorb</h1>
<div id="secondary_container">
<div id='cartItems_container'>
<?php
session_start();
function runSQL($sql){ // Counter für Divider
global $db_link; $counter = 0;
$db_res = mysqli_query($db_link, $sql);
if(!$db_res){
header("Location: 404.html");
exit;
}
return $db_res;
}
if(isset($_POST['submit'])){ // Überprüfen, ob Bücher im Warenkorb liegen
$kartenid = $_POST['karten-id']; if(isset($_SESSION['cart']) && !empty($_SESSION['cart'])) {
$passwort = $_POST['password']; // Es liegen Bücher im Warenkorb
// Alle Elemente im Warenkorb durchgehen
foreach ($_SESSION["cart"] as $key=>$item) {
$existiert = runSQL("SELECT COUNT(*) FROM `benutzer` WHERE `KartenID` = '$kartenid' and `Passwort` = '$passwort'"); $quantity = $item['quantity'];
$karteexistiert = runSQL("SELECT COUNT(*) FROM `benutzer` WHERE `KartenID` = '$kartenid'");
$zeile = mysqli_fetch_array($karteexistiert);
$row = mysqli_fetch_array($existiert);
if($row['COUNT(*)'] > 0){ $sql = '';
$_SESSION['eingeloggt'] = 1; $servername = "localhost";
$username = "web_b-3";
$password = "een7Ao6s";
$dbname = "bibliothek_candle";
echo '<html> $connection =
<head> mysqli_connect($servername, $username, $password, $dbname);
<meta lang="de"/>
<meta charset="utf-8"/>
<meta name="viewport" content="device=device-width, initial-scaling=1"/>
<link rel="Stylesheet" type="text/css" href="style.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Candle Bibliothek | Warenkorb</title>
<link rel="icon" href="pictures/candle.png">
<script src="notwendiges_laden.js" defer></script>
</head>
<body style="background-color:#987554;">
<header id="header"></header> if (!$connection) {
die("Verbindung fehlgeschlagen: " . mysqli_connect_error());
}
/* SQL-Befehl vorbereiten */
$sql = $connection->prepare("SELECT b.BuchID, b.Titel,
b.Bild,
GROUP_CONCAT(DISTINCT CONCAT(a.VorName, ' ', a.NachName)
SEPARATOR ', ') AS 'Autor',
IF(b.Anzahl!=0, 'Verfügbar', CONCAT('Verfügbar ab: ',
(SELECT DATE_FORMAT(DATE_ADD(ab.Enddatum, INTERVAL 1 DAY)
,'%d.%m.%Y') FROM `ausgeliehenes_buch` AS ab
WHERE ab.BuchID = b.BuchID
ORDER BY ab.Reserviert ASC, ab.Enddatum ASC LIMIT 1)))
AS 'Verfügbarkeit' FROM `buch` AS b
INNER JOIN `buch_verfasst_von_autor` AS bvva
ON b.BuchID = bvva.BuchID
INNER JOIN `autor` AS a ON bvva.AutorNr = a.AutorNr
WHERE b.BuchID = ?
GROUP BY b.BuchID;");
<div class="main"> // Parameter binden
<h1 id="warenkorbHeader"> $sql->bind_param("i", $ID);
Warenkorb
</h1>
<div class="containerOfAll"> // ID festlegen
$ID = $key;
// SQL-Befehl ausführen
$sql->execute();
// Ergebnis speichern
$result = $sql->get_result();
if ($counter != 0) {
echo "<div class='divider'></div>";
}
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$bookID = $row['BuchID'];
$bookCover = $row['Bild'];
$bookTitle = $row['Titel'];
$bookAuthor = $row['Autor'];
$bookAvailability = $row['Verfügbarkeit'];
// TODO: OnClick auslagern.
echo "<div id='book_container$bookID' class='book_container'
onclick='open_bookDetails(this.id)'>
<div class='bookCover_container'>
<img class='bookCover'
src='book_covers/$bookCover'
alt='Kein Bild vorhanden'>
</div>
<div class='bookDetails_container'>
<h2 class='bookTitle'>$bookTitle</h2>
<div class='bookDetails'>
<p class='author'>von $bookAuthor</p>
</div>
<div class='available_container'>
<p id='available_$bookID' class='available'>
$bookAvailability</p>
<!--TODO: Auslagern-->
<script type='text/javascript'
language='JavaScript'>
(function() {
var currentElement = document.
getElementById('available_$bookID');
var parentDiv =
currentElement.parentElement;
if (currentElement.innerHTML.trim()
== 'Verfügbar') {
parentDiv.style.backgroundColor
= '#70AD47';
}
else {
parentDiv.style.backgroundColor
= '#F34343';
}
})();
</script>
</div>
</div>
<!--TODO: OnClick Event auslagern-->
<div class='quantity_container'>
<div class='reduce_container'
id='reduce$bookID'
onclick='decreaseQuantity(this.id)'>
<div class='reduce'></div>
</div>
<div class='quantityText_container'>
<p class='quantityText'
id='quantityText$bookID'>$quantity</p>
</div>
<div class='add_container'
id='add$bookID'
onclick='increaseQuantity(this.id)'>
<div class='add'></div>
</div>
</div>
<div class='trashCan_container'
id='trashCan$bookID'
onclick='removeBookFromCart(this.id)'>
<div class='trashCan'></div>
</div>
</div>";
$counter++;
}
} else {
echo "Keine Ergebnisse.";
}
</div> if (!$result) {
die("Ungültige SQL-Abfrage: " . mysqli_connect_error());
}
<!--Reservieren--> mysqli_close($connection);
<div id="reservieren">
<h2 id="ArtikelWarenkorb"> </h2>
<a id="jetztReservieren" href="reservierung.php">Jetzt reservieren</a>
</div>
</div>
<script> $counter++;
var widthissue = false; }
window.addEventListener("resize", function(event) { }
if(window.innerWidth > 800 && widthissue) { else {
widthissue = false // Es liegen keine Bücher im Warenkorb
unset() echo
} "Der Warenkorb ist leer,
else if(window.innerWidth < 800) widthissue = true; bitte fügen Sie Bücher hinzu.";
}) }
</script> ?>
<nav id="activeid" class="active"></nav> </div>
<div id='totalQuantity_container'>
<div id='totalQuantityText_container'>
<p id='totalQuantityText'>? Artikel</p>
</div>
<input type='button' id='reserveNow'
onclick='open_reservation()' value='Jetzt reservieren'>
</div>
</div>
</div>
<!------------------------------------------------------------------------->
<footer id="footer" class="fuss" ></footer> <!-- TODO: Auslagern (falls möglich) -->
</body> <script>
function open_bookDetails(ID) {
var data = new URLSearchParams();
data.append("bookID", ID);
var url = "http://141.19.142.11/buch_details.php?" +
data.toString();
location.href = url;
}
</html>'; function decreaseQuantity(ID) {
}else if($zeile['COUNT(*)'] > 0){ // OnClick Event für open_bookDetails stoppen
header("Location: passwort_stimmt_nicht.php"); if (!e) var e = window.event;
}else{ e.cancelBubble = true;
header("Location: benutzer_existiert_nicht.php"); if (e.stopPropagation) e.stopPropagation();
}
}else{
header("Location: 404.html");
}
?> // ID abtrennen
ID = ID.replace('reduce', '');
var request = new XMLHttpRequest();
request.open('POST',
'http://141.19.142.11/warenkorb_funktionen.php', true);
// TODO: Handler erstellen
request.onload = function() {
console.log(this.responseText);
// Überprüfen, ob die Menge im Warenkorb verringert wurde
if (this.responseText.includes('Erfolgreich verringert')) {
toChange = document.getElementById(`quantityText${ID}`);
toChange.innerHTML = parseInt(toChange.innerHTML) - 1;
}
}
request.setRequestHeader('Content-type',
'application/x-www-form-urlencoded');
request.send(`function=decreaseQuantity&id=${ID}`);
}
function increaseQuantity(ID) {
// OnClick Event für open_bookDetails stoppen
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
// ID abtrennen
ID = ID.replace('add', '');
var request = new XMLHttpRequest();
request.open('POST',
'http://141.19.142.11/warenkorb_funktionen.php', true);
// TODO: Handler erstellen
request.onload = function() {
console.log(this.responseText);
// Überprüfen, ob die Menge im Warenkorb erhöht wurde
if (this.responseText.includes('Erfolgreich erhöht')) {
toChange = document.getElementById(`quantityText${ID}`);
toChange.innerHTML = parseInt(toChange.innerHTML) + 1;
}
}
request.setRequestHeader('Content-type',
'application/x-www-form-urlencoded');
request.send(`function=increaseQuantity&id=${ID}`);
}
function removeBookFromCart(ID) {
// OnClick Event für open_bookDetails stoppen
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
// ID abtrennen
ID = ID.replace('trashCan', '');
var request = new XMLHttpRequest();
request.open('POST',
'http://141.19.142.11/warenkorb_funktionen.php', true);
// TODO: Handler erstellen
request.onload = function() {
console.log(this.responseText);
// Überprüfen, ob das Buch aus dem Warenkorb entfernt wurde
if (this.responseText.includes('Erfolgreich entfernt')) {
window.location.reload(true);
}
}
request.setRequestHeader('Content-type',
'application/x-www-form-urlencoded');
request.send(`function=removeBookFromCart&id=${ID}`);
}
function open_reservation() {
var url = "http://141.19.142.11/reservierung.php";
location.href = url;
}
</script>
<!------------------------------------------------------------------------->
<!--Link JS file-->
<script src="burgerIcon.js"></script>
<!--If it was small and got big,
it calls the function only one time and doesn't do it all the time-->
<script>
var widthissue = false;
window.addEventListener("resize", function(event) {
if(window.innerWidth > 800 && widthissue) {
widthissue = false
unset()
}
else if(window.innerWidth < 800) widthissue = true;
})
</script>
<nav id="activeid" class="active"></nav>
<footer id="footer" class="fuss" ></footer>
</body>
</html>