Meine Bücher weiter gemacht

master
Nils Eilinghoff 2023-06-14 16:18:00 +02:00
parent f775cc5585
commit 149cda66ae
1 changed files with 62 additions and 42 deletions

View File

@ -81,53 +81,71 @@ if(isset($_POST['submit'])){
<h1 id="searchResult_heading">Meine Bücher</h1> <h1 id="searchResult_heading">Meine Bücher</h1>
<div id="searchResult_container">'; <div id="searchResult_container">';
$sql = "SELECT b.BuchID, b.Titel, b.Bild, $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,
GROUP_CONCAT(DISTINCT CONCAT(a.VorName, ' ', a.NachName) GROUP_CONCAT(DISTINCT CONCAT(a.VorName, ' ', a.NachName)
SEPARATOR ', ') AS 'Autor', SEPARATOR ', ') AS 'Autor',
IF(b.Anzahl!=0, 'Verfügbar', CONCAT('Verfügbar ab: ', IF(
(SELECT DATE_FORMAT(DATE_ADD(ab.Enddatum, INTERVAL 1 DAY) (SELECT ausgeliehenes_buch.Anfangsdatum FROM ausgeliehenes_buch WHERE ausgeliehenes_buch.AusleihID=ab.AusleihID) = Curdate(), 'Sofort Abholbereit',
,'%d.%m.%Y') FROM `ausgeliehenes_buch` AS ab (
WHERE ab.BuchID = b.BuchID IF(
ORDER BY ab.Reserviert ASC, ab.Enddatum ASC LIMIT 1))) (SELECT ausgeliehenes_buch.Anfangsdatum FROM ausgeliehenes_buch WHERE ausgeliehenes_buch.AusleihID=ab.AusleihID) > Curdate(),
AS 'Verfügbarkeit' FROM `buch` AS b 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
INNER JOIN `buch_verfasst_von_autor` AS bvva INNER JOIN `buch_verfasst_von_autor` AS bvva
ON b.BuchID = bvva.BuchID ON b.BuchID = bvva.BuchID
INNER JOIN `autor` AS a ON bvva.AutorNr = a.AutorNr INNER JOIN `autor` AS a ON bvva.AutorNr = a.AutorNr
INNER JOIN `buch_hat_kategorie` AS bhk ON bhk.BuchID = b.BuchID WHERE ab.BenutzerID=?
INNER JOIN `kategorie` AS k ON k.KategorieID = bhk.KategorieID GROUP BY ab.AusleihID;");
INNER JOIN `sprache` AS sp ON sp.SprachenID = b.SprachenID
INNER JOIN `buch_hat_stichwort` AS bhs ON bhs.BuchID = b.BuchID
INNER JOIN `stichwort` AS st ON st.StichwortID = bhs.StichwortID
GROUP BY b.BuchID
;";
$servername = "localhost"; $sql->bind_param("i", $BenutzerID);
$username = "web_b-3"; $BenutzerID = 5;
$password = "een7Ao6s"; $sql->execute();
$dbname = "bibliothek_candle"; $result = $sql->get_result();
$connection = $db_link;
$connection = mysqli_connect($servername, $username, $password, $dbname);
if (!$connection) { if (!$connection) {
die("Verbindung fehlgeschlagen: " . mysqli_connect_error()); die("Verbindung fehlgeschlagen: " . mysqli_connect_error());
} }
$result = mysqli_query($connection, $sql);
$counter = 0; $counter = 0;
if (mysqli_num_rows($result) > 0) { if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) { while($row = mysqli_fetch_assoc($result)) {
$bookID = $row['BuchID']; $bookID = $row['BuchID'];
$ausleihID = $row['AusleihID'];
$bookCover = $row['Bild']; $bookCover = $row['Bild'];
$bookTitle = $row['Titel']; $bookTitle = $row['Titel'];
$bookAuthor = $row['Autor']; $bookAuthor = $row['Autor'];
$bookAvailability = $row['Verfügbarkeit']; $bookAvailability = $row['Verfügbarkeit'];
$bookExtendable = $row['Verlängerbar'];
$bookStartdate = $row['Anfangsdatum'];
$bookEnddate = $row['Enddatum'];
$bookStartdatePlusSeven = $bookStartdate +7;
if ($counter != 0) { if ($counter != 0) {
echo "<div class='divider'></div>"; echo "<div class='divider'></div>";
} }
// TODO: OnClick auslagern. // TODO: OnClick auslagern.
echo "<div id='book_container$bookID' class='book_container' echo "<div id='book_container$bookID+$ausleihID' class='book_container'
onclick='open_bookDetails(this.id)'> onclick='open_bookDetails(this.id)'>
<div class='bookCover_container'> <div class='bookCover_container'>
<img class='bookCover' src='book_covers/$bookCover' <img class='bookCover' src='book_covers/$bookCover'
@ -140,35 +158,36 @@ if(isset($_POST['submit'])){
</div> </div>
<div class='available_container'> <div class='available_container'>
<p id='available_$bookID' class='available'> <p id='available_$ausleihID' class='available'>
$bookAvailability</p> $bookAvailability</p>
<!--TODO: Auslagern--> </div>
<script type='text/javascript' <div>
<p id='bestellungsInfo$ausleihID'></p>
</div>
<script type='text/javascript'
language='JavaScript'> language='JavaScript'>
(function() { (function() {
var currentElement = document. var currentElement = document.
getElementById('available_$bookID'); getElementById('available_$ausleihID');
var parentDiv = var parentDiv = currentElement.parentElement;
currentElement.parentElement; if (currentElement.innerHTML.trim() === 'Sofort Abholbereit') {
if (currentElement.innerHTML.trim()
== 'Verfügbar') {
parentDiv.style.backgroundColor parentDiv.style.backgroundColor
= '#70AD47'; = '#70AD47';
document.getElementById('bestellungsInfo$ausleihID').innerHTML = 'Diese Reservierung verfällt, wenn das Buch nicht bis zum $bookStartdatePlusSeven abgeholt wurde.';
} }
else { else if (currentElement.innerHTML.trim().includes('Rückgabe') && $bookExtendable === 1){
parentDiv.style.backgroundColor
= '#70AD47';
} else if (currentElement.innerHTML.trim().includes('Rückgabe') && $bookExtendable === 0){
parentDiv.style.backgroundColor parentDiv.style.backgroundColor
= '#F34343'; = '#F34343';
} else {
parentDiv.style.backgroundColor
= '#F34343';
document.getElementById('bestellungsInfo$ausleihID').innerHTML = 'Dieses Buch ist für sie Reserviert.';
} }
})(); })();
</script> </script>
</div>
<div>
<script>
</script>
<p>Helloooo</p>
</div>
</div> </div>
<div class='shoppingCart_container'> <div class='shoppingCart_container'>
<div class='shoppingCart'></div> <div class='shoppingCart'></div>
@ -205,6 +224,7 @@ if(isset($_POST['submit'])){
<script> <script>
function open_bookDetails(ID) { function open_bookDetails(ID) {
var data = new URLSearchParams(); var data = new URLSearchParams();
ID = ID.substr(0, ID.lastIndexOf('+'));
data.append("bookID", ID); data.append("bookID", ID);
var url = "http://141.19.142.11/buch_details.php?" + var url = "http://141.19.142.11/buch_details.php?" +