-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookborrow.php
353 lines (322 loc) · 19.1 KB
/
bookborrow.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<?php
require("templates/header.php");
?>
<style>
.form{
display:none;
}
</style>
<link rel="stylesheet" href="css/search.css">
<script>
$(document).ready(function(){
$('input[type="radio"]').click(function(){
var demovalue = $(this).val();
$("div.form").hide();
$("#show"+demovalue).show();
$("#table_display").hide();
});
});
$(function() {
var $radios = $('input:radio[name=demo]');
if(!document.location.search.length) {
$radios.filter('[value=Book]').prop('checked', true);
$("#showBook").show();
}
});
function disp_tab()
{
if(document.location.search.length) {
document.getElementById("table_display").style.display = "block"// query string exists
} else {
console.log("No display")
document.getElementById("table_display").style.display = "none"// no query string exists
}
}
</script>
</head>
<body onload = "disp_tab()">
</div>
<!--form start-->
<div class="container">
<div class="row">
<div class="col-md-12">
<div class = "structure">
<h2>Search for the book of your choice!</h2>
<!--radio button start-->
<input type="radio" name="demo" value="Book"/> Book name    
<input type="radio" name="demo" value="Author"/> Author name    
<input type="radio" name="demo" value="Publisher"/> Publisher name    
<input type="radio" name="demo" value="Domain"/> Type/ Domain
<!--radio button start-->
</div>
<div class = "input_display">
<div id="showBook" class="form">
<strong>Search by Book name :</strong><br><br>
<form id="MyForm" action="" method="GET">
<div class="input-group mb-3">
<input type="text" name="search_by_book" required value="<?php if(isset($_GET["search_by_book"])){echo $_GET["search_by_book"]; } ?>" class="form-control" placeholder="Search data"> 
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
</div>
<div id="showAuthor" class="form">
<strong>Search by Author name :</strong><br><br>
<form id="MyForm" action="" method="GET">
<div class="input-group mb-3">
<input type="text" name="search_by_author" required value="<?php if(isset($_GET["search_by_author"])){echo $_GET["search_by_author"]; } ?>" class="form-control" placeholder="Search data"> 
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
</div>
<div id="showPublisher" class="form">
<strong>Search by Publisher name :</strong><br><br>
<form id="MyForm" action="" method="GET">
<div class="input-group mb-3">
<input type="text" name="search_by_publ" required value="<?php if(isset($_GET["search_by_publ"])){echo $_GET["search_by_publ"]; } ?>" class="form-control" placeholder="Search data"> 
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
</div>
<div id="showDomain" class="form">
<strong>Search by Book type :</strong><br><br>
<form action="" method="GET">
<div class="input-group mb-3">
<select name="search_by_type" class = "form-select">
<?php
$con = mysqli_connect("localhost","root","","lib");
$sql = "SELECT * FROM rack";
$all_categories = mysqli_query($con,$sql);
$i=1;
while ($a3 = mysqli_fetch_array(
$all_categories,MYSQLI_ASSOC)):;
?>
<option value="<?php echo $a3["rack_type"];
?>">
<?php echo "Rack"." ".$i." - ".$a3["rack_type"];
// To show the category name to the user
?>
</option>
<?php
$i+=1;
endwhile;
// While loop must be terminated
?>
</select> 
<!-- <input type="text" name="search_by_type" required value="<?php if(isset($_GET["search_by_type"])){echo $_GET["search_by_type"]; } ?>" class="form-control" placeholder="Search data"> -->
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!--form end -->
<div id="table_display">
<div class="col-md-12">
<div class="card mt-4">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>book_id</th>
<th>Book_Name</th>
<th>First author</th>
<!--
<th>Second Author</th>
<th>Third Author</th>-->
<th>Publisher Name</th>
<th>Published Year</th>
<th>Edition</th>
<th>Copies</th>
<th>Book Type</th>
<th>Availability</th>
<th>Borrow</th>
</tr>
</thead>
<tbody>
<?php
$con = mysqli_connect("localhost","root","","lib");
/*------------book name----------------------------- */
if(isset($_GET['search_by_book']))
{
$filtervalues = $_GET['search_by_book'];
$query = "SELECT a1.name AS author_1, a2.name AS author_2, a3.name AS author_3,book_id,book_name,publisher_name,published_year,rack_type,edition,available_copies,availability FROM book AS b INNER JOIN publisher on b.publisher_id=publisher.publisher_id INNER JOIN rack on b.rack_id=rack.rack_id LEFT JOIN author AS a1 ON b.author1 = a1.author_id LEFT JOIN author AS a2 ON b.author2 = a2.author_id LEFT JOIN author AS a3 ON b.author3 = a3.author_id WHERE book_name LIKE '%$filtervalues%'";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) > 0)
{
foreach($query_run as $items)
{
?>
<tr>
<td><?= $items['book_id']; ?></td>
<td><?= $items['book_name']; ?></td>
<td><?= $items['author_1']; ?></td>
<!--
<td>$items['author_2']; </td>
<td> $items['author_3'];</td>-->
<td><?= $items['publisher_name']; ?></td>
<td><?= $items['published_year']; ?></td>
<td><?= $items['edition']; ?></td>
<td><?= $items['available_copies']; ?></td>
<td><?= $items['rack_type']; ?></td>
<td><?= $items['availability']; ?></td>
<?php $book_id = intval( $items['book_id']); ?>
<td><button class='btn btn-success'><a style='text-decoration:None;color:white;' href="userborrow.php? b_id=<?php echo $book_id; ?>" >Borrow</a></button></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="4">No Record Found</td>
</tr>
<?php
}
}
/*------------book name----------------------------- */
/*------------author name----------------------------- */
if(isset($_GET['search_by_author']))
{
$filtervalues = $_GET['search_by_author'];
$query = "SELECT a1.name AS author_1, a2.name AS author_2, a3.name AS author_3,book_id,book_name,publisher_name,published_year,rack_type,edition,available_copies,availability FROM book AS b INNER JOIN publisher on b.publisher_id=publisher.publisher_id INNER JOIN rack on b.rack_id=rack.rack_id LEFT JOIN author AS a1 ON b.author1 = a1.author_id LEFT JOIN author AS a2 ON b.author2 = a2.author_id LEFT JOIN author AS a3 ON b.author3 = a3.author_id WHERE a1.name LIKE '%$filtervalues%' or a2.name LIKE '%$filtervalues%' or a3.name LIKE '%$filtervalues%'";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) > 0)
{
foreach($query_run as $items)
{
?>
<tr>
<?$_SESSION["book_id"] = $items['book_id'];?>
<td><?= $items['book_id']; ?></td>
<td><?= $items['book_name']; ?></td>
<td><?= $items['author_1']; ?></td>
<!--
<td>$items['author_2']; </td>
<td> $items['author_3'];</td>-->
<td><?= $items['publisher_name']; ?></td>
<td><?= $items['published_year']; ?></td>
<td><?= $items['edition']; ?></td>
<td><?= $items['available_copies']; ?></td>
<td><?= $items['rack_type']; ?></td>
<td><?= $items['availability']; ?></td>
<?php $book_id = intval( $items['book_id']); ?>
<td><button class='btn btn-success'><a style='text-decoration:None;color:white;'href="userborrow.php? b_id=<?php echo $book_id; ?>" >Borrow</a></button></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="4">No Record Found</td>
</tr>
<?php
}
}
/*------------author name----------------------------- */
/*------------publisher name----------------------------- */
if(isset($_GET['search_by_publ']))
{
$filtervalues = $_GET['search_by_publ'];
$query = "SELECT a1.name AS author_1, a2.name AS author_2, a3.name AS author_3,book_id,book_name,publisher_name,published_year,rack_type,edition,available_copies,availability FROM book AS b INNER JOIN publisher on b.publisher_id=publisher.publisher_id INNER JOIN rack on b.rack_id=rack.rack_id LEFT JOIN author AS a1 ON b.author1 = a1.author_id LEFT JOIN author AS a2 ON b.author2 = a2.author_id LEFT JOIN author AS a3 ON b.author3 = a3.author_id WHERE publisher_name LIKE '%$filtervalues%'";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) > 0)
{
foreach($query_run as $items)
{
?>
<tr>
<?$_SESSION["book_id"] = $items['book_id'];?>
<td><?= $items['book_id']; ?></td>
<td><?= $items['book_name']; ?></td>
<td><?= $items['author_1']; ?></td>
<!--
<td>$items['author_2']; </td>
<td> $items['author_3'];</td>-->
<td><?= $items['publisher_name']; ?></td>
<td><?= $items['published_year']; ?></td>
<td><?= $items['edition']; ?></td>
<td><?= $items['available_copies']; ?></td>
<td><?= $items['rack_type']; ?></td>
<td><?= $items['availability']; ?></td>
<?php $book_id = intval( $items['book_id']); ?>
<td><button class='btn btn-success'><a style='text-decoration:None;color:white;' href="userborrow.php? b_id=<?php echo $book_id; ?>" >Borrow</a></button></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="4">No Record Found</td>
</tr>
<?php
}
}
/*------------publisher name----------------------------- */
/*------------type name----------------------------- */
if(isset($_GET['search_by_type']))
{
$filtervalues = $_GET['search_by_type'];
$query = "SELECT a1.name AS author_1, a2.name AS author_2, a3.name AS author_3,book_id,book_name,publisher_name,published_year,rack_type,edition,available_copies,availability FROM book AS b INNER JOIN publisher on b.publisher_id=publisher.publisher_id INNER JOIN rack on b.rack_id=rack.rack_id LEFT JOIN author AS a1 ON b.author1 = a1.author_id LEFT JOIN author AS a2 ON b.author2 = a2.author_id LEFT JOIN author AS a3 ON b.author3 = a3.author_id WHERE rack_type LIKE '%$filtervalues%'";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) > 0)
{
foreach($query_run as $items)
{
?>
<tr>
<?$_SESSION["book_id"] = $items['book_id'];?>
<td><?= $items['book_id']; ?></td>
<td><?= $items['book_name']; ?></td>
<td><?= $items['author_1']; ?></td>
<!--
<td>$items['author_2']; </td>
<td> $items['author_3'];</td>-->
<td><?= $items['publisher_name']; ?></td>
<td><?= $items['published_year']; ?></td>
<td><?= $items['edition']; ?></td>
<td><?= $items['available_copies']; ?></td>
<td><?= $items['rack_type']; ?></td>
<td><?= $items['availability']; ?></td>
<?php $book_id = intval( $items['book_id']); ?>
<td><button class='btn btn-success'><a style='text-decoration:None;color:white;'href="userborrow.php? b_id=<?php echo $book_id; ?>" >Borrow</a></button></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="4">No Record Found</td>
</tr>
<?php
}
}
/*------------type name----------------------------- */
?>
</tbody>
</table></div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
// Set session variables
?>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
<?php
include("templates/footer.php");
?>