-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookList.jsp
More file actions
313 lines (294 loc) 路 13.5 KB
/
Copy pathbookList.jsp
File metadata and controls
313 lines (294 loc) 路 13.5 KB
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
<%@ page import="model.User" %>
<%
User user = (User) session.getAttribute("user");
if (user == null) {
response.sendRedirect("login.jsp");
return;
}
%>
<%@ include file="commonAdminHeader.jsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="model.Reservation, java.util.List, model.User, model.Book, dao.BookDAO, dao.UserDAO" %>
<%@ page import="model.Reservation.Status" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Reservations</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
body {
background-color: #f8f9fa;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding-top: 70px;
}
.navbar {
background-color: #1b5e20;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 10px 0;
position: fixed;
top: 0;
width: 100%;
z-index: 1000;
}
.navbar-brand {
font-weight: 600;
font-size: 1.5rem;
color: white;
}
.navbar-brand:hover {
color: #8bc34a;
}
.nav-link {
color: rgba(255, 255, 255, 0.85);
font-weight: 500;
margin: 0 8px;
padding: 8px 12px;
border-radius: 4px;
transition: all 0.3s;
}
.nav-link:hover, .nav-link.active {
color: white;
background-color: rgba(255, 255, 255, 0.1);
}
.nav-link i {
margin-right: 6px;
}
.user-dropdown .dropdown-toggle {
color: white;
display: flex;
align-items: center;
}
.library-header {
background-color: #1b5e20;
color: white;
padding: 30px 0;
margin-bottom: 40px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.library-header h1 {
font-weight: 600;
letter-spacing: 0.5px;
}
.reservation-container {
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 30px;
margin-bottom: 40px;
}
.btn-primary {
background-color: #4e73df;
border-color: #4e73df;
}
.btn-primary:hover {
background-color: #3a5bd9;
border-color: #3a5bd9;
}
.status-pending {
color: #f0ad4e;
}
.status-active {
color: #5cb85c;
}
.status-cancelled {
color: #d9534f;
}
.status-completed {
color: #0275d8;
}
.no-reservations {
text-align: center;
padding: 40px 0;
}
</style>
</head>
<body>
<%
// Initialize DAOs for additional information
BookDAO bookDAO = new BookDAO();
UserDAO userDAO = new UserDAO();
// Get the list of reservations from request attribute (may be null for search results)
List<Reservation> reservations = (List<Reservation>) request.getAttribute("reservations");
List<Book> bookList = (List<Book>) request.getAttribute("bookList");
boolean isAdmin = user.isAdmin();
%>
<!-- Top Navigation Bar -->
<nav class="navbar navbar-expand-lg">
<div class="container">
<a class="navbar-brand" href="dashboard.jsp">
<i class="fas fa-book-open me-2"></i>Library System
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link" href="dashboard.jsp">
<i class="fas fa-tachometer-alt"></i>Dashboard
</a>
</li>
<% if (user.isAdmin()) { %>
<li class="nav-item">
<a class="nav-link" href="searchBook.jsp">
<i class="fas fa-book"></i>Manage Books
</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="reservation?action=list">
<i class="fas fa-list-alt"></i>View Reservations
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="user?action=list">
<i class="fas fa-users"></i>Manage Users
</a>
</li>
<% } else { %>
<li class="nav-item">
<a class="nav-link" href="searchBook.jsp">
<i class="fas fa-book"></i>Search Books
</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="reservation?action=user&userId=<%= user.getUserId() %>">
<i class="fas fa-list"></i>My Reservations
</a>
</li>
<% } %>
</ul>
<div class="dropdown user-dropdown">
<a class="dropdown-toggle d-flex align-items-center text-decoration-none" href="#" role="button" data-bs-toggle="dropdown">
<i class="fas fa-user-circle me-2"></i>
<span><%= user.getUsername() %> (<%= user.getRole() %>)</span>
</a>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="#"><i class="fas fa-user me-2"></i>Profile</a></li>
<% if (user.isAdmin()) { %>
<li><a class="dropdown-item" href="user?action=list"><i class="fas fa-users me-2"></i>Manage Users</a></li>
<% } %>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item text-danger" href="logout.jsp"><i class="fas fa-sign-out-alt me-2"></i>Logout</a></li>
</ul>
</div>
</div>
</div>
</nav>
<div class="library-header text-center">
<h1><i class="bi bi-book"></i> Library Book Reservation System</h1>
</div>
<div class="container">
<div class="reservation-container">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2><i class="bi bi-bookmark"></i> <%= isAdmin ? "All Reservations" : "My Reservations" %></h2>
<a href="dashboard.jsp" class="btn btn-outline-secondary">
<i class="bi bi-arrow-left"></i> Back to Dashboard
</a>
</div>
<% if (bookList != null) { %>
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>ID</th>
<th>Book Title</th>
<th>Author</th>
<th>ISBN</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<% for (Book book : bookList) { %>
<tr>
<td><%= book.getBookId() %></td>
<td><%= book.getTitle() %></td>
<td><%= book.getAuthor() %></td>
<td><%= book.getIsbn() %></td>
<td><span class="badge <%= book.isAvailable() ? "bg-success" : "bg-danger" %>"><%= book.isAvailable() ? "Available" : "Reserved" %></span></td>
</tr>
<% } %>
</tbody>
</table>
</div>
<% } else if (reservations == null || reservations.isEmpty()) { %>
<div class="no-reservations">
<i class="bi bi-inbox-fill fs-1 text-muted"></i>
<h3 class="mt-3">No Reservations Found</h3>
<p class="text-muted">You don't have any active reservations at the moment.</p>
<a href="searchBook.jsp" class="btn btn-primary mt-3">Browse Books</a>
</div>
<% } else { %>
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>ID</th>
<th>Book Title</th>
<% if (isAdmin) { %><th>User</th><% } %>
<th>Reservation Date</th>
<th>Expiry Date</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% for (Reservation reservation : reservations) {
// Get book details
Book book = bookDAO.getBookById(reservation.getBookId());
// Get user details if admin view
user = null;
if (isAdmin) {
user = userDAO.getUserById(reservation.getUserId());
}
// Determine status CSS class
String statusClass = "";
switch(reservation.getStatus()) {
case Pending: statusClass = "status-pending"; break;
case Active: statusClass = "status-active"; break;
case Cancelled: statusClass = "status-cancelled"; break;
case Completed: statusClass = "status-completed"; break;
}
%>
<tr>
<td><%= reservation.getReservationId() %></td>
<td><%= book != null ? book.getTitle() : "Unknown Book" %></td>
<% if (isAdmin) { %>
<td><%= user != null ? user.getUsername() : (reservation.getUserName() != null ? reservation.getUserName() : "Unknown User") %></td>
<% } %>
<td><%= reservation.getReservationDate() %></td>
<td><%= reservation.getExpiryDate() %></td>
<td>
<span class="<%= statusClass %>">
<i class="bi bi-circle-fill me-1"></i>
<%= reservation.getStatus() %>
</span>
</td>
<td>
<% if (reservation.isActive() && reservation.getStatus() != Status.Cancelled) { %>
<a href="reservation?action=cancel&reservationId=<%= reservation.getReservationId() %>&bookId=<%= reservation.getBookId() %>"
class="btn btn-sm btn-danger">
<i class="bi bi-x-circle"></i> Cancel
</a>
<% } %>
<% if (isAdmin && reservation.getStatus() == Status.Pending) { %>
<a href="reservation?action=approve&reservationId=<%= reservation.getReservationId() %>"
class="btn btn-sm btn-success ms-1">
<i class="bi bi-check-circle"></i> Approve
</a>
<% } %>
</td>
</tr>
<% } %>
</tbody>
</table>
</div>
<% } %>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>