-
Notifications
You must be signed in to change notification settings - Fork 1
/
book_list.php
477 lines (448 loc) · 15.4 KB
/
book_list.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<?php
/****************************
* File Name: book_list.php *
* Author: Ammar S.A.A *
* Output: List of books *
****************************/
require('config.php');
require(WEBSITE_PATH.'./includes/db_connection.php');
require(WEBSITE_PATH.'./includes/session.php');
include(WEBSITE_PATH.'./includes/header.php');
include(WEBSITE_PATH.'./includes/logo.php');
include(WEBSITE_PATH.'./includes/menu.php');
//Get things out from session if user
if (IfIsUser($conn)) {
$sql_select = "SELECT * FROM tblusers WHERE user_name = '{$_SESSION['user_name']}' ";
$result = $conn->query($sql_select);
if($result) {
$row = $result->fetch_assoc();
$user_id = $row['id'];
$full_name = $row['full_name'];
}
}
//Get things out from session if admin
else{
$sql_select = "SELECT * FROM admin WHERE user_name = '{$_SESSION['user_name']}' ";
$result = $conn->query($sql_select);
if($result) {
$row = $result->fetch_assoc();
$user_id = $row['id'];
}
}
$action='';
if(isset($_GET['action']) && isset($_GET['id']))
{
$action = $_GET['action'];
$id = $_GET['id'];
$sql = "SELECT * FROM tblbooks WHERE id={$id}";
$result = $conn->query($sql);
if($result && $result->num_rows > 0)
{
$row = $result->fetch_assoc();
$id = $row['id'];
$book_pic = $row['book_pic'];
$book_online = $row['book_online'];
$book_name = $row['book_name'];
$book_name_urdu = $row['book_name_urdu'];
$cat_id = $row['cat_id'];
$author_id = $row['author_id'];
$isbn_no = $row['isbn_number'];
$price = $row['book_price'];
$reg_date = $row['reg_date'];
$updation_date = $row['updation_date'];
$status = $row['status'];
}
}
switch ($action) {
//If requests a book
case 'request':
$sql = "INSERT INTO `tblissuedbooksdetail`(
`book_id`,
`user_id`,
`return_status`
)
VALUES(
{$id},
{$user_id},
3
)";
$result = $conn->query($sql);
if($result)
{
$msg = "<div class='alert alert-success'>Book named,<strong>".$book_name."</strong> is Requested Succcessfully for you(<b>".$full_name."</b>).</div>";
}
else{
$msg = "<div class='alert alert-danger'>Opss!Book named,<b>".$book_name."</b> is Not Requested Successfully, Please Try Again.</div>";
}
break;
//If deletes a book
case 'delete':
$sql = "DELETE FROM tblbooks WHERE id={$id}";
$result = $conn->query($sql);
if($result)
{
$msg = "<div class='alert alert-success'>Record Deleted Successfully.</div>";
}
else{
$msg = "<div class='alert alert-danger'>Record Not Deleted Successfully.</div>";
}
break;
//If read's online a book
case 'online':
$sql = "SELECT `book_online` FROM `tblbooks` WHERE id={$id} AND (status=1 OR 5)";
$result = $conn->query($sql);
if ($result && $result->num_rows > 0){
$row = $result->fetch_assoc();
$id = $row['id'];
$book_pic = $row['book_pic'];
$book_online = $row['book_online'];
$book_name = $row['book_name'];
$book_name_urdu = $row['book_name_urdu'];
$cat_id = $row['cat_id'];
$author_id = $row['author_id'];
$isbn_no = $row['isbn_number'];
$price = $row['book_price'];
redirect("./files/book/".$book_online);
}
else{
$msg = "<div class='alert alert-danger text-capitalize'>not available for online reading.</div>";
}
break;
}
//Get Author ID & will output the books from that author_id (ENGLISH)
if (isset($_GET['author_id'])){
$author_id = $_GET['author_id'];
$sql = "SELECT
tblbooks.id,
tblbooks.book_pic,
tblbooks.book_online,
tblbooks.book_name,
tblbooks.book_name_urdu,
tblcategory.category_name,
tblauthors.author_name,
tblbooks.isbn_number,
tblbooks.book_price,
tblbooks.status,#tblissuedbooksdetail.return_status,
tblbooks.reg_date,
tblbooks.updation_date
FROM
tblbooks
INNER JOIN tblcategory ON tblbooks.cat_id=tblcategory.id
INNER JOIN tblauthors ON tblbooks.author_id=tblauthors.id
#INNER JOIN tblissuedbooksdetail ON tblbooks.status=tblissuedbooksdetail.id
WHERE author_id={$author_id}
ORDER BY id DESC";
}//Get Author ID & will output the books from that author_id_urdu (URDU)
elseif (isset($_GET['author_id_urdu'])){
$author_id = $_GET['author_id_urdu'];
$sql = "SELECT
tblbooks.id,
tblbooks.book_pic,
tblbooks.book_online,
tblbooks.book_name,
tblbooks.book_name_urdu,
tblcategory.category_name,
tblauthors.author_name_urdu,
tblbooks.isbn_number,
tblbooks.book_price,
tblbooks.status,#tblissuedbooksdetail.return_status,
tblbooks.reg_date,
tblbooks.updation_date
FROM
tblbooks
INNER JOIN tblcategory ON tblbooks.cat_id=tblcategory.id
INNER JOIN tblauthors ON tblbooks.author_id=tblauthors.id
#INNER JOIN tblissuedbooksdetail ON tblbooks.status=tblissuedbooksdetail.id
WHERE author_id={$author_id}
ORDER BY id DESC";
}//Get Category ID & will output the books from that cat_id
elseif (isset($_GET['cat_id'])){
$cat_id = $_GET['cat_id'];
$sql = "SELECT
tblbooks.id,
tblbooks.book_pic,
tblbooks.book_online,
tblbooks.book_name,
tblbooks.book_name_urdu,
tblcategory.category_name,
tblauthors.author_name,
tblbooks.isbn_number,
tblbooks.book_price,
tblbooks.status,#tblissuedbooksdetail.return_status,
tblbooks.reg_date,
tblbooks.updation_date
FROM
tblbooks
INNER JOIN tblcategory ON tblbooks.cat_id=tblcategory.id
INNER JOIN tblauthors ON tblbooks.author_id=tblauthors.id
#INNER JOIN tblissuedbooksdetail ON tblbooks.status=tblissuedbooksdetail.id
WHERE cat_id={$cat_id}
ORDER BY id DESC";
}else{
$sql = "SELECT
tblbooks.id,
tblbooks.book_pic,
tblbooks.book_online,
tblbooks.book_name,
tblbooks.book_name_urdu,
tblcategory.category_name,
tblauthors.author_name,
tblbooks.isbn_number,
tblbooks.book_price,
tblbooks.status,#tblissuedbooksdetail.return_status,
tblbooks.reg_date,
tblbooks.updation_date
FROM
tblbooks
INNER JOIN tblcategory ON tblbooks.cat_id=tblcategory.id
INNER JOIN tblauthors ON tblbooks.author_id=tblauthors.id
#INNER JOIN tblissuedbooksdetail ON tblbooks.status=tblissuedbooksdetail.id
ORDER BY id DESC";
}
if(isset($_POST['search']) && !empty($_POST['search'])){
$search = trim($_POST['search']);
$sql="SELECT
tblbooks.id,
tblbooks.book_pic,
tblbooks.book_online,
tblbooks.book_name,
tblbooks.book_name_urdu,
tblcategory.category_name,
tblauthors.author_name,
tblbooks.isbn_number,
tblbooks.book_price,
tblbooks.status,#tblissuedbooksdetail.return_status,
tblbooks.reg_date,
tblbooks.updation_date
FROM
tblbooks
INNER JOIN tblcategory ON tblbooks.cat_id=tblcategory.id
INNER JOIN tblauthors ON tblbooks.author_id=tblauthors.id
#INNER JOIN tblissuedbooksdetail ON tblbooks.status=tblissuedbooksdetail.id
WHERE book_name LIKE '%{$search}%'
OR book_name_urdu LIKE '%{$search}%'
OR author_name LIKE '%{$search}%'
OR category_name LIKE '%{$search}%'
OR tblbooks.status LIKE '%{$search}%'
ORDER BY id DESC";
}
$result = $conn->query($sql);
if (isset($msg))
{
echo $msg;
}
?>
<section id="content">
<div class="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col md-8 lg-10 sm-6">
<!--Search Nav Start-->
<nav class="navbar navbar-light default-color bg-transparent nav justify-content-between">
<a class="navbar-brand" href="book_list.php">Book List</a>
<!--Search Form Start-->
<form class="form-inline form-responsive my-0 form-inline bg-transparent" method="POST">
<div class="md-form form-sm my-0">
<input type="text" class="form-control" name="search" placeholder="Search..." />
<button class="btn btn-sm my-0 btn-transparent" type="submit">
<i class="material-icons">search</i>
</button>
</div>
</form>
<!--Search Form End-->
<?php if (IfIsUser($conn)) {?>
<?php } else { ?>
<a class="btn btn-outline-primary" href="<?php echo WEBSITE_URL. 'book_add.php' ?>" role="button">Add New</a>
<?php } ?>
</nav>
<!--Search Nav End-->
</div>
</div>
<div class="row">
<div class="table-responsive">
<table class="table table-hover table-condensed table-striped">
<thead class="thead thead-light">
<tr>
<th class="text-nowrap">ID</th>
<th class="text-nowrap">Book Picture</th>
<th class="text-nowrap">Book Name</th>
<th class="urdu text-nowrap">کتاب کا نام</th>
<th class="text-nowrap">Category</th>
<th class="text-nowrap
<?php
if (isset($_GET['author_id_urdu'])) {
$author_id_urdu = $_GET['author_id_urdu'];
}else{
$author_id_urdu = '';
}
if ($author_id_urdu) { echo " urdu"; }
?>"
><?php if ($author_id_urdu) { echo "مصنف کا نام"; }else{ echo "Author"; } ?></th>
<th class="text-nowrap">ISBN No.</th>
<th class="text-nowrap">Price</th>
<th class="text-nowrap">Status</th>
<?php if (IfIsUser($conn)) { } else { ?>
<th class="text-nowrap">Reg. Date</th>
<th class="text-nowrap">Updt. Date</th>
<?php } ?>
<?php if (IfIsUser($conn)) { ?>
<th colspan="2" class="text-nowrap">Action</th>
<?php } else { ?>
<th colspan="3" class="text-nowrap">Action</th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php
if ($result){
foreach ($result as $row) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td class="img">
<?php
if(empty($row['book_pic']))
{
echo "<p class='initialism text-center'>Picture <b>Not</b> <br />Available</p>";
}
else{
echo "<img width='55in' class='img-responsive' src='".WEBSITE_URL."./images/book_pic/".$row['book_pic']."'/>";
}
?>
</td>
<td><?php echo $row['book_name']; ?></td>
<td class="urdu"><?php echo $row['book_name_urdu']; ?></td>
<td><?php echo $row['category_name']; ?></td>
<td <?php if ($author_id_urdu) { echo "class='urdu'"; } ?>>
<?php
if (!$author_id_urdu) {
echo $row['author_name'];
}else{
echo $row['author_name_urdu'];
}
?>
</td>
<td><?php echo $row['isbn_number']; ?></td>
<td><?php echo $row['book_price']; ?></td>
<td><?php echo GetReturnStatus($row['status']); ?></td>
<?php if (IfIsUser($conn)) { } else { ?>
<td><?php echo $row['reg_date']; ?></td>
<td><?php echo $row['updation_date']; ?></td>
<?php } ?>
<?php if (IfIsUser($conn)) {?>
<td>
<button role="button" class="btn btn-warning btn-sm">
<a class="" href="<?php echo WEBSITE_URL.'book_list.php?action=request&id='.$row['id']; ?>">
<i class="fa fa-envelope fa-2x"></i>
</a>
</button>
</td>
<?php if (isset($row['book_online'])) {?>
<td>
<button role="button" class="btn btn-info btn-sm">
<a class="" href="<?php echo WEBSITE_URL.'book_list.php?action=online&id='.$row['id']; ?>">
<i class="fa fa-eye fa-2x"></i>
</a>
</button>
</td>
<?php }else{ ?>
<td>
<button role="button" class="btn btn-info btn-sm">
<a class="" href="<?php echo WEBSITE_URL.'book_list.php?action=online&id=#'; ?>">
<i class="fa fa-eye-slash fa-2x"></i>
</a>
</button>
</td>
<?php }} else { ?>
<td>
<button role="button" class="btn btn-warning btn-sm">
<a href="<?php echo WEBSITE_URL. 'book_add.php?id='.$row['id']; ?> ">
<i class="display-5 glyphicon glyphicon-edit"></i>
</a>
</button>
</td>
<td>
<button class="btn btn-danger btn-sm" onclick="delete_confirm(<?php echo $row["id"]; ?>)" >
<i class="display-5 glyphicon glyphicon-trash"></i>
</button>
</td>
<?php if (isset($row['book_online'])) {?>
<td>
<button role="button" class="btn btn-info btn-sm">
<a class="" href="<?php echo WEBSITE_URL.'book_list.php?action=online&id='.$row['id']; ?>">
<i class="display-5 glyphicon glyphicon-eye-open"></i>
</a>
</button>
</td>
<?php }else{ ?>
<td>
<button role="button" class="btn btn-info btn-sm">
<a class="" href="<?php echo WEBSITE_URL.'book_list.php?action=online&id=#'; ?>">
<i class="display-5 glyphicon glyphicon-eye-close"></i>
</a>
</button>
</td>
<?php }} ?>
</tr>
<?php }
}else{
echo "<tr><td colspan='11'><p>No record found for <b>{$search}</b></p></td></tr>";
}
?>
</tbody>
</table>
<div>
<p>
<?php
if (isset($search)) {
GetTotalSearchResult($conn,$result,$search);
}elseif (isset($_GET['author_id'])) {
$author_id = $_GET['author_id'];
$total_books = GetTotalWhere($conn, TBLBOOKS, 'author_id', $author_id);
echo "Showing total <b>".$total_books."</b> of <b>".$total_books."</b> ";
if ($total_books > 1) {
echo "results.";
}else{ echo "result.";}
}elseif ($author_id_urdu) {
$total_books = GetTotalWhere($conn, TBLBOOKS, 'author_id', $author_id_urdu);
echo "Showing total <b>".$total_books."</b> of <b>".$total_books."</b> ";
if ($total_books > 1) {
echo "results.";
}else{ echo "result.";}
}elseif (isset($_GET['cat_id'])) {
$cat_id = $_GET['cat_id'];
$total_books = GetTotalWhere($conn, TBLBOOKS, 'cat_id', $cat_id);
echo "Showing total <b>".$total_books."</b> of <b>".$total_books."</b> ";
if ($total_books > 1) {
echo "results.";
}else{ echo "result.";}
}else{
$total_books = GetTotal($conn, TBLBOOKS);
echo "Showing total <b>".$total_books."</b> of <b>".$total_books."</b> ";
if ($total_books > 1) {
echo "results.";
}else{ echo "result.";}
}
?>
</p>
</div>
</div>
</div>
<br />
</div>
</div>
</section>
</div>
</div>
<script>
function delete_confirm(id) {
var txt;
if (confirm("Are you sure? you want to delete this record.Remember: It can't be recovered.")) {
window.location.href = "<?php echo WEBSITE_URL. 'book_list.php?action=delete&id=' ?>"+id;
}
header("location:<?php echo WEBSITE_URL. 'book_list.php' ?>");
}
</script>
<?php
include(WEBSITE_PATH.'./includes/footer.php');
?>