-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5data_class.php
597 lines (508 loc) · 22 KB
/
5data_class.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
<?php include "4db.php";
session_start();
class data extends db{
private $bookauthor;
private $bookdetail;
private $bookname;
private $bookpic;
private $bookprice;
private $bookpub;
private $bookquantity;
private $book;
private $user;
private $days;
private $date;
private $returnDate;
/*function search(){
$search_keyword = '';
if(!empty($_POST['search']['keyword'])) {
$search_keyword = $_POST['search']['keyword'];
}
//$sql= 'SELECT * FROM user WHERE name LIKE :keyword OR email LIKE :keyword OR type LIKE :keyword ORDER BY id DESC';
$sql='SELECT u.id,u.name,u.email,u.type,i.issuebook,i.issuedays,i.issuedate,i.issuereturn FROM user u INNER JOIN issuebook i ON u.id=i.userid WHERE u.name LIKE :keyword OR u.email LIKE :keyword OR u.type LIKE :keyword OR i.issuebook LIKE :keyword OR i.issuedays LIKE :keyword OR i.issuedate LIKE :keyword OR i.issuereturn LIKE :keyword ORDER BY id DESC';
// Pagination Code starts
$per_page_html = '';
$page = 1;
$start=0;
if(!empty($_POST["page"])) {
$page = $_POST["page"];
$start=($page-1) * 2;
}
$limit=" limit " . $start . "," . 2;
$pagination_statement = $this->connection->prepare($sql);
$pagination_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pagination_statement->execute();
$row_count = $pagination_statement->rowCount();
if(!empty($row_count)){
$per_page_html .= "<div style='text-align:center;margin:20px 0px;'>";
$page_count=ceil($row_count/2);
if($page_count>1) {
for($i=1;$i<=$page_count;$i++){
if($i==$page){
$per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page current" />';
} else {
$per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page" />';
}
}
}
$per_page_html .= "</div>";
}
$query = $sql.$limit;
$pdo_statement = $this->connection->prepare($query);
$pdo_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pdo_statement->execute();
$result = $pdo_statement->fetchAll();
return $result;
}
*/
/* function search1() {
$search_keyword = '';
if(!empty($_POST['search']['keyword'])) {
$search_keyword = $_POST['search']['keyword'];
}
$sql1= 'SELECT * FROM issuebook WHERE issuebook LIKE :keyword OR issuedays LIKE :keyword OR issuedate LIKE :keyword ORDER BY userid DESC';
$pdo_statement1 = $this->connection->prepare($sql1);
$pdo_statement1->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pdo_statement1->execute();
$result1 = $pdo_statement1->fetchAll();
return $result1;
} */
function userLogin($t1,$t2){
/* $q="SELECT * FROM user where email='$t1' and pass='$t2'";
$recordSet=$this->connection->query($q);
$result=$recordSet->rowCount();
if($result > 0){
foreach($recordSet->fetchAll() as $row){
$logid=$row['id'];
header("Location:6user_service_dashboard.php?userlogid=$logid");
}
}
else{
header("Location:1index.php?msg=Invalid Credentials");
} */
try{
$q="SELECT * FROM user where email=? and pass=?";
//echo $q;
//exit(1);
$recordSet=$this->connection->prepare($q);
$recordSet->bindParam(1,$t1);
$recordSet->bindParam(2,$t2);
$recordSet->execute();
$row=$recordSet->fetch(PDO::FETCH_ASSOC);
//$result=$recordSet->rowCount();
//if($result > 0){
//foreach($recordSet->fetchAll() as $row){
$logid=$row['id'];
$_SESSION["userid"]=$logid;
header("Location:6user_service_dashboard.php?userlogid=$logid");
//}
}
catch (PDOException $e)
{
header("Location:1index.php?msg=Invalid Credentials");
}
}
function userdetail($id){
$q="SELECT * FROM user where id='$id'";
$data=$this->connection->query($q);
return $data;
}
function bookissued($id){
$fine="";
$issueret="";
$q="SELECT * FROM issuebook where userid='$id'";
$recordset=$this->connection->query($q);
foreach($recordset as $row){
$issueret=$row['issuereturn'];
$fine=$row['fine'];
}
$date=date("d/m/y");
if($date>$issueret){
$q="UPDATE issuebook SET fine='$fine' where userid='$id'";
if($this->connection->exec($q)) {
$q="SELECT * FROM issuebook where userid='$id'";
$data=$this->connection->query($q);
return $data;
}
else{
$q="SELECT * FROM issuebook where userid='$id' ";
$data=$this->connection->query($q);
return $data;
}
}
else{
$q="SELECT * FROM issuebook where userid='$id'";
$data=$this->connection->query($q);
return $data;
}
}
function reqbook($userid,$bookid){
$q="SELECT * FROM book where id='$bookid'";
$recordset=$this->connection->query($q);
$q="SELECT * FROM user where id='$userid'";
$recordSet=$this->connection->query($q);
foreach($recordSet->fetchAll() as $row){
$user=$row['name'];
$type=$row['type'];
}
foreach($recordset->fetchAll() as $row){
$book=$row['bookname'];
if($type=="student"){
$days=7;
}
if($type=="teacher"){
$days=21;
}
}
$q="INSERT INTO requestbook (id,userid,bookid,username,usertype,bookname,issuedays)VALUES('', $userid, $bookid, $user, $type, $book, $days)";
if($this->connection->exec($q)){
header("Location:6user_service_dashboard.php?userlogid=$userid");
}
else
{
header("Location:6user_service_dashboard.php?msg=fail");
}
}
function returnbook($id){
$fine="";
$bookava="";
$issuebook="";
$bookrentel="";
$q="SELECT * FROM issuebook where id='$id'";
$recordSet=$this->connection->query($q);
foreach($recordSet->fetchAll() as $row) {
$userid=$row['userid'];
$issuebook=$row['issuebook'];
$fine=$row['fine'];
}
if($fine==0){
$q="SELECT * FROM book where bookname='$issuebook'";
$recordSet=$this->connection->query($q);
foreach($recordSet->fetchAll() as $row) {
$bookava=$row['bookava']+1;
$bookrentel=$row['bookrent']-1;
}
$q="UPDATE book SET bookava='$bookava', bookrent='$bookrentel' where bookname='$issuebook'";
$this->connection->exec($q);
$q="DELETE from issuebook where id=$id and issuebook='$issuebook' and fine='0' ";
if($this->connection->exec($q)){
header("Location:6user_service_dashboard.php?userlogid=$userid");
}
// else{
// header("Location:otheruser_dashboard.php?msg=fail");
// }
}
// if($fine!=0){
// header("Location:otheruser_dashboard.php?userlogid=$userid&msg=fine");
// }
}
//Admin
function adminLogin($t1,$t2){
try{
$q="SELECT * FROM admin where email=:em and pass=:ps";
//echo $q;
//exit(1);
$recordSet=$this->connection->prepare($q);
$recordSet->bindParam(':em',$t1);
$recordSet->bindParam(':ps',$t2);
$recordSet->execute();
$row=$recordSet->fetch(PDO::FETCH_ASSOC);
//$result=$recordSet->rowCount();
//if($result > 0){
//foreach($recordSet->fetchAll() as $row){
$logid=$row['id'];
$_SESSION["adminid"]=$logid;
header("Location:7admin_service_dashboard.php");
//}
}
catch (PDOException $e)
{
header("Location:1index.php?msg=Invalid Credentials");
}
}
function addperson($name,$email,$pass,$type){
$this->name=$name;
$this->email=$email;
$this->pass=$pass;
$this->type=$type;
$q="INSERT INTO user(id, name, email, pass, type)VALUES('', '$name', '$email', '$pass', '$type')";
if($this->connection->exec($q)){
header("Location:7admin_service_dashboard.php?msg=New person added");
}
else{
header ("Location:7admin_service_dashboard.php?msg=Registration failed");
}
}
function addbook($bookpic,$bookname,$bookdetail,$bookauthor,$bookpub,$branch,$bookprice,$bookquantity){
$this->$bookpic=$bookpic;
$this->bookname=$bookname;
$this->bookdetail=$bookdetail;
$this->bookauthor=$bookauthor;
$this->bookpub=$bookpub;
$this->branch=$branch;
$this->bookprice=$bookprice;
$this->bookquantity=$bookquantity;
$q="INSERT INTO book(id, bookpic, bookname, bookdetail, bookauthor, bookpub, branch, bookprice, bookquantity, bookava, bookrent)VALUES('', '$bookpic', '$bookname', '$bookdetail', '$bookauthor', '$bookpub', '$branch', '$bookprice', '$bookquantity', '$bookquantity', 0)";
if($this->connection->exec($q)){
header("Location:7admin_service_dashboard.php?msg=New Book Added");
}
else{
header("Location:7admin_service_dashboard.php?msg=Book Addition Failed");
}
}
function issuereport(){
$q="SELECT * FROM issuebook ORDER BY id DESC";
$data=$this->connection->query($q);
return $data;
}
function studentrecord(){
$q="SELECT * FROM user";
$data=$this->connection->query($q);
return $data;
}
function deleteuser($id){
$q="DELETE FROM user where id='$id'";
if($this->connection->exec($q)){
header("Location:7admin_service_dashboard.php?msg=done");
}
else{
header("Location:7admin_service_dashboard.php?msg=failed");
}
}
function deletebook($id){
$q="DELETE FROM book where id='$id'";
if($this->connection->exec($q)){
header("Location:7admin_service_dashboard.php?msg=done");
}
else{
header("Location:7admin_service_dashboard.php?msg=failed");
}
}
function bookrecord(){
$q="SELECT * FROM book";
$data=$this->connection->query($q);
return $data;
}
function bookdetail($viewid){
$q="SELECT * FROM book where id='$viewid'";
$data=$this->connection->query($q);
return $data;
}
function getbook(){
$q="SELECT * FROM book";
$data=$this->connection->query($q);
return $data;
}
function userlog($lid){
$uid="";
$rcheck="";
$type="";
$idate="";
$ireturn="";
$q="SELECT * FROM log WHERE bookid='$lid'";
$lg=$this->connection->query($q);
foreach($lg->fetchAll() as $row){
$uid=$row['userid'];
}
$q="SELECT * FROM user WHERE id='$uid'";
$ur=$this->connection->query($q);
foreach($ur->fetchAll() as $row){
$uname=$row['name'];
$type=$row['type'];
}
return [$uname,$type];
//return $ur;
}
function booklog($lid){
$q="SELECT * FROM log AS l INNER JOIN user AS u ON l.userid=u.id WHERE bookid='$lid'";
$lg=$this->connection->query($q);
return $lg;
//$sql="SELECT u.id,u.name,u.type,b.id,l.bookid,l.userid,l.bookreturn,l.returncheck FROM log l INNER JOIN user u ON u.id=l.userid INNER JOIN book b WHERE l.userid='$uid' AND l.bookid='$lid'";
//$lg=$this->connection->query($sql);
/*$q="SELECT * FROM log WHERE bookid='$lid'";
$lg=$this->connection->query($q);
return $lg;
*/
/*foreach($lg->fetchAll() as $row){
//$uid=$row['userid'];
$rcheck=$row['returncheck'];
}
if($rcheck == '0'){
$q="SELECT * FROM issuebook WHERE bookid='$lid'";
$ib=$this->connection->query($q);
return $ib;
}
else{
$q="SELECT * FROM ";
}
*/
/*
$q="SELECT * FROM book WHERE id='$lid'";
$res=$this->connection->query($q);
foreach($res->fetchAll() as $row){
$bname=$row['bookname'];
}
$sql="SELECT l.bookid,i.issuename,i.issuetype,i.issuedays,i.issuedate,i.issuereturn,l.returncheck FROM issuebook i RIGHT JOIN log l ON l.bookid=i.bookid AND l.userid WHERE l.issuebook='$bname'";
$data=$this->connection->query($sql);
return $data;
*/
}
function getbookissue(){
$q="SELECT * FROM book where bookava !=0";
$data=$this->connection->query($q);
return $data;
}
function bookissue($book,$user,$date,$days,$returndate){
$this->book=$book;
$this->user=$user;
$this->date=$date;
$this->days=$days;
$this->returnDate=$returndate;
//Insert into log table
$q="SELECT * FROM book where bookname='$book'";
$bookres=$this->connection->query($q);
$q="SELECT * FROM user where name='$user'";
$userres=$this->connection->query($q);
$res=$userres->rowCount();
if($res > 0){
foreach($bookres->fetchAll() as $row){
$bookid=$row['id'];
}
foreach($userres->fetchAll() as $row){
$issueid=$row['id'];
}
$sql="INSERT INTO log(userid, bookid, issuebook, bookissue, bookreturn, returncheck)VALUES('$issueid','$bookid', '$book', '$date', '$returndate', '0')";
$this->connection->exec($sql);
}
//bookissue start
$q="SELECT * FROM book where bookname='$book'";
$recordSet=$this->connection->query($q);
$q="SELECT * FROM user where name='$user'";
$recordset=$this->connection->query($q);
$result=$recordset->rowCount();
if($result > 0){
foreach($recordSet->fetchAll() as $row){
$bookid=$row['id'];
$bookname=$row['bookname'];
$bookava=$row['bookava'];
$bookrent=$row['bookrent'];
$newbookava=$bookava-1;
$newbookrent=$bookrent+1;
}
foreach($recordset->fetchAll() as $row){
$issueid=$row['id'];
$issuetype=$row['type'];
}
$q="UPDATE book SET bookava='$newbookava',bookrent='$newbookrent' where id='$bookid'";
if($this->connection->exec($q)){
$q="INSERT INTO issuebook(userid, bookid, issuename, issuebook, issuetype, issuedays, issuedate, issuereturn, fine)VALUES('$issueid','$bookid','$user', '$bookname', '$issuetype', '$days', '$date', '$returndate', '')";
if($this->connection->exec($q)){
header("Location:7admin_service_dashboard.php?msg=done");
}else{
header("Location:7admin_service_dashboard.php?msg=fail");
}
}
else{
header("Location:7admin_service_dashboard.php?msg=fail");
}
}
else{
header("Location:7admin_service_dashboard.php?msg=Invalid Credentials");
}
}
function bookreq(){
$q="SELECT * FROM requestbook";
$data=$this->connection->query($q);
return $data;
}
function bookreqapprove($book,$user,$days,$date,$returndate,$reqid){
$this->book=$book;
$this->user=$user;
$this->date=$date;
$this->days=$days;
$this->returnDate=$returndate;
$q="SELECT * FROM user where name='$user'";
$recordset=$this->connection->query($q);
$result=$recordset->rowCount();
$q="SELECT * FROM book where bookname='$book'";
$recordSet=$this->connection->query($q);
if($result > 0){
foreach($recordSet->fetchAll() as $row){
$bookid=$row['id'];
$bookname=$row['bookname'];
$newbookava=$row['bookava']-1;
$newbookrent=$row['bookrent']+1;
}
foreach($recordset->fetchAll() as $row){
$issueid=$row['id'];
$issuetype=$row['type'];
}
$q="UPDATE book SET bookava='$newbookava', bookrent='$newbookrent' where id='$bookid'";
if($this->connection->exec($q)){
$q="INSERT INTO issuebook(userid,issuename,issuebook,issuetype,issuedays,issuedate,issuereturn,fine)VALUES('$issueid','$user','$bookname','$issuetype','$days','$date','$returndate','0')";
if($this->connection->exec($q)){
$q="DELETE FROM requestbook where id='$reqid'";
$this->connection->exec($q);
header("Location:7admin_service_dashboard.php?msg=done");
}
else{
header("Location:7admin_service_dashboard.php?msg=fail");
}
}
else{
header("Location:7admin_service_dashboard.php?msg=fail");
}
}
else{
header("Location:7admin_service_dashboard.php?msg=Invalid Credentials");
}
}
function returnbookad($id){
//returnbook
$fine="";
$bookava="";
$issuebook="";
$bookrentel="";
$ibook="";
$bid="";
$uid="";
$idate="";
//INSERT into log table
$rdate=date('d/m/y');
$q="SELECT * FROM issuebook where id='$id'";
$ibookres=$this->connection->query($q);
$rs=$ibookres->rowCount();
if($rs > 0){
foreach($ibookres->fetchAll() as $row){
$ibook=$row['issuebook'];
$uid=$row['userid'];
$bid=$row['bookid'];
$idate=$row['issuedate'];
}
$db="INSERT INTO log(userid, bookid, issuebook, bookissue, bookreturn, returncheck)VALUES('$uid','$bid', '$ibook', '$idate','$rdate', '1')";
$this->connection->exec($db);
}
//log close
$q="SELECT * FROM issuebook where id='$id'";
$recordSet=$this->connection->query($q);
foreach($recordSet->fetchAll() as $row) {
$issuebook=$row['issuebook'];
$fine=$row['fine'];
}
if($fine==0){
$q="SELECT * FROM book where bookname='$issuebook'";
$recordSet=$this->connection->query($q);
foreach($recordSet->fetchAll() as $row) {
$bookava=$row['bookava']+1;
$bookrentel=$row['bookrent']-1;
}
$q="UPDATE book SET bookava='$bookava', bookrent='$bookrentel' where bookname='$issuebook'";
$this->connection->exec($q);
$q="DELETE from issuebook where id=$id and issuebook='$issuebook' and fine='0' ";
if($this->connection->exec($q)){
header("Location:7admin_service_dashboard.php");
}
}
}
}
?>