Candle/meinebuecher.php

245 lines
10 KiB
PHP
Raw Normal View History

2023-06-14 11:44:33 +02:00
<!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="suchergebnisse.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Candle Bibliothek | Meine Bücher</title>
<link rel="icon" href="pictures/candle.png">
<script src="notwendiges_laden.js" defer></script>
</head>
<body>
<header id="header">
<h1 class="kopf" >
<br><br>
Bibliothek
<a href="index.html" id="bildID">
<img id="CandleID" src="pictures/candle.png"
alt="Bild von einer Kerze" width="200" height="192"/></a>
<br><br>
Candle
</h1>
<div>
<a id="uberuns" href="uberuns.html">Über Uns</a>
<a id="buecher" href="buecher.php">Bücher</a>
<a id="meinebuecher" href="anmelden_meinebuecher.php">
Meine Bücher</a>
<?php
session_start();
if(isset($_SESSION["eingeloggt"]) && $_SESSION["eingeloggt"] == 1 ){
echo "<a id='abmelden' href='abmelden.php'>Abmelden</a>";}
?>
<form action="suchergebnisse.php">
<input type="hidden" name="searchType" value="simple">
<input name="searchFor" class="suchleiste" type="search"
placeholder="Suche...">
<button type="submit" id="buttonID" class="searchButton">
<i class="fa fa-search"></i>
</button>
</form>
<a id="erweitertesuche" href="erweitertesuche.html">
Erweiterte Suche</a>
<a href="anmelden.php" id="warenKorbID">
<img id="shoppingCard" src="pictures/einkaufswagen.png"
alt="Bild von einem Wagen" width="50" height="50"/>
</a>
</div>
</header>
2023-05-26 16:39:10 +02:00
<?php
session_start();
$db_link = mysqli_connect('localhost', 'web_b-3', 'een7Ao6s', 'bibliothek_candle', '3306');
function runSQL($sql){
global $db_link;
$db_res = mysqli_query($db_link, $sql);
if(!$db_res){
header("Location: 404.html");
exit;
}
return $db_res;
}
2023-06-11 12:00:38 +02:00
if(isset($_POST['submit'])){
$kartenid = $_POST['karten-id'];
2023-06-05 15:13:50 +02:00
$passwort = $_POST['password'];
2023-06-05 15:13:50 +02:00
$existiert = runSQL("SELECT COUNT(*) FROM `benutzer` WHERE `KartenID` = '$kartenid' and `Passwort` = '$passwort'");
$row = mysqli_fetch_array($existiert);
$karteexistiert = runSQL("SELECT COUNT(*) FROM `benutzer` WHERE `KartenID` = '$kartenid'");
$zeile = mysqli_fetch_array($karteexistiert);
2023-06-11 12:00:38 +02:00
if($row['COUNT(*)'] > 0){
$_SESSION['eingeloggt'] = 1;
2023-06-14 11:44:33 +02:00
echo '
2023-06-11 12:00:38 +02:00
<div class="hauptcontainer">
<h1 id="searchResult_heading">Meine Bücher</h1>
<div id="searchResult_container">';
2023-06-14 16:18:00 +02:00
$sql = $db_link->prepare(
"SELECT ab.AusleihID, ab.BuchID, b.Titel, b.Bild, ab.Verlängerbar, DATE_FORMAT(ab.Anfangsdatum, '%d.%m.%Y') as Anfangsdatum, DATE_FORMAT(ab.Enddatum, '%d.%m.%Y') as Enddatum,
2023-06-11 12:00:38 +02:00
GROUP_CONCAT(DISTINCT CONCAT(a.VorName, ' ', a.NachName)
SEPARATOR ', ') AS 'Autor',
2023-06-14 16:18:00 +02:00
IF(
(SELECT ausgeliehenes_buch.Anfangsdatum FROM ausgeliehenes_buch WHERE ausgeliehenes_buch.AusleihID=ab.AusleihID) = Curdate(), 'Sofort Abholbereit',
(
IF(
(SELECT ausgeliehenes_buch.Anfangsdatum FROM ausgeliehenes_buch WHERE ausgeliehenes_buch.AusleihID=ab.AusleihID) > Curdate(),
CONCAT(
'Abholbereit am: ', (
SELECT DATE_FORMAT(
ausgeliehenes_buch.Anfangsdatum , '%d.%m.%Y'
) FROM ausgeliehenes_buch WHERE ausgeliehenes_buch.AusleihID=ab.AusleihID
)
)
, CONCAT(
'Rückgabe am: ', (
SELECT DATE_FORMAT(
ausgeliehenes_buch.Enddatum , '%d.%m.%Y'
) FROM ausgeliehenes_buch WHERE ausgeliehenes_buch.AusleihID=ab.AusleihID
)
))
)
)
AS 'Verfügbarkeit'
FROM ausgeliehenes_buch AS ab
INNER JOIN buch as b
ON ab.BuchID = b.BuchID
2023-06-11 12:00:38 +02:00
INNER JOIN `buch_verfasst_von_autor` AS bvva
ON b.BuchID = bvva.BuchID
2023-06-14 16:18:00 +02:00
INNER JOIN `autor` AS a ON bvva.AutorNr = a.AutorNr
WHERE ab.BenutzerID=?
GROUP BY ab.AusleihID;");
$sql->bind_param("i", $BenutzerID);
$BenutzerID = 5;
$sql->execute();
$result = $sql->get_result();
$connection = $db_link;
2023-06-11 12:00:38 +02:00
if (!$connection) {
die("Verbindung fehlgeschlagen: " . mysqli_connect_error());
}
$counter = 0;
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$bookID = $row['BuchID'];
2023-06-14 16:18:00 +02:00
$ausleihID = $row['AusleihID'];
2023-06-11 12:00:38 +02:00
$bookCover = $row['Bild'];
$bookTitle = $row['Titel'];
$bookAuthor = $row['Autor'];
$bookAvailability = $row['Verfügbarkeit'];
2023-06-14 16:18:00 +02:00
$bookExtendable = $row['Verlängerbar'];
$bookStartdate = $row['Anfangsdatum'];
$bookEnddate = $row['Enddatum'];
$bookStartdatePlusSeven = $bookStartdate +7;
2023-06-11 12:00:38 +02:00
if ($counter != 0) {
echo "<div class='divider'></div>";
}
// TODO: OnClick auslagern.
2023-06-14 16:18:00 +02:00
echo "<div id='book_container$bookID+$ausleihID' class='book_container'
2023-06-11 12:00:38 +02:00
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'>
2023-06-14 16:18:00 +02:00
<p id='available_$ausleihID' class='available'>
$bookAvailability</p>
</div>
<div>
<p id='bestellungsInfo$ausleihID'></p>
</div>
<script type='text/javascript'
2023-06-11 12:00:38 +02:00
language='JavaScript'>
(function() {
var currentElement = document.
2023-06-14 16:18:00 +02:00
getElementById('available_$ausleihID');
var parentDiv = currentElement.parentElement;
if (currentElement.innerHTML.trim() === 'Sofort Abholbereit') {
2023-06-11 12:00:38 +02:00
parentDiv.style.backgroundColor
= '#70AD47';
2023-06-14 16:18:00 +02:00
document.getElementById('bestellungsInfo$ausleihID').innerHTML = 'Diese Reservierung verfällt, wenn das Buch nicht bis zum $bookStartdatePlusSeven abgeholt wurde.';
2023-06-11 12:00:38 +02:00
}
2023-06-14 16:18:00 +02:00
else if (currentElement.innerHTML.trim().includes('Rückgabe') && $bookExtendable === 1){
parentDiv.style.backgroundColor
= '#70AD47';
} else if (currentElement.innerHTML.trim().includes('Rückgabe') && $bookExtendable === 0){
2023-06-11 12:00:38 +02:00
parentDiv.style.backgroundColor
= '#F34343';
2023-06-14 16:18:00 +02:00
} else {
parentDiv.style.backgroundColor
= '#F34343';
document.getElementById('bestellungsInfo$ausleihID').innerHTML = 'Dieses Buch ist für sie Reserviert.';
2023-06-11 12:00:38 +02:00
}
})();
</script>
</div>
<div class='shoppingCart_container'>
<div class='shoppingCart'></div>
</div>
</div>";
$counter++;
}
} else {
echo "Keine Ergebnisse.";
2023-06-05 15:13:50 +02:00
}
2023-06-11 12:00:38 +02:00
if (!$result) {
die("Ungültige SQL-Abfrage: " . mysqli_connect_error());
}
mysqli_close($connection);
}else if($zeile['COUNT(*)'] > 0){
header("Location: passwort_stimmt_nicht.php");
2023-06-11 12:00:38 +02:00
}else{
header("Location: benutzer_existiert_nicht.php");
2023-06-11 12:00:38 +02:00
}
}else{
2023-06-05 16:57:35 +02:00
header("Location: 404.html");
2023-06-11 12:00:38 +02:00
}
2023-05-26 16:39:10 +02:00
?>
2023-06-11 12:00:38 +02:00
</div>
</div>
<script>
function open_bookDetails(ID) {
var data = new URLSearchParams();
2023-06-14 16:18:00 +02:00
ID = ID.substr(0, ID.lastIndexOf('+'));
2023-06-11 12:00:38 +02:00
data.append("bookID", ID);
var url = "http://141.19.142.11/buch_details.php?" +
data.toString();
location.href = url;
}
</script>
<!--Link JS file-->
<script src="burgerIcon.js"></script>
<script src="resize.js"></script>
2023-06-11 12:00:38 +02:00
<!--Burger-->
2023-06-12 11:23:37 +02:00
<nav id="activeid" class="active"></nav>
2023-06-11 12:00:38 +02:00
<footer id="footer" class="fuss" ></footer>
</body>
</html>