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

Commit 444a140

Browse files
committed
at last
1 parent ad7f9c3 commit 444a140

15 files changed

Lines changed: 242 additions & 21 deletions

.idea/data_source_mapping.xml

Lines changed: 3 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
include 'includes/db.php';
3+
include 'includes/functions.php';
34
/** @var mysqli $conn */
45
session_start();
56

@@ -66,7 +67,7 @@
6667
<div class="promo-banner shadow-sm">
6768
<h2 class="fw-bold">Welcome, <?php echo e($user_name); ?>!</h2>
6869
<p class="lead">What would you like to read today?</p>
69-
<button class="btn btn-light btn-lg text-success fw-bold">View New Arrivals</button>
70+
<a href="new_arrivals.php" class="btn btn-light btn-lg text-success fw-bold">View New Arrivals</a>
7071
</div>
7172

7273
<div class="mt-4">

admin/add_book.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<a href="add_book.php" class="active">Add New Book</a>
102102
<a href="manage_users.php">Manage Users</a>
103103
<a href="view_books.php">View Bookshelf</a>
104+
<a href="fine_settings.php">Monitor User Fines</a>
104105
<hr class="text-secondary">
105106
<a href="../logout.php" class="text-danger">Logout</a>
106107
</nav>

admin/dashboard.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<a href="add_book.php">Add New Book</a>
5454
<a href="manage_users.php">Manage Users</a>
5555
<a href="view_books.php">View Bookshelf</a>
56+
<a href="fine_settings.php">Monitor User Fines</a>
5657
<hr>
5758
<a href="../logout.php" class="text-danger">Logout</a>
5859
</nav>

admin/edit_book.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
include "../includes/admin_auth.php";
33
include '../includes/db.php';
4+
include '../includes/functions.php';
45
/** @var mysqli $conn * */
56

67
$message = "";
@@ -98,6 +99,7 @@
9899
<a href="dashboard.php">Dashboard</a>
99100
<a href="add_book.php">Add New Book</a>
100101
<a href="view_books.php" class="bg-primary text-white">View Bookshelf</a>
102+
<a href="fine_settings.php">Monitor User Fines</a>
101103
<hr>
102104
<a href="../logout.php" class="text-danger">Logout</a>
103105
</nav>

