This repository was archived by the owner on Mar 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
166 lines (150 loc) · 6.75 KB
/
dashboard.php
File metadata and controls
166 lines (150 loc) · 6.75 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
<?php
include 'includes/db.php';
include 'includes/functions.php';
/** @var mysqli $conn * */
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: Login.php");
exit();
}
$user_id = $_SESSION['user_id'];
$user_query = "SELECT first_name, last_name FROM users WHERE id = ?";
$stmt = $conn->prepare($user_query);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$user_data = $stmt->get_result()->fetch_assoc();
$user_name = $user_data ? $user_data['first_name'] . " " . $user_data['last_name'] : "Guest";
$stmt->close();
$stats_query = "SELECT COUNT(*) as total FROM transactions WHERE user_id = ? AND status = 'borrowed'";
$stmt = $conn->prepare($stats_query);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$borrowed_count = $stmt->get_result()->fetch_assoc()['total'];
$stmt->close();
$loans_query = "SELECT t.id, t.book_id, b.title, t.issue_date, t.return_date, t.status
FROM transactions t
JOIN books b ON t.book_id = b.id
WHERE t.user_id = ? AND t.status = 'borrowed'
ORDER BY t.issue_date DESC";
$stmt = $conn->prepare($loans_query);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$loans_result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Library System</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<style>
.sidebar {
min-height: 100vh;
background-color: #f8f9fa;
border-right: 1px solid #dee2e6;
padding-top: 20px;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<nav class="col-md-2 d-none d-md-block sidebar">
<div class="text-center mb-4">
<h5 class="fw-bold text-success text-wrap px-2">
Library Management System
</h5>
</div>
<div class="d-grid gap-2 px-3">
<a href="Home.php"
class="btn btn-outline-success <?php echo (basename($_SERVER['PHP_SELF']) == 'Home.php') ? 'active' : ''; ?>">Home</a>
<a href="dashboard.php"
class="btn btn-outline-success <?php echo (basename($_SERVER['PHP_SELF']) == 'dashboard.php') ? 'active' : ''; ?>">My
Dashboard</a>
<a href="search.php"
class="btn btn-outline-success <?php echo (basename($_SERVER['PHP_SELF']) == 'search.php') ? 'active' : ''; ?>">Search
Books</a>
<hr>
<a href="logout.php?user_id=<?php echo $user_id ?>" class="btn btn-danger">Logout</a>
</div>
</nav>
<main class="col-md-10 ms-sm-auto px-md-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Welcome back, <?php echo e($user_name); ?></h1>
</div>
<div class="row mt-4">
<div class="col-md-4">
<div class="card shadow-sm border-start border-primary border-5">
<div class="card-body">
<h5 class="card-title text-muted small text-uppercase">Books Borrowed</h5>
<h2 class="fw-bold"><?php echo $borrowed_count; ?></h2>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm border-start border-warning border-5">
<div class="card-body">
<h5 class="card-title text-muted small">Pending Returns</h5>
<h2 class="fw-bold"><?php echo $borrowed_count; ?></h2>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm border-start border-danger border-5">
<div class="card-body">
<h5 class="card-title text-muted small">Overdue Fines</h5>
<h2 class="fw-bold">$0.00</h2>
</div>
</div>
</div>
</div>
<div class="mt-5">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3>Current Loans</h3>
<span class="badge bg-primary"><?php echo $borrowed_count; ?> Active Loan(s)</span>
</div>
<div class="table-responsive shadow-sm">
<table class="table table-hover align-middle">
<thead class="table-light">
<tr>
<th>Book Title</th>
<th>Borrow Date</th>
<th>Due Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php if ($loans_result->num_rows > 0): ?>
<?php while ($loan = $loans_result->fetch_assoc()): ?>
<tr>
<td class="fw-bold"><?php echo e($loan['title']); ?></td>
<td><?php echo date('M d, Y', strtotime($loan['issue_date'])); ?></td>
<td><?php echo date('M d, Y', strtotime($loan['return_date'])); ?></td>
<td>
<span class="badge rounded-pill bg-success me-2">
<?php echo ucfirst($loan['status']); ?>
</span>
<a href="return.php?id=<?php echo $loan['id']; ?>&book_id=<?php echo $loan['book_id']; ?>"
class="btn btn-sm btn-outline-danger"
onclick="return confirm('Are you sure you want to return: <?php echo e($loan['title']); ?>?')">
Return
</a>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="4" class="text-center text-muted py-4">You have no active loans.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</main>
</div>
</div>
<script src="assets/js/bootstrap.bundle.min.js"></script>
</body>
</html>