-
Notifications
You must be signed in to change notification settings - Fork 0
/
member.php
125 lines (125 loc) · 4.01 KB
/
member.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
<?php
session_start();
if($_SESSION['user_type']!='member')
{
header("location: login.php");
}
include 'conn.php';
$mem_id=$_SESSION['mem_id'];
$sql="SELECT * from borrow WHERE mem_id=".$mem_id." AND return_date='NONE';";
$res=$conn->query($sql);
$n=mysqli_num_rows($res);
if(isset($_POST['add_submit']))
{
$book_id=$_POST['book_id'];
$mem_id=$_SESSION['mem_id'];
$datetime = new DateTime();
$issue_date=$datetime->format('d-m-Y');
$datetime->add(new DateInterval('P1M'));
$due_date=$datetime->format('d-m-Y');
$sql="SELECT * from staff;";
$res=$conn->query($sql);
$staff_id=rand(1,mysqli_num_rows($res));
$sql="INSERT INTO borrow (book_id,mem_id,staff_id,issue_date,due_date,return_date,fine) VALUES (".$book_id.",".$mem_id.",".$staff_id.",'".$issue_date."','".$due_date."','NONE',0)";
$conn->query($sql);
$sql="SELECT * FROM book where book_id=".$book_id.";";
$res=$conn->query($sql);
$row=mysqli_fetch_assoc($res);
$available=$row['available'];
$available--;
$sql="UPDATE book SET available=".$available." WHERE book_id=".$book_id.";";
$conn->query($sql);
header("location: member.php?msg=1");
}
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Library/member</title>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js'></script>
<link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"><span style='color:lightblue'>Library Management</span></a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a>Add Books</a></li>
<li><a href="cart.php">My Cart <span class="badge"><?php echo $n; ?></span></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="logout.php"><span style='color:red'><span class="glyphicon glyphicon-log-out"></span> Log Out</span></a></li>
</ul>
</div>
</nav>
<div class='container'>
<table class="table table-bordered th, .table-bordered td { border: 1px solid #ddd!important }">
<thead>
<tr>
<th>Title</th>
<th>Genre</th>
<th>Author</th>
<th>Supplier</th>
<th>Publisher</th>
<th>Price</th>
<th>Available</th>
<th>CART</th>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT book.book_id,book.title,book.price,book.available,book.genre,supplier.name as sname,author.name as aname,publisher.name as pname from book inner join supplier on book.sup_id=supplier.sup_id inner join author on book.author_id=author.author_id inner join publisher on book.pub_id=publisher.pub_id;";
$res=$conn->query($sql);
while($row=mysqli_fetch_assoc($res))
{
?>
<tr id='book<?php echo $row["book_id"]; ?>'>
<td><?php echo $row["title"]; ?></td>
<td><?php echo $row["genre"]; ?></td>
<td><?php echo $row["aname"]; ?></td>
<td><?php echo $row["sname"]; ?></td>
<td><?php echo $row["pname"]; ?></td>
<td><?php echo $row["price"]; ?></td>
<td><?php echo $row["available"]; ?></td>
<td><button type="button" class="btn btn-primary" onclick="addCart('<?php echo $row["book_id"]; ?>')">Add</button></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</body>
</html>
<script>
function addCart(id)
{
tr=document.getElementById('book'+id);
td=tr.getElementsByTagName('td');
if(td[6].innerHTML!='0')
{
form=document.createElement('form');
form.setAttribute('action','member.php');
form.setAttribute('method','POST');
i1=document.createElement('input');
i1.setAttribute('name','book_id');
i1.setAttribute('type','text');
i1.setAttribute('value',id);
i2=document.createElement('input');
i2.setAttribute('name','add_submit');
i2.setAttribute('type','submit');
form.appendChild(i1);
form.appendChild(i2);
i2.click();
}
else
{
window.alert("Selected book is not available");
}
}
</script>