-
Notifications
You must be signed in to change notification settings - Fork 0
/
novel-listing.php
308 lines (275 loc) · 11.2 KB
/
novel-listing.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php require_once './modules/conn.php';
require_once './modules/userActivity.php';
$query = "SELECT COUNT(*) AS total_rows FROM novels";
$result = mysqli_query($conn, $query);
if ($result) {
$row = mysqli_fetch_assoc($result);
$totalRows = $row['total_rows'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="BookStore HTML5 Template" />
<title>Novels Nest - Find your favorite Novels</title>
<?php require_once './components/head.php' ?>
</head>
<body>
<!-- Preloader-->
<div id="preloader">
<div class="loader">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
<!-- Back To Top Start -->
<a href="#main-wrapper" id="backto-top" class="back-to-top"><i class="fas fa-angle-up"></i></a>
<!-- Main Wrapper Start -->
<div id="main-wrapper" class="main-wrapper overflow-hidden">
<?php require_once './components/header.php' ?>
<!-- Banner-3 Start -->
<div class="hero-banner-3 bg-lightest-gray">
<div class="container">
<div class="row">
<div class="col-xl-6 col-lg-4 col-md-4 col-sm-12">
<div class="text-block">
<h1 class="mb-12">Novels</h1>
<p class="dark-gray">Novels are windows to worlds unseen, where imagination dances with words, and every page is an invitation to explore the boundless realms of human experience.</p>
</div>
</div>
<div class="col-xl-6 col-lg-8 col-md-8 col-sm-12">
<div class="images-row">
<img src="assets/media/banner/banner2-2.png" class="blog-img" alt="">
<img src="assets/media/banner/banner2-3.png" class="blog-img big" alt="">
<img src="assets/media/banner/banner2-1.png" class="blog-img" alt="">
</div>
</div>
</div>
</div>
</div>
<!-- Banner-3 End-->
<!-- Main Content Start -->
<div class="page-content">
<section>
<div class="container">
<div class="row">
<div class="top-row p-40">
<div class="col-sm-6">
<div class="left-block">
<h6 class="dark-gray">Showing 1-9 of <?php echo $totalRows?> results</h6>
<a href="#" id="showAllLink" class="color-primary fs-6">Show All</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-3">
<div class="sidebar">
<div class="sidebar mb-48">
<div class="sidebar-block">
<div class="filters">
<form>
<div class="filter-block">
<h4 class="mb-24">Filter</h4>
<div class="form-group has-search">
<input type="text" class="form-control" placeholder="Find the books..." id="searchInput">
<button type="submit" class="b-unstyle"><i class="fal fa-search" onclick="filterNovels()"></i></button>
</div>
</div>
<hr>
<hr>
<div class="filter-block">
<div class="title mb-32">
<h5>Novel Genres</h5>
<i class="far fa-horizontal-rule"></i>
</div>
<?php
$queryTopGenres = "SELECT genres.name, COUNT(novels.genre_id) as novel_count
FROM genres
LEFT JOIN novels ON genres.genre_id = novels.genre_id
GROUP BY genres.genre_id
ORDER BY novel_count DESC
LIMIT 2";
$resultTopGenres = mysqli_query($conn, $queryTopGenres);
if ($resultTopGenres) {
echo '<ul class="unstyled list">';
while ($row = mysqli_fetch_assoc($resultTopGenres)) {
echo '<li class="mb-16">';
echo '<div class="filter-checkbox">';
echo '<input type="radio" name="genre" class="genre-checkbox" id="' . $row['name'] . '" data-genre="' . $row['name'] . '">';
echo '<label for="' . $row['name'] . '">' . $row['name'] . '</label>';
echo '</div>';
echo '<h6 class="dark-gray">(' . $row['novel_count'] . ')</h6>';
echo '</li>';
}
echo '</ul>';
} else {
echo 'Error executing the top genres query: ' . mysqli_error($conn);
}
$queryRestGenres = "SELECT genres.name, COUNT(novels.genre_id) as novel_count
FROM genres
LEFT JOIN novels ON genres.genre_id = novels.genre_id
GROUP BY genres.genre_id
ORDER BY novel_count DESC
LIMIT 2, 100"; // Skip the top 2 and fetch the next 100
$resultRestGenres = mysqli_query($conn, $queryRestGenres);
if ($resultRestGenres) {
echo '<ul id="more-categories" class="accordion-collapse collapse unstyled list" data-bs-parent="#accordionExample">';
while ($row = mysqli_fetch_assoc($resultRestGenres)) {
echo '<li class="mb-16">';
echo '<div class="filter-checkbox">';
echo '<input type="radio" name="genre" id="' . $row['name'] . '">';
echo '<label for="' . $row['name'] . '">' . $row['name'] . '</label>';
echo '</div>';
echo '<h6 class="dark-gray">(' . $row['novel_count'] . ')</h6>';
echo '</li>';
}
echo '</ul>';
echo '<a href="#" class="accordion-button load-more-btn" data-bs-toggle="collapse" data-bs-target="#more-categories" aria-expanded="true"> Show More</a>';
} else {
echo 'Error executing the rest genres query';
}
?>
</div>
<hr>
<div class="filter-block">
<div class="title mb-32">
<h5>Authors</h5>
<i class="far fa-horizontal-rule"></i>
</div>
<?php
$queryTopAuthors = "SELECT authors.name, COUNT(novels.author_id) as novel_count
FROM authors
LEFT JOIN novels ON authors.author_id = novels.author_id
GROUP BY authors.author_id
ORDER BY novel_count DESC
LIMIT 2";
$resultTopAuthors = mysqli_query($conn, $queryTopAuthors);
if ($resultTopAuthors) {
echo '<ul class="unstyled list">';
while ($row = mysqli_fetch_assoc($resultTopAuthors)) {
echo '<li class="mb-16">';
echo '<div class="filter-checkbox">';
echo '<input type="radio" class="author-checkbox" data-author="' . $row['name'] . '" id="' . $row['name'] . '">';
echo '<label for="' . $row['name'] . '">' . $row['name'] . '</label>';
echo '</div>';
echo '<h6 class="dark-gray">(' . $row['novel_count'] . ')</h6>';
echo '</li>';
}
echo '</ul>';
} else {
echo 'Error executing the top authors query: ' . mysqli_error($conn);
}
$queryRestAuthors = "SELECT authors.name, COUNT(novels.author_id) as novel_count
FROM authors
LEFT JOIN novels ON authors.author_id = novels.author_id
GROUP BY authors.author_id
ORDER BY novel_count DESC
LIMIT 2, 100"; // Skip the top 2 and fetch the next 100
$resultRestAuthors = mysqli_query($conn, $queryRestAuthors);
if ($resultRestAuthors) {
echo '<ul id="more-authors" class="accordion-collapse collapse unstyled list" data-bs-parent="#accordionExample">';
while ($row = mysqli_fetch_assoc($resultRestAuthors)) {
echo '<li class="mb-16">';
echo '<div class="filter-checkbox">';
echo '<input type="radio" class="author-checkbox" data-author="' . $row['name'] . '" id="' . $row['name'] . '">';
echo '<label for="' . $row['name'] . '">' . $row['name'] . '</label>';
echo '</div>';
echo '<h6 class="dark-gray">(' . $row['novel_count'] . ')</h6>';
echo '</li>';
}
echo '</ul>';
echo '<a href="#" class="accordion-button load-more-btn" data-bs-toggle="collapse" data-bs-target="#more-authors" aria-expanded="true"> Show More</a>';
} else {
echo 'Error executing the rest authors query';
}
?>
</div>
<hr>
<button type="reset" id="restBtn" class="b-unstyle cus-btn w-100 mt-2" name="reset">
<span class="icon"><img src="assets/media/icons/click-button.png" alt=""></span>Reset
</button>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-9">
<div class="row" id="filteredNovelsContainer">
</div>
</div>
</div>
</div>
</section>
</div>
<!-- Main Content End -->
<!-- Footer Start -->
<?php require './components/footer.php'?>
<!-- Footer Area End -->
</div>
<?php require './components/script.php' ?>
<?php require './modules/errorAlert.php';require_once './modules/adminActivity.php';?>
<script>
$(document).ready(function () {
// Attach click event to "Show All" link
$('#showAllLink').on('click', function (e) {
e.preventDefault();
// Trigger the server-side script with the 'showAll' parameter
updateFilteredNovels(true);
});
// Attach input event to search input
$('#searchInput').on('input', function () {
updateFilteredNovels();
});
// Attach click event to genre checkboxes
$('.genre-checkbox').on('click', function () {
updateFilteredNovels();
});
// Attach click event to author checkboxes
$('.author-checkbox').on('click', function () {
updateFilteredNovels();
});
$('#restBtn').on('click', function () {
updateFilteredNovels();
});
// Initialize filtered novels on page load
updateFilteredNovels();
function updateFilteredNovels(showAll = false) {
// Collect selected genres and authors
var selectedGenres = $('.genre-checkbox:checked').map(function () {
return $(this).data('genre');
}).get();
var selectedAuthors = $('.author-checkbox:checked').map(function () {
return $(this).data('author');
}).get();
// Get the search query
var searchQuery = $('#searchInput').val();
// Send AJAX request to the server
$.ajax({
type: 'POST',
url: './modules/novelSearcher.php', // Replace with the actual PHP handler file
data: {
action: 'filterNovels',
genres: selectedGenres,
authors: selectedAuthors,
searchQuery: searchQuery,
showAll: showAll ? 'true' : ''
},
success: function (response) {
// Update the container with filtered novels
$('#filteredNovelsContainer').html(response);
console.log(response)
}
});
}
});
</script>
</body>
</html>