Certainly! I've enhanced your member dashboard with a modern, clean, and advanced UI using Bootstrap 5 components, cards, icons, tables, badges, and better responsive layout. The interface now has a sidebar with icons, smooth transitions, modals for actions, clearer alerts, improved forms, tooltips, and more refined styles while keeping the logic almost the same.
Below is the full updated PHP + HTML + CSS + JS code for your member dashboard, ready to replace your current page. It assumes you have Bootstrap 5 CSS/JS included via CDN, plus FontAwesome 6 for icons.
<?php
session_start();
if (!isset($_SESSION['username']) || !isset($_SESSION['role']) || $_SESSION['role'] !== 'member') {
header("Location: login.php");
exit;
}
require 'config.php';
$userId = $_SESSION['user_id'];
// Messages for actions feedback
$messages = [];
if (!empty($_GET['borrowed'])) {
$messages[] = ['type' => 'success', 'text' => 'Book borrowed successfully.'];
}
if (!empty($_GET['returned'])) {
$messages[] = ['type' => 'success', 'text' => 'Book returned successfully.'];
}
if (!empty($_GET['profile_updated'])) {
$messages[] = ['type' => 'success', 'text' => 'Profile updated successfully.'];
}
if (!empty($_GET['profile_error'])) {
$messages[] = ['type' => 'danger', 'text' => htmlspecialchars($_GET['profile_error'])];
}
// Fetch user's borrowed books - CURRENT BORROWED
// Includes overdue fine and due soon indicator (due in 3 days or less)
$stmtBorrowed = $pdo->prepare("
SELECT br.id AS borrow_id, b.title, b.author, br.borrow_date, br.due_date,
CASE
WHEN br.return_date IS NULL AND br.due_date < CURDATE()
THEN DATEDIFF(CURDATE(), br.due_date) * 1 ELSE 0
END AS fine,
CASE
WHEN br.return_date IS NULL AND br.due_date BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 3 DAY)
THEN 1 ELSE 0
END AS due_soon
FROM borrow_records br
JOIN books b ON br.book_id = b.id
WHERE br.user_id = ? AND br.return_date IS NULL
ORDER BY br.due_date ASC
");
$stmtBorrowed->execute([$userId]);
$currentBorrowedBooks = $stmtBorrowed->fetchAll();
// Fetch borrow history (returned books) - UPDATED to select stored fine
$stmtHistory = $pdo->prepare("
SELECT br.id AS borrow_id, b.title, b.author, br.borrow_date, br.due_date, br.return_date, br.fine
FROM borrow_records br
JOIN books b ON br.book_id = b.id
WHERE br.user_id = ? AND br.return_date IS NOT NULL
ORDER BY br.return_date DESC
LIMIT 20
");
$stmtHistory->execute([$userId]);
$borrowHistory = $stmtHistory->fetchAll();
// Search & Pagination for available books
$search = trim($_GET['search'] ?? '');
$searchParam = "%" . $search . "%";
$searchActive = $search !== '';
$perPage = 12;
$page = max(1, intval($_GET['page'] ?? 1));
$offset = ($page - 1) * $perPage;
if ($searchActive) {
// Count total matching books
$stmtBooksTotal = $pdo->prepare("
SELECT COUNT(*) FROM books
WHERE available_copies > 0 AND (title LIKE ? COLLATE utf8mb4_general_ci OR author LIKE ? COLLATE utf8mb4_general_ci)
");
$stmtBooksTotal->execute([$searchParam, $searchParam]);
$totalBooks = $stmtBooksTotal->fetchColumn();
// Fetch matching books with limit and offset
$stmtBooks = $pdo->prepare("
SELECT * FROM books
WHERE available_copies > 0
AND (title LIKE ? COLLATE utf8mb4_general_ci OR author LIKE ? COLLATE utf8mb4_general_ci)
ORDER BY title
LIMIT ? OFFSET ?
");
$stmtBooks->bindValue(1, $searchParam, PDO::PARAM_STR);
$stmtBooks->bindValue(2, $searchParam, PDO::PARAM_STR);
$stmtBooks->bindValue(3, $perPage, PDO::PARAM_INT);
$stmtBooks->bindValue(4, $offset, PDO::PARAM_INT);
$stmtBooks->execute();
} else {
$stmtBooksTotal = $pdo->query("SELECT COUNT(*) FROM books WHERE available_copies > 0");
$totalBooks = $stmtBooksTotal->fetchColumn();
$stmtBooks = $pdo->prepare("
SELECT * FROM books
WHERE available_copies > 0
ORDER BY title
LIMIT ? OFFSET ?
");
$stmtBooks->bindValue(1, $perPage, PDO::PARAM_INT);
$stmtBooks->bindValue(2, $offset, PDO::PARAM_INT);
$stmtBooks->execute();
}
$availableBooks = $stmtBooks->fetchAll();
$totalPages = ceil($totalBooks / $perPage);
require 'header.php'; // Your site's header including Bootstrap CSS, etc.
?>
<!-- Google Fonts + FontAwesome -->
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@600;700&family=Open+Sans&display=swap" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet" />
<style>
/* --- Base & Typography --- */
body {
font-family: 'Open Sans', sans-serif;
background-color: #f4f6fc;
color: #344767;
min-height: 100vh;
}
h1, h2, h3, h4, h5 {
font-family: 'Montserrat', sans-serif;
color: #2e3e68;
}
/* --- Layout --- */
.d-flex {
min-height: 100vh;
}
/* Sidebar */
.sidebar {
width: 280px;
background: #3b44a1;
color: #fefeff;
padding: 2rem 1rem;
display: flex;
flex-direction: column;
gap: 1rem;
position: sticky;
top: 0;
height: 100vh;
border-right: 1px solid rgba(255,255,255,0.1);
}
.sidebar h3 {
font-weight: 700;
font-size: 1.8rem;
margin-bottom: 2rem;
user-select: none;
}
.sidebar a {
display: flex;
align-items: center;
gap: 12px;
color: #cfd9f8;
padding: 0.7rem 1rem;
border-radius: 10px;
font-weight: 600;
font-size: 1rem;
text-decoration: none;
transition: background-color 0.3s, color 0.4s;
user-select: none;
}
.sidebar a i {
min-width: 20px;
font-size: 1.2rem;
}
.sidebar a.active, .sidebar a:hover {
background-color: #1e275f;
color: #9bc6fc;
}
.sidebar a.logout-link {
margin-top: auto;
background: #ea5555;
color: #fff;
transition: background-color 0.3s ease;
}
.sidebar a.logout-link:hover {
background: #cc4444;
}
/* Main Content */
.main-content {
flex: 1;
background-color: #fff;
padding: 2.5rem 3rem;
overflow-x: hidden;
}
/* Header User */
.header-user {
display: flex;
align-items: center;
gap: 1.5rem;
margin-bottom: 2.5rem;
}
.avatar {
width: 84px;
height: 84px;
border-radius: 50%;
border: 3px solid #3b44a1;
object-fit: cover;
box-shadow: 0 2px 8px rgb(59 68 161 / 0.3);
transition: transform 0.3s ease;
}
.avatar:hover {
transform: scale(1.1);
}
.header-user h1 {
font-size: 2.25rem;
font-weight: 700;
color: #223366;
}
.header-user p {
margin: 4px 0 0;
color: #556080;
font-size: 1.05rem;
font-weight: 500;
}
/* Alerts/Messages */
.messages {
margin-bottom: 1.75rem;
}
/* Cards Wrapper */
.row.g-4 {
display: grid;
grid-template-columns: repeat(auto-fill,minmax(240px,1fr));
gap: 1.5rem;
}
/* Card Book */
.card-book {
background-color: #fefeff;
border-radius: 16px;
padding: 1.25rem 1.5rem;
box-shadow: 0 10px 20px rgb(0 0 0 / 0.04);
display: flex;
flex-direction: column;
justify-content: space-between;
transition: transform 0.3s ease, box-shadow 0.4s ease;
cursor: default;
}
.card-book:hover {
transform: translateY(-8px);
box-shadow: 0 20px 35px rgb(0 0 0 / 0.10);
}
.card-book h5 {
font-family: 'Montserrat', sans-serif;
font-weight: 700;
color: #3b44a1;
margin-bottom: 6px;
}
.card-book .author {
font-style: italic;
color: #677a99;
font-size: 0.95rem;
margin-bottom: 0.75rem;
}
.card-book p {
font-size: 0.93rem;
color: #4a5568;
margin-bottom: 0.4rem;
}
/* Buttons */
.btn-borrow, .btn-return {
font-weight: 700;
border-radius: 8px;
padding: 0.55rem 0;
color: white;
text-align: center;
font-size: 0.95rem;
box-shadow: 0 4px 8px rgb(0 0 0 / 0.12);
transition: background-color 0.3s ease;
user-select: none;
border: none;
width: 100%;
}
.btn-borrow {
background-color: #3b44a1;
}
.btn-borrow:hover {
background-color: #29366a;
}
.btn-return {
background-color: #da4a4a;
}
.btn-return:hover {
background-color: #b73c3c;
}
/* Badges */
.fine-badge {
background: #e55353;
color: white;
font-weight: 700;
padding: 0.3rem 0.8rem;
border-radius: 9px;
font-size: 0.76rem;
display: inline-block;
margin-top: 0.75rem;
box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
letter-spacing: 0.03em;
}
.due-soon {
background-color: #fbbc04;
color: #664d03;
font-weight: 700;
padding: 0.3rem 0.55rem;
border-radius: 10px;
font-size: 0.78rem;
margin-left: 0.5rem;
box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
user-select: none;
}
/* Section Titles */
.section-title {
font-family: 'Montserrat', sans-serif;
font-weight: 700;
font-size: 1.5rem;
color: #253858;
margin-bottom: 1.2rem;
border-bottom: 3px solid #3b44a1;
padding-bottom: 0.3rem;
user-select: none;
}
/* Tables */
table.borrow-history, table.table-striped {
width: 100%;
border-collapse: collapse;
font-size: 0.95rem;
box-shadow: 0 0 12px rgb(0 0 0 / 0.06);
border-radius: 12px;
overflow: hidden;
}
table.borrow-history th, table.table-striped thead th {
background-color: #ebf0ff;
color: #3b44a1;
font-weight: 700;
padding: 0.85rem 1rem;
text-align: left;
}
table.borrow-history td, table.table-striped tbody td {
padding: 0.75rem 1rem;
border-bottom: 1px solid #e0e6ff;
color: #4a5568;
}
table.borrow-history tr:last-child td, table.table-striped tbody tr:last-child td {
border-bottom: none;
}
/* Bootstrap buttons override for action buttons inside table */
table.borrow-history a.btn, table.table-striped a.btn {
font-size: 0.85rem;
padding: 0.3rem 0.6rem;
}
/* Pagination */
nav.pagination-nav {
margin-top: 1.8rem;
display: flex;
justify-content: center;
}
.pagination {
gap: 6px;
}
.pagination li a {
border-radius: 8px;
font-weight: 600;
font-size: 0.9rem;
color: #3b44a1;
min-width: 38px;
padding: 6px 12px;
border: 1.5px solid transparent;
transition: all 0.3s ease;
}
.pagination li.active a {
background-color: #3b44a1;
color: white;
border-color: #3b44a1;
box-shadow: 0 2px 8px rgb(59 68 161 / 0.3);
}
.pagination li a:hover {
background-color: #29366a;
color: white;
border-color: #29366a;
}
/* Search Bar */
form.search-bar {
max-width: 580px;
margin-bottom: 2rem;
}
form.search-bar .form-control {
border-right: 0 !important;
border-top-right-radius: 0 !important;
border-bottom-right-radius: 0 !important;
}
form.search-bar button {
border-top-left-radius: 0 !important;
border-bottom-left-radius: 0 !important;
}
form.search-bar .btn-outline-secondary {
margin-left: 0.8rem;
padding: 0.45rem 1rem;
font-weight: 600;
font-size: 0.9rem;
}
/* Profile Form */
form.needs-validation {
max-width: 460px;
background: #f9fbff;
border-radius: 14px;
padding: 2rem 2.5rem;
box-shadow: 0 12px 25px rgb(59 68 161 / 0.1);
user-select: none;
}
form.needs-validation .form-label {
font-weight: 600;
color: #374151;
}
form.needs-validation input.form-control {
border-radius: 10px;
padding: 0.6rem 0.85rem;
font-size: 0.95rem;
transition: all 0.3s ease;
}
form.needs-validation input.form-control:focus {
box-shadow: 0 0 10px rgb(59 68 161 / 0.4);
border-color: #3b44a1;
}
button[type="submit"].btn-primary {
background-color: #3b44a1;
border-color: #3b44a1;
font-weight: 700;
border-radius: 8px;
padding: 0.5rem 1.2rem;
font-size: 1rem;
box-shadow: 0 5px 20px rgb(59 68 161 / 0.2);
transition: background-color 0.3s ease, box-shadow 0.3s ease;
}
button[type="submit"].btn-primary:hover {
background-color: #29366a;
box-shadow: 0 8px 30px rgb(41 54 106 / 0.4);
}
/* Invalid Feedback Styling */
.is-invalid, .was-validated .is-invalid {
border-color: #dc3545 !important;
box-shadow: none !important;
}
.invalid-feedback {
font-size: 0.85rem;
color: #dc3545;
display: none;
}
#password-mismatch-feedback {
margin-top: 4px;
}
/* Responsive */
@media (max-width: 991.98px) {
.sidebar {
width: 220px;
padding: 2rem 1rem 2rem 1rem;
}
.main-content {
padding: 2rem 2rem;
}
}
@media (max-width: 767.98px) {
.d-flex {
flex-direction: column;
}
.sidebar {
width: 100%;
height: auto;
position: relative;
padding: 1.5rem;
flex-direction: row;
gap: 1rem;
overflow-x: auto;
border-right: none;
border-bottom: 1px solid rgba(0,0,0,.1);
}
.sidebar h3 {
display: none;
}
.sidebar a {
flex: 1 0 auto;
justify-content: center;
padding: 0.45rem 0.4rem;
font-size: 0.9rem;
white-space: nowrap;
}
.sidebar a i {
margin: 0;
font-size: 1.25rem;
display: block;
line-height: 1;
margin-bottom: 0.1rem;
}
.main-content {
padding: 1rem 1rem;
}
form.search-bar {
max-width: 100%;
flex-wrap: wrap;
gap: 0.65rem;
}
form.search-bar .btn-outline-secondary {
margin-left: 0;
flex: 0 0 130px;
}
}
</style>
<div class="d-flex" style="min-height:100vh;">
<!-- Sidebar -->
<nav class="sidebar" aria-label="Member Dashboard Navigation">
<h3>Member Panel</h3>
<a href="#dashboard" class="active" data-bs-toggle="tab" aria-current="page"><i class="fa-solid fa-house"></i> Dashboard</a>
<a href="#borrowedBooks" data-bs-toggle="tab"><i class="fa-solid fa-book-open-reader"></i> Borrowed Books</a>
<a href="#searchBooks" data-bs-toggle="tab"><i class="fa-solid fa-magnifying-glass-book"></i> Search & Borrow</a>
<a href="#borrowHistory" data-bs-toggle="tab"><i class="fa-solid fa-clock-rotate-left"></i> Borrow History</a>
<a href="#profileSection" data-bs-toggle="tab"><i class="fa-solid fa-user-gear"></i> Profile</a>
<a href="logout.php" class="logout-link" role="button"><i class="fa-solid fa-right-from-bracket"></i> Logout</a>
</nav>
<!-- Main Content -->
<main class="main-content" tabindex="-1">
<div class="tab-content" id="member-tabs">
<!-- Dashboard Tab -->
<section class="tab-pane fade show active" id="dashboard" role="tabpanel" aria-labelledby="dashboard-tab" tabindex="0" aria-live="polite">
<div class="header-user">
<img src="https://i.pravatar.cc/100?u=<?= urlencode($_SESSION['username']) ?>" alt="Avatar" class="avatar" width="84" height="84" loading="lazy" />
<div>
<h1>Welcome back, <?= htmlspecialchars($_SESSION['username']) ?>!</h1>
<p>Your Member Dashboard</p>
</div>
</div>
<div class="messages" role="alert" aria-live="polite">
<?php foreach ($messages as $msg): ?>
<div class="alert alert-<?= htmlspecialchars($msg['type']) ?> alert-dismissible fade show" role="alert">
<?= $msg['text'] ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endforeach; ?>
</div>
<section class="mb-5" aria-label="Currently Borrowed Books Overview">
<h2 class="section-title">Currently Borrowed Books</h2>
<?php if (!$currentBorrowedBooks): ?>
<div class="alert alert-info d-flex align-items-center" role="alert">
<i class="fa-solid fa-book-open-reader me-2"></i>
<div>You currently have no borrowed books.</div>
</div>
<?php else: ?>
<div class="row g-4" aria-live="polite">
<?php foreach ($currentBorrowedBooks as $book): ?>
<article class="col-sm-6 col-md-4 col-lg-3" role="group" aria-label="<?= htmlspecialchars($book['title']) ?>">
<div class="card-book shadow-sm">
<div>
<h5>
<?= htmlspecialchars($book['title']) ?>
<?php if ($book['due_soon']): ?>
<span class="due-soon" title="Due within 3 days!">Due Soon</span>
<?php endif; ?>
</h5>
<p class="author">by <?= htmlspecialchars($book['author']) ?></p>
<p><strong>Borrowed:</strong> <?= date('M j, Y', strtotime($book['borrow_date'])) ?></p>
<p><strong>Due:</strong> <?= date('M j, Y', strtotime($book['due_date'])) ?></p>
<?php if ((int)$book['fine'] > 0): ?>
<span class="fine-badge" title="Overdue fine">Overdue Fine: $<?= number_format($book['fine'], 2) ?></span>
<?php endif; ?>
</div>
<button type="button" class="btn-return mt-3 btn btn-danger w-100" data-bs-toggle="modal" data-bs-target="#returnModal<?= $book['borrow_id'] ?>" title="Return Book">
<i class="fa-solid fa-rotate-left me-1"></i> Return Book
</button>
<!-- Return Confirmation Modal -->
<div class="modal fade" id="returnModal<?= $book['borrow_id'] ?>" tabindex="-1" aria-labelledby="returnLabel<?= $book['borrow_id'] ?>" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content rounded-4">
<div class="modal-header">
<h5 class="modal-title" id="returnLabel<?= $book['borrow_id'] ?>">Confirm Return</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to return <strong><?= htmlspecialchars($book['title']) ?></strong>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<a href="return.php?id=<?= $book['borrow_id'] ?>" class="btn btn-danger">Confirm Return</a>
</div>
</div>
</div>
</div>
</div>
</article>
<?php endforeach; ?>
</div>
<?php endif; ?>
</section>
</section>
<!-- Borrowed Books Tab (Detailed List) -->
<section class="tab-pane fade" id="borrowedBooks" role="tabpanel" aria-labelledby="borrowedBooks-tab" tabindex="0">
<h2 class="section-title mb-4">Your Borrowed Books</h2>
<?php if (!$currentBorrowedBooks): ?>
<div class="alert alert-info d-flex align-items-center" role="alert">
<i class="fa-solid fa-book-reader me-2"></i> No current borrowed books found.
</div>
<?php else: ?>
<div class="table-responsive shadow-sm rounded-4">
<table class="table table-striped align-middle mb-0">
<thead>
<tr>
<th scope="col">Title & Author</th>
<th scope="col">Borrow Date</th>
<th scope="col">Due Date</th>
<th scope="col">Fine</th>
<th scope="col" class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($currentBorrowedBooks as $book): ?>
<tr>
<td>
<strong><?= htmlspecialchars($book['title']) ?></strong><br/>
<em class="text-muted"><?= htmlspecialchars($book['author']) ?></em>
</td>
<td><?= date('M j, Y', strtotime($book['borrow_date'])) ?></td>
<td>
<?= date('M j, Y', strtotime($book['due_date'])) ?>
<?php if ($book['due_soon']): ?>
<span class="badge bg-warning text-dark ms-2" data-bs-toggle="tooltip" data-bs-placement="top" title="Due Soon">⚠</span>
<?php endif; ?>
</td>
<td>
<?php if ($book['fine'] > 0): ?>
<span class="text-danger fw-semibold">$<?= number_format($book['fine'], 2) ?></span>
<?php else: ?>
<span class="text-muted">-</span>
<?php endif; ?>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger" data-bs-toggle="modal" data-bs-target="#returnModalTable<?= $book['borrow_id'] ?>" aria-label="Return <?= htmlspecialchars($book['title']) ?>">
<i class="fa-solid fa-rotate-left me-1"></i> Return
</button>
<!-- Modal -->
<div class="modal fade" id="returnModalTable<?= $book['borrow_id'] ?>" tabindex="-1" aria-labelledby="returnLabelTable<?= $book['borrow_id'] ?>" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content rounded-4">
<div class="modal-header">
<h5 class="modal-title" id="returnLabelTable<?= $book['borrow_id'] ?>">Confirm Return</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to return <strong><?= htmlspecialchars($book['title']) ?></strong>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<a href="return.php?id=<?= $book['borrow_id'] ?>" class="btn btn-danger">Confirm Return</a>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</section>
<!-- Search & Borrow Tab -->
<section class="tab-pane fade" id="searchBooks" role="tabpanel" aria-labelledby="searchBooks-tab" tabindex="0">
<h2 class="section-title mb-3">Search & Borrow Books</h2>
<form method="get" class="search-bar d-flex mb-4" role="search" autocomplete="off" aria-label="Search books form">
<input type="search" name="search" class="form-control me-2" placeholder="Search books by title or author..." aria-label="Search books" value="<?= htmlspecialchars($search) ?>" />
<button class="btn btn-primary" type="submit" aria-label="Search books">Search</button>
<?php if($searchActive): ?>
<a href="member_dashboard.php#searchBooks" class="btn btn-outline-secondary ms-2" aria-label="Clear search">Clear</a>
<?php endif; ?>
</form>
<?php if (!$availableBooks): ?>
<div class="alert alert-warning d-flex align-items-center" role="alert">
<i class="fa-solid fa-circle-exclamation me-2"></i>
<div>No books available matching your search criteria.</div>
</div>
<?php else: ?>
<div class="row g-4" aria-live="polite" aria-label="Available books to borrow">
<?php foreach($availableBooks as $book): ?>
<article class="col-sm-6 col-md-4 col-lg-3" role="group" aria-label="<?= htmlspecialchars($book['title']) ?>">
<div class="card-book shadow-sm d-flex flex-column justify-content-between">
<div>
<h5><?= htmlspecialchars($book['title']) ?></h5>
<p class="author">by <?= htmlspecialchars($book['author']) ?></p>
<p class="fw-semibold"><i class="fa-solid fa-book"></i> Available Copies: <?= (int)$book['available_copies'] ?></p>
</div>
<button type="button" class="btn-borrow btn btn-primary mt-3" data-bs-toggle="modal" data-bs-target="#borrowModal<?= $book['id'] ?>" aria-label="Borrow <?= htmlspecialchars($book['title']) ?>">
<i class="fa-solid fa-circle-plus me-1"></i> Borrow
</button>
<!-- Borrow Confirmation Modal -->
<div class="modal fade" id="borrowModal<?= $book['id'] ?>" tabindex="-1" aria-labelledby="borrowLabel<?= $book['id'] ?>" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content rounded-4">
<div class="modal-header">
<h5 class="modal-title" id="borrowLabel<?= $book['id'] ?>">Confirm Borrow</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Do you want to borrow <strong><?= htmlspecialchars($book['title']) ?></strong> by <?= htmlspecialchars($book['author']) ?>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<a href="borrow.php?id=<?= $book['id'] ?>" class="btn btn-primary">Confirm Borrow</a>
</div>
</div>
</div>
</div>
</div>
</article>
<?php endforeach; ?>
</div>
<?php if ($totalPages > 1): ?>
<nav class="pagination-nav" aria-label="Page navigation">
<ul class="pagination">
<?php
$queryParams = $_GET;
for ($i = 1; $i <= $totalPages; $i++):
$queryParams['page'] = $i;
$url = htmlspecialchars($_SERVER['PHP_SELF'] . '?' . http_build_query($queryParams)) . '#searchBooks';
?>
<li class="page-item <?= ($i === $page)? 'active' : '' ?>">
<a class="page-link" href="<?= $url ?>" aria-current="<?= ($i === $page)? 'page' : 'false' ?>"><?= $i ?></a>
</li>
<?php endfor; ?>
</ul>
</nav>
<?php endif; ?>
<?php endif; ?>
</section>
<!-- Borrow History Tab -->
<section class="tab-pane fade" id="borrowHistory" role="tabpanel" aria-labelledby="history-tab" tabindex="0">
<h2 class="section-title mb-4">Borrow History (Last 20 records)</h2>
<?php if (!$borrowHistory): ?>
<div class="alert alert-info d-flex align-items-center" role="alert">
<i class="fa-solid fa-folder-open me-2"></i> No borrow history found.
</div>
<?php else: ?>
<div class="table-responsive shadow-sm rounded-4">
<table class="borrow-history table mb-0">
<thead>
<tr>
<th scope="col">Title & Author</th>
<th scope="col">Borrow Date</th>
<th scope="col">Due Date</th>
<th scope="col">Return Date</th>
<th scope="col">Fine</th>
</tr>
</thead>
<tbody>
<?php foreach ($borrowHistory as $record): ?>
<tr>
<td>
<strong><?= htmlspecialchars($record['title']) ?></strong><br/>
<em class="text-muted"><?= htmlspecialchars($record['author']) ?></em>
</td>
<td><?= date('M j, Y', strtotime($record['borrow_date'])) ?></td>
<td><?= date('M j, Y', strtotime($record['due_date'])) ?></td>
<td><?= date('M j, Y', strtotime($record['return_date'])) ?></td>
<td>
<?php if ($record['fine'] > 0): ?>
<span class="text-danger fw-semibold">$<?= number_format($record['fine'], 2) ?></span>
<?php else: ?>
<span class="text-muted">-</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</section>
<!-- Profile Section -->
<section class="tab-pane fade" id="profileSection" role="tabpanel" aria-labelledby="profile-tab" tabindex="0">
<h2 class="section-title mb-4">Your Profile</h2>
<form method="post" action="profile_update.php" class="needs-validation" novalidate aria-label="Profile update form">
<div class="mb-4">
<label for="usernameInput" class="form-label">Username</label>
<input type="text" class="form-control" name="username" id="usernameInput" value="<?= htmlspecialchars($_SESSION['username']) ?>" required aria-describedby="usernameHelp" />
<div class="invalid-feedback">Username is required and must be valid.</div>
</div>
<div class="mb-4">
<label for="passwordInput" class="form-label">New Password (optional)</label>
<input type="password" class="form-control" name="password" id="passwordInput" placeholder="Enter new password" aria-describedby="passwordHelp" />
</div>
<div class="mb-4">
<label for="passwordConfirmInput" class="form-label">Confirm New Password</label>
<input type="password" class="form-control" name="password_confirm" id="passwordConfirmInput" placeholder="Repeat new password" />
<div class="invalid-feedback" id="password-mismatch-feedback">Passwords do not match.</div>
</div>
<button type="submit" class="btn btn-primary" aria-live="polite">Save Changes</button>
</form>
</section>
</div><!-- /.tab-content -->
</main><!-- /.main-content -->
</div><!-- /.d-flex -->
<!-- Bootstrap JS + Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
(() => {
'use strict';
// Initialize Bootstrap tooltips
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
// Bootstrap tab activation from sidebar links with hash routing support
const tabLinks = document.querySelectorAll('.sidebar a[data-bs-toggle="tab"]');
const tabPanes = document.querySelectorAll('.tab-pane');
function activateTabByHash(hash) {
if (!hash) return;
const link = Array.from(tabLinks).find(a => a.getAttribute('href') === hash);
if (link) {
tabLinks.forEach(l => l.classList.remove('active'));
tabPanes.forEach(p => p.classList.remove('show', 'active'));
link.classList.add('active');
const target = document.querySelector(hash);
if (target) {
target.classList.add('show', 'active');
target.focus();
window.scrollTo({top: 0, behavior: 'smooth'});
}
}
}
tabLinks.forEach(link => {
link.addEventListener('click', e => {
e.preventDefault();
const targetHash = link.getAttribute('href');
history.pushState(null, '', targetHash);
activateTabByHash(targetHash);
});
});
// Activate tab based on current URL hash on page load
activateTabByHash(window.location.hash || '#dashboard');
// Bootstrap form validation for profile update
const form = document.querySelector('form.needs-validation');
if(form){
const passwordInput = document.getElementById('passwordInput');
const passwordConfirmInput = document.getElementById('passwordConfirmInput');
const passwordMismatchFeedback = document.getElementById('password-mismatch-feedback');
form.addEventListener('submit', event => {
// Reset mismatch feedback visibility
passwordMismatchFeedback.style.display = 'none';
passwordConfirmInput.classList.remove('is-invalid');
// Check validity of form native validation
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
form.classList.add('was-validated');
return;
}
// If password fields are filled, validate matching
const pw = passwordInput.value.trim();
const pwConfirm = passwordConfirmInput.value.trim();
if (pw !== '' || pwConfirm !== '') {
if (pw !== pwConfirm) {
event.preventDefault();
event.stopPropagation();
passwordConfirmInput.classList.add('is-invalid');
passwordMismatchFeedback.style.display = 'block';
form.classList.add('was-validated');
} else {
passwordConfirmInput.classList.remove('is-invalid');
passwordMismatchFeedback.style.display = 'none';
}
}
});
}
})();
</script>
<?php require 'footer.php'; ?>
Enhancements Summary:
- Sidebar: Collapsible-ish with icons, color highlight on active link, sticky on desktop, horizontal scroll on mobile.
- Header User: Enlarged avatar with hover effect, bigger greeting text.
- Cards and Tables: Modern card shadows, smooth hover transformations, icons for clarity.
- Buttons: Rounded modern buttons with icons for "Borrow" and "Return" actions.
- Modals: Confirm borrow/return actions via Bootstrap modals instead of simple JS confirm — better UI/UX.
- Alerts: Dismissable Bootstrap alerts for action messages.
- Search Bar: Styled, responsive with clear button.
- Pagination: Styled pagination with active state.
- Forms: Better styling, bigger inputs, client validation, password mismatch check with feedback.
- Accessibility: ARIA roles, live regions, keyboard focus for tabs.
- Responsiveness: Sidebar adapts for mobile, main content padding adjusted for smaller screen.
- FontAwesome Icons: Clear visuals to the user's actions and sections.
- Tooltip: On due soon badge for info.
- Subtle animations and transitions for hover states for smooth feel.
Notes:
- You need FontAwesome CSS for icons; I included from CDN.
- Ensure your
header.php includes Bootstrap 5 CSS and appropriate meta viewport tags.
- The body content is clean, semantic, and accessible.
- Modals improve user confirmation workflows rather than browser native confirm()
- Tabs state synchronizes with URL hash for deep linking.
- The code uses Bootstrap classes extensively for rapid UI styling and responsiveness.
If you want me to help with header.php or footer.php or any backend integrations like return.php or borrow.php, just ask!