Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit b1596f8

Browse files
committed
commit
1 parent b23a87e commit b1596f8

6 files changed

Lines changed: 340 additions & 58 deletions

File tree

.idea/data_source_mapping.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Home.php

Lines changed: 102 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
include 'db.php';
3-
/** @var mysqli $conn * */
3+
/** @var mysqli $conn */
44
session_start();
55

66
if (!isset($_SESSION['user_id'])) {
@@ -9,17 +9,22 @@
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>

borrow.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
11
<?php
2+
session_start();
3+
include 'db.php';
4+
/** @var mysqli $conn */
5+
6+
// 1. Security Check: Only logged-in users can borrow
7+
if (!isset($_SESSION['user_id'])) {
8+
header("Location: login.php");
9+
exit();
10+
}
11+
12+
// 2. Capture the Book ID from the link (e.g., borrow.php?book_id=5)
13+
if (isset($_GET['book_id'])) {
14+
$book_id = (int)$_GET['book_id']; // Cast to integer for safety
15+
$user_id = $_SESSION['user_id'];
16+
17+
// 3. Automated Dates (Matching your table columns)
18+
$issue_date = date('Y-m-d');
19+
$return_date = date('Y-m-d', strtotime('+14 days'));
20+
$status = 'Borrowed';
21+
22+
// 4. Prepared Statement for your 'transactions' table
23+
$query = "INSERT INTO transactions (user_id, book_id, issue_date, return_date, status) VALUES (?, ?, ?, ?, ?)";
24+
$stmt = $conn->prepare($query);
25+
26+
// "ii" for two integers, "sss" for three strings (dates & status)
27+
$stmt->bind_param("iisss", $user_id, $book_id, $issue_date, $return_date, $status);
28+
29+
if ($stmt->execute()) {
30+
// Success! Go back to dashboard
31+
header("Location: dashboard.php?msg=borrow_success");
32+
} else {
33+
// Error handling
34+
echo "Error recording transaction: " . $stmt->error;
35+
}
36+
37+
$stmt->close();
38+
} else {
39+
// If no book was selected, send them to the search page
40+
header("Location: search.php");
41+
exit();
42+
}

0 commit comments

Comments
 (0)