forked from TharunKumarReddyPolu/Librarian-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tab.php
599 lines (540 loc) · 12.8 KB
/
tab.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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<?php
session_start();
if(!isset($_SESSION['loggedin']) || $_SESSION['loggedin']!=true){
header("location: index.php");
exit;
}
require 'librarian-nav.php' ;
?>
<style >
.active{
background-color: var(--bg-color);
}
.active3{
background-color: var(--first-color);
}
.active1{
background-color: var(--bg-color);
}
.active2{
background-color: var(--bg-color);
}
.active4{
background-color: var(--bg-color);
}
</style>
<?php
$showAlert = false;
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "librarianbot";
$valueToSearch = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['bookinsert'])){
$bookname = $_POST["BookName"];
$bookid = $_POST["BookId"];
$bookcode = $_POST["BarCode"];
$custody="Librarian";
$sql1 = "INSERT INTO books (BookId,BookName,BarCode,Custody) VALUES ('$bookid','$bookname','$bookcode','$custody')";
$result = mysqli_query($conn, $sql1);
if ($result){
$showAlert = true;
}
}
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `books` WHERE CONCAT(`BookId`, `BookName`, `Custody`, `DateOfLent`) LIKE '%".$valueToSearch."%'";
$result = mysqli_query($conn, $query);
}
else {
$query = "SELECT * FROM `books`";
$result = mysqli_query($conn, $query);
}
$result = $conn->query($query);
// output data of each row
?>
<style>
* {
font-family: sans-serif; /* Change your font family */
}
body{
background: #ffffff;
padding: 0 0px;
}
.content-table {
border-collapse: collapse;
margin: 50px 10%;
font-size: 1em;
border-radius: 15px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
width:85%;
}
.content-table thead tr {
background-color: #12192C;
color: #ffffff;
text-align: left;
font-weight: bold;
padding:40px 10px;
}
.content-table tbody tr:hover {
background-color: #f3f3f3;
color: #000000;
text-align: left;
padding:40px 10px;
}
.content-table thead tr th{
padding:15px 15px 10px 10px;
}
.one{
width:100px;
}
.two{
width:80px;
}
.content-table th,
.content-table td {
padding: 17px 10px;
}
.content-table tbody tr {
border-bottom: 1px solid #dddddd;
}
.content-table tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
.content-table tbody tr:last-of-type {
border-bottom: 2px solid #12192C;
}
.content-table tbody tr.active-row {
font-weight: bold;
color: #12192C;
}
.button {
border-radius: 7px;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 15px;
padding: 10px 10px;
width: 50px;
transition: all 0.5s;
cursor: pointer;
margin-right: 0px;
margin-left:0px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}
.button1 {
background-color: #0C5DF4;
}
.button2 {
background-color: #FF1212;
}
.button3 {
background-color: #ffd500;
color:#000000;
}
.due{
background-color:#ff0000;
}
.nodue{
background-color:#00ff00;
}
.wrapper{
max-width: 500px;
width: 100%;
background: #fff;
border-radius:10px;
margin: 20px auto;
box-shadow: 1px 1px 2px rgba(0,0,0,0.5);
padding: 30px;
border:1px solid #000000;
}
.wrapper .title{
font-size: 24px;
font-weight: 700;
margin-bottom: 25px;
color: #566573;
text-transform: uppercase;
text-align: center;
}
.wrapper .form{
width: 100%;
}
.wrapper .form .inputfield{
margin-bottom: 15px;
display: flex;
align-items: center;
}
.wrapper .form .inputfield label{
width: 200px;
color: #566573;
margin-right: 10px;
font-size: 14px;
}
.wrapper .form .inputfield .input,
.wrapper .form .inputfield .textarea{
width: 100%;
outline: none;
border: 1px solid #d5dbd9;
font-size: 15px;
padding: 8px 10px;
border-radius: 3px;
transition: all 0.3s ease;
}
.wrapper .form .inputfield .textarea{
width: 100%;
height: 125px;
resize: none;
}
.wrapper .form .inputfield .custom_select{
position: relative;
width: 100%;
height: 37px;
}
.wrapper .form .inputfield .custom_select:before{
content: "";
position: absolute;
top: 12px;
right: 10px;
border: 8px solid;
border-color: #566573 transparent transparent transparent;
pointer-events: none;
}
.wrapper .form .inputfield .custom_select select{
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: none;
width: 100%;
height: 100%;
border: 0px;
padding: 8px 10px;
font-size: 15px;
border: 1px solid #566573;
border-radius: 3px;
}
.wrapper .form .inputfield .input:focus,
.wrapper .form .inputfield .textarea:focus,
.wrapper .form .inputfield .custom_select select:focus{
border: 1px solid #566573;
}
.wrapper .form .inputfield p{
font-size: 14px;
color: #757575;
}
.wrapper .form .inputfield .check{
width: 15px;
height: 15px;
position: relative;
display: block;
cursor: pointer;
}
.wrapper .form .inputfield .check input[type="checkbox"]{
position: absolute;
top: 0;
left: 0;
opacity: 0;
}
.wrapper .form .inputfield .check .checkmark{
width: 15px;
height: 15px;
border: 1px solid #566573;
display: block;
position: relative;
}
.wrapper .form .inputfield .check .checkmark:before{
content: "";
position: absolute;
top: 1px;
left: 2px;
width: 5px;
height: 2px;
border: 2px solid;
border-color: transparent transparent #fff #fff;
transform: rotate(-45deg);
color:#566573;
display: none;
}
.wrapper .form .inputfield .check input[type="checkbox"]:checked ~ .checkmark{
background: #566573;
}
.wrapper .form .inputfield .check input[type="checkbox"]:checked ~ .checkmark:before{
display: block;
color:#566573;
}
.wrapper .form .inputfield .btn{
width: 100%;
padding: 8px 10px;
font-size: 15px;
border: 2px solid #2E4053;
background: #12192C;
color: #fff;
cursor: pointer;
border-radius: 3px;
outline: none;
}
.wrapper .form .inputfield .btn:hover{
background: #12192C ;
border: 2px solid #2E4053;
}
.wrapper .form .inputfield:last-child{
margin-bottom: 0;
}
@media (max-width:420px) {
.wrapper .form .inputfield{
flex-direction: column;
align-items: flex-start;
}
.wrapper .form .inputfield label{
margin-bottom: 5px;
}
.wrapper .form .inputfield.terms{
flex-direction: row;
}
}
.alert {
padding: 20px;
background-color: #f44336; /* Red */
color: white;
margin-bottom: 15px;
margin-left:80px;
}
.green{
background-color: #27AE60;
color: black;
}
/* The close button */
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
/* When moving the mouse over the close button */
.closebtn:hover {
color: black;
}
.regbtn{
width: 100%;
padding: 8px 10px;
font-size: 15px;
border: 2px solid #2E4053;
background: #ffffff;
color: #2E4053;
cursor: pointer;
border-radius: 3px;
outline: none;
text-align:center;
text-decoration:none;
}
.regbtn:hover{
width: 100%;
padding: 8px 10px;
font-size: 15px;
border: 2px solid #2E4053;
background: #2E4053;
color: #ffffff;
cursor: pointer;
border-radius: 3px;
outline: none;
text-align:center;
}
.alert {
padding: 20px;
background-color: #f44336; /* Red */
color: white;
margin-bottom: 15px;
}
.green{
background-color: #27AE60;
color: black;
}
/* The close button */
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
/* When moving the mouse over the close button */
.closebtn:hover {
color: black;
}
.search{
background-color: #0C5DF4;
height:45px;
border-radius:50%;
margin-top:50px;
border: 0px;
}
.searchbar[type=text] {
margin-top:50px;
margin-left:70%;
margin-right:10px;
margin-bottom:50px;
position:block;
width: 250px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 18px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 11px 20px 11px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
</style>
<html>
<?php
if($showAlert){ ?>
<div class="alert green">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
BOOK INSERTED!
</div>
<?php ;
}
?>
<div class="wrapper">
<form action="tab.php" method="POST">
<div class="title">
ADD BOOK
</div>
<div class="form">
<div class="inputfield">
<label>BOOK ID</label>
<input type="text" class="input" name="BookId" required>
</div>
<div class="inputfield">
<label>BOOK NAME</label>
<input type="text" class="input" name="BookName" required>
</div>
<div class="inputfield">
<label>BAR CODE</label>
<input type="text" class="input" name="BarCode" required>
</div>
<div class="inputfield">
<input type="submit" name="bookinsert" value="ADD BOOK" class="btn">
</div>
</div>
</form>
</div>
<form action="tab.php" method="post">
<div>
<input class="searchbar" type="text" name="valueToSearch" placeholder="Search..." value="<?php echo $valueToSearch ;?>" style="float:left;">
<button type="submit" method="POST" name="search" class="button search" style="float:left;"><ion-icon name="search" class="nav__icon"></button>
</div>
</form>
<table class="content-table">
<thead>
<tr>
<th>Book Id</th>
<th>Book Name</th>
<th>Custody</th>
<th>Date Of Lent</th>
<th>Days</th>
<th>Date of submission</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
while($row = $result->fetch_assoc()) {
$fine_per_day = 3;
$to_date = time();
$total_fine = 0;
//echo $to_date;
$from_date = strtotime($row['DateOfLent']);
$day_diff = $to_date - $from_date;
$fine_days = floor($day_diff/(60*60*24));
$Total_days = $fine_days;
if($fine_days>15){
$fine_days = $fine_days - 15;
$total_fine = $fine_days * $fine_per_day;
}
else{
$total_fine = 0;
}
if($Total_days<0)
{
$Total_days=0;
}
?>
<tr>
<td><?php echo $row['BookId']; ?></td>
<td><?php echo $row['BookName']; ?></td>
<td><?php echo $row['Custody']; ?></td>
<td><?php echo date('Y-m-d', strtotime($row['DateOfLent'])); ?></td>
<?php if($row['Custody']!="Librarian"){
?>
<td><?php echo $Total_days; ?></td>
<td><?php echo date('Y-m-d', strtotime($row['DateOfLent']."+15 day")); ?></td>
<?php if($Total_days>15){ ?>
<td><div class="button button1 due" ><ion-icon name="logo-usd" class="nav__icon"><div> </td>
<?php }
else{ ?>
<td><div class="button button1 nodue"><ion-icon name="checkmark-done-sharp" class="nav__icon"><div> </td>
<?php }
?>
<?php }
else {
?>
<td>-</td>
<td>-</td>
<td><div class="button button1 nodue"><ion-icon name="checkmark-done-sharp" class="nav__icon"><div> </td>
<?php
}
?>
</tr>
<?php
}
if ($result->num_rows == 0) {
?>
<tr>
<td><?php echo "0 results"; ?></td>
</tr>
<?php
}
$conn->close();
?>
</tbody>
</table>
</html>
<script>
function confirm(a)
{
var txt;
var person = prompt("Please enter your rollnumber:");
if (person == a)
{
alert ("ARE YOU SURE TO DELETE RECORD '"+a+" '");
return true;
} else
{
alert ("You entered wrong rollnumber");
return false;
}
}
</script>
<script src="https://unpkg.com/[email protected]/dist/ionicons.js"></script>