admin/fine_settings.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
include '../includes/admin_auth.php';
3+
include '../includes/db.php';
4+
include_once '../includes/functions.php';
5+
/** @var mysqli $conn **/
6+
7+
$message = "";
8+
9+
// Update the fine rate
10+
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
11+
$new_rate = $_POST['fine_rate'];
12+
$stmt = $conn->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'fine_rate'");
13+
$stmt->bind_param("s", $new_rate);
14+
15+
if ($stmt->execute()) {
16+
$message = "<div class='alert alert-success'>Fine rate updated successfully!</div>";
17+
}
18+
}
19+
20+
// Get the current rate to display in the input
21+
$res = $conn->query("SELECT setting_value FROM settings WHERE setting_key = 'fine_rate'");
22+
$current_rate = $res->fetch_assoc()['setting_value'];
23+
?>
24+
25+
<!DOCTYPE html>
26+
<html lang="en">
27+
<head>
28+
<meta charset="UTF-8">
29+
<title>Fine Settings | Admin Panel</title>
30+
<link rel="stylesheet" href="../assets/css/bootstrap.min.css">
31+
<style>
32+
body { background-color: #f8f9fa; }
33+
.sidebar { min-height: 100vh; background-color: #212529; position: fixed; width: 16.666667%; padding-top: 20px; }
34+
.sidebar a { color: #adb5bd; padding: 12px 20px; display: block; text-decoration: none; }
35+
.sidebar a.active { background-color: #007bff; color: white; }
36+
.main-content { margin-left: 16.666667%; padding: 40px; }
37+
</style>
38+
</head>
39+
<body>
40+
<div class="container-fluid">
41+
<div class="row">
42+
<nav class="col-md-2 d-none d-md-block sidebar">
43+
<h4 class="text-center fw-bold mb-4 text-primary">Admin Panel</h4>
44+
<a href="dashboard.php">Dashboard</a>
45+
<a href="add_book.php">Add New Book</a>
46+
<a href="manage_users.php">Manage Users</a>
47+
<a href="view_books.php">View Bookshelf</a>
48+
<a href="fine_settings.php" class="active">Fine Settings</a>
49+
<hr class="text-secondary">
50+
<a href="../logout.php" class="text-danger">Logout</a>
51+
</nav>
52+
53+
<main class="col-md-10 ms-sm-auto px-md-4 main-content">
54+
<h2 class="fw-bold mb-4">Edit Daily Fine Amount</h2>
55+
<?php echo $message; ?>
56+
57+
<div class="card shadow-sm p-4" style="max-width: 500px;">
58+
<form method="POST">
59+
<div class="mb-3">
60+
<label class="form-label fw-bold">Daily Fine Rate ($)</label>
61+
<input type="number" step="0.01" name="fine_rate" class="form-control" value="<?php echo e($current_rate); ?>" required>
62+
<div class="form-text">Example: 0.50 for 50 cents per day.</div>
63+
</div>
64+
<button type="submit" class="btn btn-primary">Update Rate</button>
65+
</form>
66+
</div>
67+
</main>
68+
</div>
69+
</div>
70+
</body>
71+
</html>

admin/manage_users.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
include "../includes/admin_auth.php";
33
include '../includes/db.php';
4+
include '../includes/functions.php';
45
/** @var mysqli $conn * */
56

67
// Handle User Deletion logic if needed
@@ -75,6 +76,7 @@
7576
<a href="add_book.php">Add New Book</a>
7677
<a href="manage_users.php" class="active">Manage Users</a>
7778
<a href="view_books.php">View Bookshelf</a>
79+
<a href="fine_settings.php">Monitor User Fines</a>
7880
<hr class="text-secondary">
7981
<a href="../logout.php" class="text-danger">Logout</a>
8082
</nav>

admin/new_arrivals.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
include '../includes/admin_auth.php'; // Admin files use ../
3+
include '../includes/db.php';
4+
include_once '../includes/functions.php';
5+
6+
// Fetch "Hot" books based on the number of times they appear in transactions
7+
$query = "SELECT b.title, b.author, COUNT(t.book_id) as borrow_count
8+
FROM books b
9+
JOIN transactions t ON b.id = t.book_id
10+
GROUP BY b.id
11+
ORDER BY borrow_count DESC LIMIT 5";
12+
$result = $conn->query($query);
13+
?>
14+
<!DOCTYPE html>
15+
<html lang="en">
16+
<head>
17+
<meta charset="UTF-8">
18+
<title>Hot Books | Admin Panel</title>
19+
<link rel="stylesheet" href="../assets/css/bootstrap.min.css">
20+
<style>
21+
body { background-color: #f8f9fa; }
22+
.sidebar { min-height: 100vh; background-color: #212529; position: fixed; width: 16.666667%; padding-top: 20px; }
23+
.sidebar a { color: #adb5bd; padding: 12px 20px; display: block; text-decoration: none; }
24+
.sidebar a.active { background-color: #007bff; color: white; }
25+
.main-content { margin-left: 16.666667%; padding: 40px; } /* Matches padding */
26+
</style>
27+
</head>
28+
<body>
29+
<div class="container-fluid">
30+
<div class="row">
31+
<nav class="col-md-2 d-none d-md-block sidebar">
32+
<h4 class="text-center fw-bold mb-4 text-primary">Admin Panel</h4>
33+
<a href="dashboard.php">Dashboard</a>
34+
<a href="view_books.php">View Bookshelf</a>
35+
<a href="new_arrivals.php" class="active">Hot Books</a>
36+
<hr class="text-secondary">
37+
<a href="../logout.php" class="text-danger">Logout</a>
38+
</nav>
39+
40+
<main class="col-md-10 ms-sm-auto px-md-4 main-content">
41+
<h2 class="fw-bold mb-4 text-dark">Trending Books (Hot Now)</h2>
42+
<div class="card border-0 shadow-sm p-3">
43+
<table class="table table-hover align-middle">
44+
<thead class="table-dark">
45+
<tr>
46+
<th>Book Title</th>
47+
<th>Author</th>
48+
<th>Times Borrowed</th>
49+
<th>Popularity</th>
50+
</tr>
51+
</thead>
52+
<tbody>
53+
<?php while($row = $result->fetch_assoc()): ?>
54+
<tr>
55+
<td class="fw-bold"><?php echo e($row['title']); ?></td>
56+
<td><?php echo e($row['author']); ?></td>
57+
<td><span class="badge bg-primary"><?php echo $row['borrow_count']; ?> times</span></td>
58+
<td>
59+
<div class="progress" style="height: 10px;">
60+
<div class="progress-bar bg-warning" style="width: <?php echo ($row['borrow_count'] * 10); ?>%"></div>
61+
</div>
62+
</td>
63+
</tr>
64+
<?php endwhile; ?>
65+
</tbody>
66+
</table>
67+
</div>
68+
</main>
69+
</div>
70+
</div>
71+
</body>
72+
</html>

admin/view_books.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
include "../includes/admin_auth.php";
33
include '../includes/db.php';
4+
include '../includes/functions.php';
5+
46
/** @var mysqli $conn * */
57

68
// 1. Fetch all books
@@ -65,6 +67,7 @@
6567
<a href="add_book.php">Add New Book</a>
6668
<a href="manage_users.php">Manage Users</a>
6769
<a href="view_books.php" class="active">View Bookshelf</a>
70+
<a href="fine_settings.php">Monitor User Fines</a>
6871
<hr class="text-secondary">
6972
<a href="../logout.php" class="text-danger">Logout</a>
7073
</nav>

dashboard.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?php
22
include 'includes/db.php';
3+
include 'includes/functions.php';
34
/** @var mysqli $conn * */
45
session_start();
56

6-
// 1. SECURITY CHECK: Ensure user is logged in
7+
78
if (!isset($_SESSION['user_id'])) {
89
header("Location: Login.php");
910
exit();
1011
}
1112

1213
$user_id = $_SESSION['user_id'];
1314

14-
// 2. FETCH USER DATA: Combining first and last name
1515
$user_query = "SELECT first_name, last_name FROM users WHERE id = ?";
1616
$stmt = $conn->prepare($user_query);
1717
$stmt->bind_param("i", $user_id);
@@ -20,15 +20,13 @@
2020
$user_name = $user_data ? $user_data['first_name'] . " " . $user_data['last_name'] : "Guest";
2121
$stmt->close();
2222

23-
// 3. FETCH STATS: Count active 'borrowed' transactions for this user
2423
$stats_query = "SELECT COUNT(*) as total FROM transactions WHERE user_id = ? AND status = 'borrowed'";
2524
$stmt = $conn->prepare($stats_query);
2625
$stmt->bind_param("i", $user_id);
2726
$stmt->execute();
2827
$borrowed_count = $stmt->get_result()->fetch_assoc()['total'];
2928
$stmt->close();
3029

31-
// 4. FETCH CURRENT LOANS: Joining with 'books' table to get Titles
3230
$loans_query = "SELECT t.id, t.book_id, b.title, t.issue_date, t.return_date, t.status
3331
FROM transactions t
3432
JOIN books b ON t.book_id = b.id

0 commit comments

Comments
 (0)