-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_display_page.php
138 lines (124 loc) · 5.07 KB
/
book_display_page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php include_once("./view/layout/head.php") ?>
<?php include_once("./view/components/header/header.php") ?>
<?php
$book_id = filter_input(INPUT_GET, "book-id", FILTER_SANITIZE_STRING);
$book;
$book_genres;
if ($book_id != null) {
$query = "SELECT * FROM books WHERE id = '$book_id' LIMIT 1";
$result = $connection->execute_query($query);
$book = $result->fetch_all(MYSQLI_ASSOC)[0];
$query = "
SELECT genres.id, genres.title FROM books_to_genres
JOIN genres ON books_to_genres.genre_id = genres.id
JOIN books ON books_to_genres.book_id = books.id
WHERE books.id = $book_id
";
$result = $connection->execute_query($query);
$book_genres = $result->fetch_all(MYSQLI_ASSOC);
}
?>
<?php include_once("./view/components/input_field/input_field.php") ?>
<link rel="stylesheet" href="./view/pages/book_display_page/book_display_page.css">
<main id="book-display-page">
<?php if ($book != null): ?>
<div class="book-card" tabindex="0" onclick="this.querySelector('form>button').click();">
<form action="./book_display_page.php" method="GET" aria-hidden>
<input type="hidden" name="book_id" value="<?= $book["id"] ?>" />
<button type="submit"></button>
</form>
<header>
<p>
<?= str_pad(floor($book["price"]), 3, "0", STR_PAD_LEFT) . "." .
str_pad(round($book["price"] - floor($book["price"]), 2) * 100, 2, "0", STR_PAD_RIGHT) ?>$
</p>
<div class="star-displayer" title="This book has a rating of <?= $book["rating"] * 2 ?>/10.">
<div>
<?php for ($i = 5; $i > 0; $i--): ?>
<span>
<?php include("./assets/icons/star.svg") ?>
</span>
<?php endfor ?>
</div>
<div>
<?php for ($i = $book["rating"]; $i > 0; $i--): ?>
<span data-is-half="<?= ($i == 0.5) ? "true" : "" ?>">
<?php include("./assets/icons/star.svg") ?>
</span>
<?php endfor ?>
</div>
</div>
</header>
<figure>
<img src="<?= "./uploads/covers/" . $book["cover_url"] ?>" aria-hidden>
<img src="<?= "./uploads/covers/" . $book["cover_url"] ?>"
alt="The cover of the book "<?= $book["title"] ?>".">
</figure>
<figcaption>
<p>
<?= $book["title"] ?>
</p>
<?php if (trim($book["author"]) != ""): ?>
<p>
By
<a href="?author=<?= $book["author"] ?>"
title="Click to see other books made by <?= $book["author"] ?>.">
<?= $book["author"] ?>
</a>
</p>
<?php endif ?>
</figcaption>
</div>
<section>
<div>
<div class="colourized-text">Title:</div>
<div>
<?= $book["title"] ?>
</div>
</div>
<div>
<div class="colourized-text">Author:</div>
<div>
<?= $book["author"] ?>
</div>
</div>
<div id="genre-displayer">
<div class="colourized-text">Genres:</div>
<?php foreach ($book_genres as $genre): ?>
<div>
<?= $genre["title"] ?>
</div>
<?php endforeach ?>
</div>
<form action="./control/add_to_cart.php" method="POST">
<input name="book-id" type="hidden" value="<?= $book["id"] ?>">
<input name="user-id" type="hidden" value="<?= $_SESSION["user"]["id"]; ?>">
<?= input_field(
$name = "bought-amount",
$title = "Bought Amount",
$type = "number",
$value = 1,
$pattern = null,
$pattern_message = null,
$id = null,
$optional = false,
$minimum = 1,
$maximum = 99,
) ?>
<section class="button-displayer">
<button type="reset">Reset</button>
<button type="submit">Add to Cart</button>
</section>
</form>
</section>
<?php else: ?>
<main id="book-display-message">
<section>
<h1>Book Not Found</h1>
<p>The book you're looking for doesn't exist.</p>
</section>
</main>
<?php endif ?>
</main>
<?php include_once("./view/components/footer/footer.php") ?>
<?php include_once("./view/layout/foot.php") ?>