-
Notifications
You must be signed in to change notification settings - Fork 1
/
patron_book_view.php
240 lines (221 loc) · 13.4 KB
/
patron_book_view.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
<?php
include 'db.php';
session_start();
$expiry = 5400; //90 min is 5400 sec
if(isset($_SESSION['login_time']) && (time() - $_SESSION['login_time'] > $expiry)) {
session_unset();
session_destroy();
echo "<script>
alert('Please login again. Your session has expired.');
window.location.href = 'http://comet.cs.brynmawr.edu/~nchoudhary/CS380-Library-System/patron_login.php';
</script>";
}
?>
<!DOCTYPE html>
<html lang = "en-US" dir = "ltr">
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<link rel = "stylesheet" href = "http://comet.cs.brynmawr.edu/~nchoudhary/CS380-Library-System/style.css">
<link rel = "stylesheet" type = "text/css" href = "http://comet.cs.brynmawr.edu/~nchoudhary/CS380-Library-System/bookTableStyle.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
// filterFunction deals with filtering the columns of the table
function filterFunction() {
// get the input values to filter
var bookInput, authorInput, genreInput, yearInput, publisherInput, bookFilter, authorFilter, genreFilter, yearFilter, table, tr, td, i, txtValue;
bookInput = document.getElementById("bookInput");
authorInput = document.getElementById("authorInput");
genreInput = document.getElementById("genreInput");
yearInput = document.getElementById("yearInput");
publisherInput = document.getElementById("publisherInput");
bookFilter = bookInput.value.toUpperCase();
authorFilter = authorInput.value.toUpperCase();
genreFilter = genreInput.value.toUpperCase();
yearFilter = yearInput.value.toUpperCase();
publisherFilter = publisherInput.value.toUpperCase();
// get the table to search through
table = document.getElementById("result");
tr = table.getElementsByTagName("tr");
// go through values of the table and filter by inputs and skip the header and the inputs rows
for(i = 2; i < tr.length; i++) {
// checking the columns based on inputs
bookTd = tr[i].getElementsByTagName("td")[0];
authorTd = tr[i].getElementsByTagName("td")[1];
genreTd = tr[i].getElementsByTagName("td")[2];
yearTd = tr[i].getElementsByTagName("td")[3];
publisherTd = tr[i].getElementsByTagName("td")[4];
if(bookTd && authorTd && genreTd && yearTd && publisherTd) {
txtValueBook = bookTd.textContent || bookTd.innerText;
txtValueAuthor = authorTd.textContent || authorTd.innerText;
txtValueGenre = genreTd.textContent || genreTd.innerText;
txtValueYear = yearTd.textContent || yearTd.innerText;
txtValuePublisher = publisherTd.textContent || publisherTd.innerText;
if((txtValueBook.toUpperCase().indexOf(bookFilter) > -1) &&
(txtValueAuthor.toUpperCase().indexOf(authorFilter) > -1) &&
(txtValueGenre.toUpperCase().indexOf(genreFilter) > -1) &&
(txtValueYear.toUpperCase().indexOf(yearFilter) > -1) &&
(txtValuePublisher.toUpperCase().indexOf(publisherFilter) > -1)) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
$(document).ready(function() {
//Toggles the Show or Hide Borrowed div
$('.viewBooks').click(function(event) {
event.stopPropagation();
$(".showup").slideToggle("fast");
$('.showup').load('loadBorrowBooksDiv.php', function() { //loads the php file to update the div with new borrowed books
console.log('Load was performed.');
});
});
//Toggles the the text for Show or Hide Borrowed button
$('.viewBtn').click(function(event) {
var button = $(this);
button.text(button.text() == "Hide Borrowed" ? "Show Borrowed" : "Hide Borrowed")
});
});
</script>
<style>
* {
box-sizing: border-box;
}
body, html {
height: 100%;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background: rgb(245, 243, 243);
}
</style>
</head>
<body>
<div class = "hero-image">
<div id = "navbar">
<a href = "http://comet.cs.brynmawr.edu/~nchoudhary/CS380-Library-System/patron_index.php"> Home</a>
<a href = "http://comet.cs.brynmawr.edu/~nchoudhary/CS380-Library-System/nav_student.php"> Books</a>
<a href = "logout.php">Log Out</a>
<div class = "logo"><h1 style = "color: yellow; font-size: 25px;text-align: center;">NJM Online Library</h1></div>
</div>
</div>
<div class = "row">
<div class = "leftcolumn">
<div class = "card2">
<h1>Student Borrow Book Page</h1>
<div class = "viewBooks"><button class = "viewBtn">Show Borrowed</button></div>
<div class = "showup" id = "showup"></div>
<br />
<div class = 'listing' id = 'listing'>
<?php
ob_start();
//Session variable to get the user id of the username
$userId = "select user_id from njm_users where username = '" . $_SESSION['userName'] . "'";
$idResult = $connection->query($userId);
while($row = $idResult->fetch_assoc()) {
$id = $row['user_id'];
}
//query to create table of available books
//$q = "select * from njm_books where status = 'Available';";
$q = "select * from njm_books
inner join njm_publishers
on njm_books.publisher_id = njm_publishers.publisher_id
where njm_books.status = 'Available'";
$result = $connection->query($q);
if($result->num_rows > 0) {
echo "
<table id='result'>
<tr>
<th>Book Title</th>
<th>Author</th>
<th>Genre</th>
<th>Year</th>
<th>Publisher</th>
<th>Borrow</th>
</tr>
<tr>
<td><input type = 'text' id = 'bookInput' onkeyup = 'filterFunction()' placeholder = 'Search for Title'></td>
<td><input type = 'text' id = 'authorInput' onkeyup = 'filterFunction()' placeholder = 'Search for Author'></td>
<td><input type = 'text' id = 'genreInput' onkeyup = 'filterFunction()' placeholder = 'Search for Genre'></td>
<td><input type = 'text' id = 'yearInput' onkeyup = 'filterFunction()' placeholder = 'Search for Year'></td>
<td><input type = 'text' id = 'publisherInput' onkeyup = 'filterFunction()' placeholder = 'Search for Publisher'></td>
<td>Action</td>
</tr>
";
echo "<tbody class='bookRows' id = 'bookRows'>";
while($row = $result->fetch_assoc()) {
$title = $row['title'];
$author = $row['author'];
$book_id = $row['book_id'];
$genre = $row['genre'];
$year = $row['year'];
$publisher = $row['name'];
echo "<form id='bookorder' name='form1' method='post'> <tr class='table'>
<td class='table' data-input='title'> <input type = 'hidden' name ='title' value = '$title' > $title </td>
<td class='table' data-input='author'> <input type = 'hidden' name ='author' value = '$author' > $author </td>
<td class='table' data-input='genre'> <input type = 'hidden' name ='genre' value = '$genre' > $genre </td>
<td class='table' data-input='year'> <input type = 'hidden' name ='year' value = '$year' > $year </td>
<td class='table' data-input='publisher'> <input type = 'hidden' name ='publisher' value = '$publisher' > $publisher </td>
<input type = 'hidden' name='book_id' value= '$book_id' >
<td> <button class='editbtn' type='submit' value='submit'> Borrow </button></td>
</tr> </form>";
}
echo "</tbody>";
// checks if form has been submitted and adds to the transaction table and changes the status in the books table
if(isset($_POST['title']) && isset($_POST['author'])){
$dueDate = date('Y-m-d', strtotime('+7 day')); // gets the current date and adds a week to it
$q = "insert into njm_transactions (transaction_type, book_id, user_id, due_date) values
('borrowed', '".$_POST['book_id']."', '$id', '$dueDate');"; // need to change 14 to user_id
if(mysqli_query($conn, $q)) {
//shows alert box to indicate that a book has been borrowed
echo "<script>
alert('".$_POST['title']." By ".$_POST['author']." Added Successfully');
window.location.href = window.location.search;
</script>";
} else {
echo "Error: " . $q . "<br>" . mysqli_error($conn);
}
$statusChange = "update njm_books set status = 'Not Available' where book_id = '".$_POST['book_id']."';";
if(mysqli_query($conn, $statusChange)) {
//echo "New record created successfully";
} else {
echo "Error: " . $statusChange . "<br>" . mysqli_error($conn);
}
}
} else {
echo "Did not Work!";
}
echo "</table>";
?>
</div>
</div>
</div>
<div class = "rightcolumn" style="padding-top:180px;">
<h4><a href = "http://comet.cs.brynmawr.edu/~nchoudhary/CS380-Library-System/main_login.php">Log in</a></h4>
<h3>Monthly Book Club Reads</h3>
<div class = "fakeimg"><img src = "http://comet.cs.brynmawr.edu/~nchoudhary/CS380-Library-System/images/persuasion_ja.jpg"><br>Persuasion by Jane Austen</div>
<div class = "fakeimg"><img src = "http://comet.cs.brynmawr.edu/~nchoudhary/CS380-Library-System/images/anxious_people.jpeg"><br>Anxious People by Fredrick Backman</div><br>
</div>
</div>
<div class = "footer">
<p style = "color:white; text-align: center; ">
<br><br>
Contact us @
Email: ouremail.brynmawr.edu <br>
Phone: +1 610 526 5000
</p>
</div>
<script>
window.onscroll = function() {myFunction()};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;
function myFunction() {
if(window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
</script>
</body>
</html>