-
Notifications
You must be signed in to change notification settings - Fork 1
/
issuedbooks_list.php
504 lines (486 loc) · 18.7 KB
/
issuedbooks_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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
<?php
/************************************
* File Name: issuedbooks_list.php *
* Author: Ammar S.A.A *
* Output: List of issued 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');
//Delete Query
if(isset($_GET['action']) && isset($_GET['id']))
{
$id = $_GET['id'];
$sql = "DELETE FROM tblissuedbooksdetail WHERE id={$id}";
$result = $conn->query($sql);
if($result)
{
$msg = "<div class='alert alert-success text-capitalize'>";
$msg .= " <b><u>Record Deleted Successfully</u></b>,";
$msg .= " To view <b>Total Books Returned</b> click/tap <a href='issuedbooks_list.php?action=returned'>HERE</a>," ;
$msg .= " if you want To view <b>Total Books Requested</b> click/tap <a href='issuedbooks_list.php?action=requested'>HERE</a>,";
$msg .= " if you want To view <b>Total Books Issued</b> click/tap <a href='issuedbooks_list.php?action=issued'>HERE</a> or" ;
$msg .= " if you want To view <b>Total Books Issued & Returned</b> click/tap <a href='issuedbooks_list.php'>HERE</a>.";
$msg .= "</div>";
}
else{
$msg = "<div class='alert alert-danger'>Record Not Deleted Successfully.</div>";
}
}
//Getting things out from session query
$sql_select = "SELECT * FROM tblusers WHERE user_name = '{$_SESSION['user_name']}' ";
$sql = $conn->query($sql_select);
while($row = mysqli_fetch_array($sql)) {
$user_id = $row['id'];
$full_name = $row['full_name'];
$email_id = $row['email_id'];
$user_name = $row['user_name'];
$password = $row['password'];
$mobile_no = $row['mobile_no'];
$status = $row['status'];
$profile_picture = $row['profile_picture'];
$reg_date = $row['reg_date'];
$updation_date = $row['updation_date'];
}
if (isset($_GET['action'])) {
$action = $_GET['action'];
}else{
$action='';
}
switch ($action) {
//If get $action with value issued
case 'issued':
if (IfIsUser($conn)){
$sql = "SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
WHERE return_status = 0 AND user_id ={$user_id}
ORDER BY id DESC";
}else{
$sql = "SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
WHERE return_status = 0
ORDER BY id DESC";
}
break;
//If get $action with value returned
case 'returned':
if (IfIsUser($conn)){
$sql = "SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
WHERE return_status = 1 AND user_id ={$user_id}
ORDER BY id DESC";
}else{
$sql = "SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
WHERE return_status = 1
ORDER BY id DESC";
}
break;
//If get $action with value requested
case 'requested':
if (IfIsUser($conn)){
$sql = "SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
WHERE return_status = 3 AND user_id ={$user_id}
ORDER BY id DESC";
}else{
$sql = "SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
WHERE return_status = 3
ORDER BY id DESC";
}
break;
//If get $action
default:
if (IfIsUser($conn)){
$sql="SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
WHERE user_id ={$user_id}
ORDER BY id DESC";
}else{
$sql = "SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
ORDER BY id DESC";
}
}
if(isset($_POST['search']) && !empty($_POST['search'])){
$search = trim($_POST['search']);
$sql="SELECT
tblissuedbooksdetail.id,
tblbooks.book_name,
tblusers.full_name,
tblissuedbooksdetail.issue_date,
tblissuedbooksdetail.due_date,
tblissuedbooksdetail.return_date,
tblissuedbooksdetail.return_status,
tblissuedbooksdetail.day_fine,
tblissuedbooksdetail.damagepage_fine,
tblissuedbooksdetail.extra_fine,
tblissuedbooksdetail.total_fine,
tblissuedbooksdetail.comments
FROM
tblissuedbooksdetail
INNER JOIN tblbooks ON tblissuedbooksdetail.book_id = tblbooks.id
INNER JOIN tblusers ON tblissuedbooksdetail.user_id = tblusers.id
WHERE book_name LIKE '%{$search}%'
OR full_name LIKE '%{$search}%'
OR return_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">
<?php if ($action == 'returned') { ?>
<a class="navbar-brand" href="issuedbooks_list.php?action=returned">Returned Books</a>
<?php } elseif ($action == 'issued') { ?>
<a class="navbar-brand" href="issuedbooks_list.php?action=issued">Issued Books</a>
<?php } elseif ($action == 'requested') { ?>
<a class="navbar-brand" href="issuedbooks_list.php?action=requested">Requested Books</a>
<?php }else{ ?>
<a class="navbar-brand" href="issuedbooks_list.php" title="Issued,Returned And Requested Books">IR&R Books</a>
<?php } ?>
<!--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)) {}else{ ?>
<a class="btn btn-outline-primary" href="issuebook.php" role="button">Issue Book</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 class="text-nowrap">
<?php if (!IfIsUser($conn)) { ?>
<th></th>
<?php } ?>
<th>ID</th>
<th>Book Name</th>
<th>Full Name</th>
<th>Issue Date</th>
<th>Due Date</th>
<th>Return Date</th>
<th>Status</th>
<th>Fine</th>
<th>Comments</th>
<?php if (IfIsUser($conn)) { if ($action == 'requested') {?>
<th>Action</th>
<?php }}else{ ?>
<th colspan="2">Action</th> <?php } ?>
</tr>
</thead>
<tbody>
<?php
if ($result){
foreach ($result as $row) {
?>
<tr>
<?php if (!IfIsUser($conn)) { ?>
<td>
<?php
if (isset($row['return_date'])) {
//If return date is greater then due date and fine == 0 echo warning
if ($row['return_date']>$row['due_date'] && $row['fine']==0) {
echo "<span class='text-danger spinner-border'></span>";
}//If return date is entered but status is issued echo warning
elseif (isset($row['return_date']) && $row['return_status']=='0') {
echo "<span class='text-danger spinner-grow'></span>";
}//If everything is ok echo glyphicon-ok
else{
echo "<span class='text-success glyphicon glyphicon-ok'></span>";
}
}elseif (isset($row['issue_date'])) {
//If book is requested echo warning
if (isset($row['issue_date']) && $row['return_status']=="3") {
echo "<span class='text-warning spinner-border'></span>";
}//If issue date is greater then due date echo warning
elseif ($row['issue_date']>$row['due_date']) {
echo "<span class='text-warning spinner-grow'></span>";
}//If Due Date is less then issue date echo warning
elseif ($row['due_date']<$row['issue_date']) {
echo "<span class='text-warning spinner-grow'></span>";
}//If everything is ok echo glyphicon-ok
else{
echo "<span class='text-success glyphicon glyphicon-ok'></span>";
}
}
?>
</td>
<?php } ?>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['book_name']; ?></td>
<td><?php echo $row['full_name']; ?></td>
<td><?php echo $row['issue_date']; ?></td>
<td><?php echo $row['due_date']; ?></td>
<td><?php echo $row['return_date']; ?></td>
<td><?php echo GetReturnStatus($row['return_status']); ?></td>
<td><?php echo $row['total_fine']." Rs."; ?></td>
<td><?php echo $row['comments']; ?></td>
<?php if (IfIsUser($conn)) { if ($action == 'requested') {?>
<td>
<button class="btn btn-danger btn-sm" onclick="delete_confirm(<?php echo $row["id"]; ?>)"><a><i class="display-5 glyphicon glyphicon-trash"></i></a></button>
</td>
<?php }}else{ ?>
<td>
<button class="btn btn-warning btn-sm"><a href="<?php echo WEBSITE_URL. 'issuebook.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"]; ?>)"><a><i class="display-5 glyphicon glyphicon-trash"></i></a></button>
</td>
<?php } ?>
</tr>
<?php }
}else{
if (IfIsUser($conn)) {
echo "<tr><td colspan='10'><p>No record found for <b>{$search}</b></p></td></tr>";
}else{
echo "<tr><td colspan='12'><p>No record found for <b>{$search}</b></p></td></tr>";
}
}
?>
</tbody>
<tfoot class="tfoot">
<tr>
<?php if (IfIsUser($conn)){ ?>
<td colspan='10'>
<?php }else{ ?>
<td colspan='12'>
<?php }
if (isset($search)) {
GetTotalSearchResult($conn,$result,$search);
}else{
if ($action == 'returned' && IfIsUser($conn)) {
$total_returnedbooks = GetTotalWhereAnd($conn, TBLISSUEDBOOKS, 'user_id', $user_id, 'return_status', '1');
echo "The total Books Returned are <b>".$total_returnedbooks."</b>.";
} elseif ($action == 'issued' && IfIsUser($conn)) {
$total_issuedbooks = GetTotalWhereAnd($conn,TBLISSUEDBOOKS, 'user_id', $user_id, 'return_status', '0');
echo "The total Books Issued are <b>".$total_issuedbooks."</b>.";
} elseif ($action == 'requested' && IfIsUser($conn)) {
$total_requestedbooks = GetTotalWhereAnd($conn,TBLISSUEDBOOKS, 'user_id', $user_id, 'return_status', '3');
echo "The total Books Requested are <b>".$total_requestedbooks."</b>.";
}//For Admin
elseif ($action == 'returned' && !IfIsUser($conn)) {
$total_returnedbooks = GetTotalWhere($conn, TBLISSUEDBOOKS, 'return_status', '1');
echo "The total Books Returned are <b>".$total_returnedbooks."</b>.";
} elseif ($action == 'issued' && !IfIsUser($conn)) {
$total_issuedbooks = GetTotalWhere($conn,TBLISSUEDBOOKS, 'return_status', '0');
echo "The total Books Issued are <b>".$total_issuedbooks."</b>.";
} elseif ($action == 'requested' && !IfIsUser($conn)) {
$total_requestedbooks = GetTotalWhere($conn,TBLISSUEDBOOKS, 'return_status', '3');
echo "The total Books Requested are <b>".$total_requestedbooks."</b>.";
}else{
$total_books = GetTotal($conn,TBLISSUEDBOOKS);
echo "Showing Total <b>".$total_books."</b> of <b>".$total_books."</b>";
if ($total_books > 1) {
echo " Rows.";
}else{ echo " Row.";}
}
}
?>
</td>
</tr>
<tr>
<?php if (IfIsUser($conn)) { if ($action == 'requested') {?>
<td colspan="10">
<i><strong>Note:</strong>If You have requested multiple books, you can only be issued the one which is requested first.</i>
</td>
<?php }} ?>
</tr>
</tfoot>
</table>
</div>
<div class="col-md-6">
<table class="table table-condensed table-hover table-dark">
<thead class="thead thead-light">
<tr>
<td colspan="2" class="text-center"><strong>Key</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td><span class='text-success glyphicon glyphicon-ok'></span></td>
<td class="text-capitalize">Everything is OK.</td>
</tr>
<tr>
<td><span class='text-warning spinner-border'></span></td>
<td class="text-capitalize">Book is Requested And waiting to be issued.</td>
</tr>
<tr>
<td><span class='text-danger spinner-border'></span></td>
<td class="text-capitalize">Fine needs to be calculated.</td>
</tr>
<tr>
<td><span class='text-danger spinner-grow'></span></td>
<td class="text-capitalize">Status needs to be corrected.</td>
</tr>
<tr>
<td><span class='text-warning spinner-grow'></span></td>
<td class="text-capitalize">Something is wrong with dates( issue date or due date).</td>
</tr>
<tr>
<td class="text-capitalize" colspan="2">Note: Not <span class='text-success glyphicon glyphicon-ok'></span> data can cause abnormal results.</td>
</tr>
</tbody>
</table>
</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.")) {
window.location.href = "<?php echo WEBSITE_URL. 'issuedbooks_list.php?action=delete&id=' ?>"+id;
}
}
</script>
<?php
include(WEBSITE_PATH.'./includes/footer.php');
?>