11<?php
22include 'db.php ' ;
3- /** @var mysqli $conn * * /
3+ /** @var mysqli $conn */
44session_start ();
55
66if (!isset ($ _SESSION ['user_id ' ])) {
99}
1010
1111$ user_id = $ _SESSION ['user_id ' ];
12-
13- $ query = "SELECT first_name FROM users WHERE id = ? " ;
14- $ stmt = $ conn ->prepare ($ query );
12+ $ user_query = "SELECT first_name FROM users WHERE id = ? " ;
13+ $ stmt = $ conn ->prepare ($ user_query );
1514$ stmt ->bind_param ("i " , $ user_id );
1615$ stmt ->execute ();
1716$ result = $ stmt ->get_result ();
1817$ user_name = ($ row = $ result ->fetch_assoc ()) ? $ row ['first_name ' ] : "Guest " ;
18+ $ stmt ->close ();
19+
20+ $ book_query = "SELECT id, title, author, isbn, status FROM books " ;
21+ $ books_result = $ conn ->query ($ book_query );
1922
20- function e ($ text ): string {
23+ function e ($ text ): string
24+ {
2125 return htmlspecialchars ($ text , ENT_QUOTES , 'UTF-8 ' );
2226}
27+
2328?>
2429
2530<!DOCTYPE html>
@@ -30,61 +35,124 @@ function e ($text): string {
3035 <title>Home - Library System</title>
3136 <link rel="stylesheet" href="assets/css/bootstrap.min.css">
3237 <style>
33- .sidebar { min-height: 100vh; background-color: #f8f9fa; border-right: 1px solid #dee2e6; padding-top: 20px; }
34- .promo-banner { background: linear-gradient(45deg, #198754, #20c997); color: white; border-radius: 15px; padding: 40px; margin-bottom: 30px; }
35- .book-card img { height: 250px; object-fit: cover; }
38+ body {
39+ background-color: #f4f7f6;
40+ }
41+
42+ .sidebar {
43+ min-height: 100vh;
44+ background-color: #f8f9fa;
45+ border-right: 1px solid #dee2e6;
46+ padding-top: 20px;
47+ }
48+
49+ .main-content {
50+ margin-left: 16.666667%;
51+ }
52+
53+ /* Offsets the content because sidebar is fixed */
54+ .promo-banner {
55+ background: linear-gradient(45deg, #198754, #20c997);
56+ color: white;
57+ border-radius: 15px;
58+ padding: 40px;
59+ margin-bottom: 30px;
60+ }
61+
62+ .book-card {
63+ transition: transform 0.2s;
64+ border: none;
65+ }
66+
67+ .book-card:hover {
68+ transform: translateY(-5px);
69+ }
70+
71+ .book-card img {
72+ height: 250px;
73+ object-fit: cover;
74+ background-color: #eee;
75+ }
3676 </style>
3777</head>
3878<body>
3979<div class="container-fluid">
4080 <div class="row">
4181 <nav class="col-md-2 d-none d-md-block sidebar">
4282 <div class="text-center mb-4">
43- <h5 class="fw-bold">Library Management System</h5>
83+ <h5 class="fw-bold text-success text-wrap px-2">
84+ Library Management System
85+ </h5>
4486 </div>
4587 <div class="d-grid gap-2 px-3">
46- <a href="Home.php" class="btn btn-success">Home</a>
47- <a href="dashboard.php" class="btn btn-outline-success">My Dashboard</a>
48- <a href="search.php" class="btn btn-outline-success">Search Books</a>
88+ <a href="Home.php"
89+ class="btn btn-outline-success <?php echo (basename ($ _SERVER ['PHP_SELF ' ]) == 'Home.php ' ) ? 'active ' : '' ; ?> ">Home</a>
90+ <a href="dashboard.php"
91+ class="btn btn-outline-success <?php echo (basename ($ _SERVER ['PHP_SELF ' ]) == 'dashboard.php ' ) ? 'active ' : '' ; ?> ">My
92+ Dashboard</a>
93+ <a href="search.php"
94+ class="btn btn-outline-success <?php echo (basename ($ _SERVER ['PHP_SELF ' ]) == 'search.php ' ) ? 'active ' : '' ; ?> ">Search
95+ Books</a>
4996 <hr>
5097 <a href="logout.php?user_id=<?php echo $ user_id ?> " class="btn btn-danger">Logout</a>
5198 </div>
5299 </nav>
53- <main class="col-md-10 ms-sm-auto px-md-4">
100+
101+ <main class="col-md-10 ms-sm-auto px-md-4 main-content">
54102 <div class="pt-3 pb-2 mb-3 border-bottom">
55103 <h1 class="h2">Library Home</h1>
56104 </div>
57105
58- <div class="promo-banner shadow-sm d-flex align-items-center justify-content-between">
59- <div>
60- <h2 class="fw-bold">Welcome, <?php echo e ($ user_name ); ?> !</h2>
61- <p class="lead">Explore digital and physical books available today.</p>
62- <button class="btn btn-light btn-lg text-success fw-bold">View New Arrivals</button>
63- </div>
106+ <div class="promo-banner shadow-sm">
107+ <h2 class="fw-bold">Welcome, <?php echo e ($ user_name ); ?> !</h2>
108+ <p class="lead">What would you like to read today?</p>
109+ <button class="btn btn-light btn-lg text-success fw-bold">View New Arrivals</button>
64110 </div>
65111
66112 <div class="mt-4">
67113 <div class="d-flex justify-content-between align-items-center mb-4">
68- <h3 class="fw-bold">Featured Books </h3>
69- <a href="search.php" class="text-success text-decoration-none">View All</a>
114+ <h3 class="fw-bold">Explore Our Collection </h3>
115+ <a href="search.php" class="text-success text-decoration-none fw-bold ">View All Books → </a>
70116 </div>
71117
72- <div class="row row-cols-1 row-cols-md-3 row-cols-lg-4 g-4">
73- <div class="col">
74- <div class="card h-100 book-card border-0 shadow-sm">
75- <img src="https://via.placeholder.com/300x400?text=PHP+Mastery" class="card-img-top" alt="Book Cover">
76- <div class="card-body">
77- <h5 class="card-title mb-1">Introduction to PHP</h5>
78- <p class="text-muted small">by John Smith</p>
79- <span class="badge bg-success mb-3">Available</span>
80- <div class="d-grid">
81- <button class="btn btn-primary btn-sm">Borrow Now</button>
118+ <div class="row row-cols-1 row-cols-md-3 row-cols-lg-4 g-4 mb-5">
119+ <?php if ($ books_result && $ books_result ->num_rows > 0 ): ?>
120+ <?php while ($ book = $ books_result ->fetch_assoc ()): ?>
121+ <div class="col">
122+ <div class="card h-100 book-card shadow-sm">
123+ <img src="https://via.placeholder.com/300x400?text=<?php echo urlencode ($ book ['title ' ]); ?> "
124+ class="card-img-top" alt="Book Cover">
125+
126+ <div class="card-body d-flex flex-column">
127+ <h5 class="card-title mb-1 text-truncate"><?php echo e ($ book ['title ' ]); ?> </h5>
128+ <p class="text-muted small mb-2">by <?php echo e ($ book ['author ' ]); ?> </p>
129+
130+ <div class="mb-3">
131+ <?php if ($ book ['status ' ] === 'Available ' ): ?>
132+ <span class="badge bg-success">Available</span>
133+ <?php else : ?>
134+ <span class="badge bg-danger">Borrowed</span>
135+ <?php endif ; ?>
136+ </div>
137+
138+ <div class="mt-auto d-grid">
139+ <?php if ($ book ['status ' ] === 'Available ' ): ?>
140+ <a href="borrow.php?book_id=<?php echo $ book ['id ' ]; ?> "
141+ class="btn btn-primary btn-sm">Borrow Now</a>
142+ <?php else : ?>
143+ <button class="btn btn-secondary btn-sm" disabled>Unavailable</button>
144+ <?php endif ; ?>
145+ </div>
146+ </div>
82147 </div>
83148 </div>
149+ <?php endwhile ; ?>
150+ <?php else : ?>
151+ <div class="col-12 text-center py-5">
152+ <p class="text-muted">The library shelves are currently empty. Please check back later!</p>
84153 </div>
85- </div>
86-
87- </div>
154+ <?php endif ; ?>
155+ </div>
88156 </div>
89157 </main>
90158 </div>
0 commit comments