-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaff_index.php
More file actions
508 lines (459 loc) · 15.7 KB
/
staff_index.php
File metadata and controls
508 lines (459 loc) · 15.7 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
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
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
include 'staff_session_check.php';
// Include database connection
include 'connection.php';
// Fetch dashboard statistics
// Removed fetching of dashboard statistics as stats component is deleted
// $stats = [];
// $sql = "SELECT stat_name, stat_value FROM library_stats";
// $result = mysqli_query($db, $sql);
// while ($row = mysqli_fetch_assoc($result)) {
// $stats[$row['stat_name']] = $row['stat_value'];
// }
$activities = [];
// Updated query to fetch recent activities from issued_books and reservations with detailed status and dates
$sql = "
SELECT b.title AS book_title, CONCAT(s.first_name, ' ', s.last_name) AS student_name,
CASE
WHEN ib.return_date IS NULL THEN 'Issued'
ELSE 'Returned'
END AS status,
COALESCE(ib.return_date, ib.issue_date) AS activity_date
FROM issued_books ib
JOIN books b ON ib.book_id = b.id
JOIN students s ON ib.student_id = s.id
WHERE ib.issue_date IS NOT NULL
UNION ALL
SELECT b.title AS book_title, CONCAT(s.first_name, ' ', s.last_name) AS student_name,
r.status,
CASE
WHEN r.status = 'Rejected' THEN r.rejected_at
WHEN r.status = 'Returned' THEN r.returned_at
WHEN r.status = 'Issued' THEN COALESCE(ib.issue_date, r.reservation_date)
ELSE r.reservation_date
END AS activity_date
FROM reservations r
JOIN books b ON r.book_id = b.id
JOIN students s ON s.email = r.student_email
LEFT JOIN issued_books ib ON ib.student_id = s.id AND ib.book_id = r.book_id AND ib.return_date IS NULL
WHERE r.status IN ('Rejected', 'Booked', 'Issued', 'Returned')
ORDER BY activity_date DESC
LIMIT 10
";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$activities[] = $row;
}
// Fetch overdue books
$overdue_books = [];
$sql = "SELECT b.title, s.first_name, s.last_name, ib.issue_date
FROM issued_books ib
JOIN books b ON ib.book_id = b.id
JOIN students s ON ib.student_id = s.id
WHERE ib.return_date IS NULL
AND ib.issue_date < DATE_SUB(NOW(), INTERVAL 14 DAY)
ORDER BY ib.issue_date ASC LIMIT 5";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$overdue_books[] = $row;
}
// Fetch contact messages for Emails component
$emails = [];
$sql_emails = "SELECT id, name, email, phone, message, submitted_at FROM contact_messages ORDER BY submitted_at DESC LIMIT 10";
$result_emails = mysqli_query($db, $sql_emails);
while ($row = mysqli_fetch_assoc($result_emails)) {
$emails[] = $row;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Staff Dashboard | Booker Library</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
<style>
:root {
--primary-color: #2c3e50;
--secondary-color: #3498db;
--accent-color: #e74c3c;
--light-bg: #f8f9fa;
--dark-text: #2c3e50;
--light-text: #f8f9fa;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: var(--light-bg);
padding-top: 56px;
color: var(--dark-text);
}
/* Sidebar Styles */
.sidebar {
height: calc(100vh - 56px);
background-color: var(--primary-color);
color: white;
padding-top: 20px;
position: fixed;
top: 56px;
width: 220px;
transition: transform 0.3s ease-in-out;
box-shadow: 2px 0 10px rgba(0,0,0,0.1);
z-index: 1000;
}
.sidebar a {
color: rgba(255,255,255,0.8);
display: block;
padding: 12px 20px;
text-decoration: none;
font-weight: 500;
transition: all 0.2s;
border-left: 3px solid transparent;
}
.sidebar a:hover {
background-color: rgba(255,255,255,0.1);
color: white;
border-left: 3px solid var(--secondary-color);
}
.sidebar a i {
margin-right: 10px;
width: 20px;
text-align: center;
}
.sidebar .active {
background-color: rgba(255,255,255,0.1);
border-left: 3px solid var(--secondary-color);
color: white;
}
/* Main Content Styles */
.content {
margin-left: 220px;
padding: 25px;
transition: margin 0.3s ease-in-out;
}
/* Navbar Styles */
.navbar-custom {
background-color: var(--secondary-color);
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.navbar-custom .navbar-brand {
font-weight: 600;
color: white;
}
/* Card Styles */
.card {
border: none;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
transition: transform 0.3s ease, box-shadow 0.3s ease;
margin-bottom: 20px;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.card-header {
background-color: var(--primary-color);
color: white;
border-radius: 10px 10px 0 0 !important;
}
/* Stats Card Styles */
.stat-card {
text-align: center;
padding: 20px;
border-radius: 10px;
background-color: white;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.stat-card .stat-value {
font-size: 2.5rem;
font-weight: 700;
}
.stat-card .stat-label {
font-size: 0.9rem;
color: #6c757d;
}
/* Activity Log Styles */
.activity-item {
padding: 10px 0;
border-bottom: 1px solid #eee;
}
.activity-item:last-child {
border-bottom: none;
}
.activity-time {
font-size: 0.8rem;
color: #6c757d;
}
/* Recent Activities Animation */
.recent-activities-container {
height: 300px;
overflow: hidden;
position: relative;
}
.recent-activities-list {
position: absolute;
width: 100%;
animation: scrollUp 20s linear infinite;
display: flex;
flex-direction: column;
bottom: 0;
}
@keyframes scrollUp {
0% {
bottom: -100%;
}
100% {
bottom: 0;
}
}
/* Responsive Styles */
@media (max-width: 992px) {
.sidebar {
transform: translateX(-100%);
}
.sidebar.show {
transform: translateX(0);
}
.content {
margin-left: 0;
}
}
/* Dashboard Components */
.dashboard-container {
display: block;
}
</style>
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-lg navbar-custom fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#" onclick="return showDashboard()" style="display: flex; align-items: center; gap: 10px;">
<img src="booker library1.png" alt="Booker Library Logo" style="height: 40px;" />
<span><i class="bi bi-book"></i> Booker Library Staff Portal</span>
</a>
<button class="navbar-toggler btn btn-outline-light d-lg-none" type="button" id="sidebarToggle">
<i class="bi bi-list"></i>
</button>
</div>
</nav>
<!-- Sidebar -->
<div class="sidebar" id="sidebar">
<a href="#" onclick="return showDashboard()" class="active" id="nav-dashboard">
<i class="bi bi-speedometer2"></i> Dashboard
</a>
<!-- Removed duplicate Communications Center button -->
<a href="book_management_new.php" id="nav-book-management">
<i class="bi bi-book"></i> Book Management
</a>
<a href="student_management.php" id="nav-student-management">
<i class="bi bi-people"></i> Student Management
</a>
<a href="issue_return_books.php" id="nav-issue-return">
<i class="bi bi-arrow-left-right"></i> Issue & Return
</a>
<a href="bookings_reservations.php" id="nav-reservations">
<i class="bi bi-calendar-check"></i> Reservations
</a>
<a href="staff_resources.php" id="nav-resources">
<i class="bi bi-folder2-open"></i> Resources
</a>
<a href="staff_communications_center.php" id="nav-communications-center" target="_self">
<i class="bi bi-megaphone"></i> Communications Center
</a>
<a href="emails.php" id="nav-emails">
<i class="bi bi-envelope"></i> Emails
</a>
<a href="settings_configurations.php" id="nav-settings">
<i class="bi bi-gear"></i> Settings
</a>
<a href="staff_logout.php" class="logout-link" id="nav-logout">
<i class="bi bi-box-arrow-right"></i> Logout
</a>
</div>
<!-- Dashboard Content -->
<div class="content dashboard-container" id="dashboardContent">
<!-- Include stats.php content -->
<?php include 'stats.php'; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">Dashboard Overview</h1>
<div class="text-muted"><?php echo date('F j, Y'); ?></div>
</div>
<!-- Stats Cards -->
<!-- Removed Stats Cards component as per user request -->
<div class="row">
<!-- Quick Actions -->
<div class="col-lg-6">
<div class="card shadow">
<div class="card-header">
<h5 class="mb-0"><i class="bi bi-lightning"></i> Quick Actions</h5>
</div>
<div class="card-body">
<div class="row text-center">
<div class="col-md-4 mb-3">
<a href="issue_return_books.php" class="btn btn-primary btn-block py-3">
<i class="bi bi-arrow-left-right"></i><br>
Issue/Return
</a>
</div>
<div class="col-md-4 mb-3">
<a href="bookings_reservations.php" class="btn btn-success btn-block py-3">
<i class="bi bi-megaphone"></i><br>
Send Alert
</a>
</div>
<div class="col-md-4 mb-3">
<a href="book_management_new.php" class="btn btn-info btn-block py-3">
<i class="bi bi-plus-circle"></i><br>
Add Book
</a>
</div>
</div>
</div>
</div>
<!-- Recent Activities -->
<div class="card shadow">
<div class="card-header">
<h5 class="mb-0"><i class="bi bi-clock-history"></i> Recent Activities</h5>
</div>
<div class="card-body recent-activities-container">
<?php if (!empty($activities)): ?>
<div class="recent-activities-list">
<?php
foreach ($activities as $activity): ?>
<div class="activity-item">
<div><strong><?php echo htmlspecialchars($activity['book_title']); ?></strong></div>
<div>Student: <?php echo htmlspecialchars($activity['student_name']); ?></div>
<div>Status: <?php echo htmlspecialchars($activity['status']); ?></div>
<div class="activity-time">
<?php
try {
$date = new DateTime($activity['activity_date']);
$date->setTimezone(new DateTimeZone('Africa/Nairobi'));
echo $date->format('M j, H:i');
} catch (Exception $e) {
echo htmlspecialchars($activity['activity_date']);
}
?>
</div>
</div>
<?php endforeach; ?>
<?php
// Duplicate the list for seamless scrolling
foreach ($activities as $activity): ?>
<div class="activity-item">
<div><strong><?php echo htmlspecialchars($activity['book_title']); ?></strong></div>
<div>Student: <?php echo htmlspecialchars($activity['student_name']); ?></div>
<div>Status: <?php echo htmlspecialchars($activity['status']); ?></div>
<div class="activity-time">
<?php
try {
$date = new DateTime($activity['activity_date'], new DateTimeZone('UTC'));
$date->setTimezone(new DateTimeZone('Africa/Nairobi'));
echo $date->format('M j, H:i');
} catch (Exception $e) {
echo htmlspecialchars($activity['activity_date']);
}
?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="text-muted">No recent activities</p>
<?php endif; ?>
</div>
</div>
</div>
<!-- Overdue Books -->
<div class="col-lg-6">
<div class="card shadow">
<div class="card-header bg-warning text-white">
<h5 class="mb-0"><i class="bi bi-exclamation-triangle"></i> Overdue Books</h5>
</div>
<div class="card-body">
<?php if (!empty($overdue_books)): ?>
<?php foreach ($overdue_books as $book): ?>
<div class="overdue-item">
<div class="fw-bold"><?php echo htmlspecialchars($book['title']); ?></div>
<div>
Borrowed by: <?php echo htmlspecialchars($book['first_name'] . ' ' . $book['last_name']); ?>
</div>
<div class="overdue-days">
<?php
$days_overdue = floor((time() - strtotime($book['issue_date'])) / (60 * 60 * 24)) - 14;
echo $days_overdue > 0 ? $days_overdue . ' days overdue' : 'Due soon';
?>
</div>
</div>
<?php endforeach; ?>
<a href="issue_return_books.php?filter=overdue" class="btn btn-warning mt-3">
<i class="bi bi-arrow-right"></i> View All Overdue Books
</a>
<?php else: ?>
<p class="text-muted">No overdue books at this time</p>
<?php endif; ?>
</div>
</div>
<!-- System Status -->
<div class="card shadow">
<div class="card-header">
<h5 class="mb-0"><i class="bi bi-server"></i> System Status</h5>
</div>
<div class="card-body">
<div class="mb-2">
<span class="fw-bold">Database:</span>
<span class="badge bg-success">Online</span>
</div>
<div class="mb-2">
<span class="fw-bold">Last Backup:</span>
<span><?php echo date('M j, Y', strtotime($stats['Last Backup'] ?? 'now')); ?></span>
</div>
<div>
<span class="fw-bold">System Version:</span>
<span>2.4.1</span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Emails Component -->
<!-- Removed entire emails section as per user request -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Sidebar toggle functionality
document.getElementById('sidebarToggle').addEventListener('click', function() {
document.getElementById('sidebar').classList.toggle('show');
});
// Function to highlight active menu item
function setActiveMenuItem(activeItem) {
document.querySelectorAll('.sidebar a').forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === activeItem) {
link.classList.add('active');
}
});
}
// Show dashboard and hide other content
function showDashboard() {
document.getElementById('dashboardContent').style.display = 'block';
setActiveMenuItem('staff_index.php');
return false;
}
// Show communications center page
function showCommunicationsCenter() {
window.location.href = 'staff_communications_center.php';
return false;
}
// Initialize the page
document.addEventListener('DOMContentLoaded', function() {
showDashboard();
});
</script>
</body>
</html>