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 pathHome.php
More file actions
127 lines (111 loc) · 5.78 KB
/
Home.php
File metadata and controls
127 lines (111 loc) · 5.78 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
<?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 FROM users WHERE id = ?";
$stmt = $conn->prepare($user_query);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$user_name = ($row = $result->fetch_assoc()) ? $row['first_name'] : "Guest";
$stmt->close();
// CHANGE 1: Added 'image' to the SELECT query
$book_query = "SELECT id, title, author, isbn, status, image FROM books";
$books_result = $conn->query($book_query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home - Library System</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<style>
body { background-color: #f4f7f6; }
.sidebar { min-height: 100vh; background-color: #f8f9fa; border-right: 1px solid #dee2e6; padding-top: 20px; position: fixed; width: 16.666667%; }
.main-content { margin-left: 16.666667%; }
.promo-banner { background: linear-gradient(45deg, #198754, #20c997); color: white; border-radius: 15px; padding: 40px; margin-bottom: 30px; }
.book-card { transition: transform 0.2s; border: none; }
.book-card:hover { transform: translateY(-5px); }
.book-card img { height: 250px; object-fit: cover; background-color: #eee; }
</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 active">Home</a>
<a href="dashboard.php" class="btn btn-outline-success">My Dashboard</a>
<a href="search.php" class="btn btn-outline-success">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 main-content">
<div class="pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Library Home</h1>
</div>
<div class="promo-banner shadow-sm">
<h2 class="fw-bold">Welcome, <?php echo e($user_name); ?>!</h2>
<p class="lead">What would you like to read today?</p>
<a href="new_arrivals.php" class="btn btn-light btn-lg text-success fw-bold">View New Arrivals</a>
</div>
<div class="mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h3 class="fw-bold">Explore Our Collection</h3>
<a href="search.php" class="text-success text-decoration-none fw-bold">View All Books →</a>
</div>
<div class="row row-cols-1 row-cols-md-3 row-cols-lg-4 g-4 mb-5">
<?php if ($books_result && $books_result->num_rows > 0): ?>
<?php while ($book = $books_result->fetch_assoc()): ?>
<div class="col">
<div class="card h-100 book-card shadow-sm">
<img src="image/<?php echo e($book['image']); ?>"
class="card-img-top"
alt="Book Cover"
onerror="this.src='https://via.placeholder.com/300x400?text=<?php echo urlencode($book['title']); ?>'">
<div class="card-body d-flex flex-column">
<h5 class="card-title mb-1 text-truncate"><?php echo e($book['title']); ?></h5>
<p class="text-muted small mb-2">by <?php echo e($book['author']); ?></p>
<div class="mb-3">
<?php if ($book['status'] === 'Available'): ?>
<span class="badge bg-success">Available</span>
<?php else: ?>
<span class="badge bg-danger">Borrowed</span>
<?php endif; ?>
</div>
<div class="mt-auto d-grid">
<?php if ($book['status'] === 'Available'): ?>
<a href="borrow.php?book_id=<?php echo $book['id']; ?>"
class="btn btn-primary btn-sm">Borrow Now</a>
<?php else: ?>
<button class="btn btn-secondary btn-sm" disabled>Unavailable</button>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<div class="col-12 text-center py-5">
<p class="text-muted">The library shelves are currently empty. Please check back later!</p>
</div>
<?php endif; ?>
</div>
</div>
</main>
</div>
</div>
<script src="assets/js/bootstrap.bundle.min.js"></script>
</body>
</html>