-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_dashboard.php
More file actions
107 lines (97 loc) · 4.34 KB
/
Copy pathadmin_dashboard.php
File metadata and controls
107 lines (97 loc) · 4.34 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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'db.php';
require 'auth.php';
require_login();
require_role(['admin']); // Only admins can access this page
// Fetch summary counts
$roomsCount = $pdo->query("SELECT COUNT(*) FROM rooms")->fetchColumn();
$bookingsCount = $pdo->query("SELECT COUNT(*) FROM bookings")->fetchColumn();
$upcomingCount = $pdo->query("SELECT COUNT(*) FROM bookings WHERE check_in >= CURDATE() AND status != 'cancelled'")->fetchColumn();
$customersCount = $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'customer'")->fetchColumn();
$staffCount = $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'staff'")->fetchColumn();
// Fetch recent bookings
$recent = $pdo->query("
SELECT b.*, u.name, u.email, r.type, r.number
FROM bookings b
JOIN users u ON b.user_id = u.id
JOIN rooms r ON b.room_id = r.id
ORDER BY b.created_at DESC
LIMIT 10
")->fetchAll(PDO::FETCH_ASSOC);
?>
<?php require 'header.php'; ?>
<section class="container">
<h2>Admin Dashboard</h2>
<div class="grid" style="margin-top:10px;margin-bottom:20px">
<div class="card center"><div class="h1"><?= (int)$roomsCount ?></div><div class="muted">Rooms</div></div>
<div class="card center"><div class="h1"><?= (int)$bookingsCount ?></div><div class="muted">Bookings</div></div>
<div class="card center"><div class="h1"><?= (int)$upcomingCount ?></div><div class="muted">Upcoming</div></div>
<div class="card center"><div class="h1"><?= (int)$customersCount ?></div><div class="muted">Customers</div></div>
<div class="card center"><div class="h1"><?= (int)$staffCount ?></div><div class="muted">Staff</div></div>
</div>
<div class="card" style="margin-bottom:20px">
<h3>Quick Actions</h3>
<div class="flex" style="gap:10px">
<a class="btn" href="manage_rooms.php">Manage Rooms</a>
<a class="btn" href="admin_users.php">Manage Users</a>
</div>
</div>
<div class="card">
<h3>Recent Bookings</h3>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Guest</th>
<th>Room</th>
<th>Check-in</th>
<th>Check-out</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($recent as $r): ?>
<tr>
<td><?= (int)$r['id'] ?></td>
<td>
<?= htmlspecialchars($r['name']) ?><br>
<span class="muted small"><?= htmlspecialchars($r['email']) ?></span>
</td>
<td><?= htmlspecialchars($r['type']) ?> • <?= htmlspecialchars($r['number']) ?></td>
<td><?= htmlspecialchars($r['check_in']) ?></td>
<td><?= htmlspecialchars($r['check_out']) ?></td>
<td><?= htmlspecialchars($r['status']) ?></td>
<td>
<?php if ($r['status'] === 'pending'): ?>
<form method="post" action="admin_booking_action.php" style="display:inline-block; margin:0;">
<input type="hidden" name="booking_id" value="<?= (int)$r['id'] ?>">
<input type="hidden" name="action" value="approve">
<?php csrf_input(); ?>
<button class="btn small" type="submit">Approve</button>
</form>
<form method="post" action="admin_booking_action.php" style="display:inline-block; margin:0;">
<input type="hidden" name="booking_id" value="<?= (int)$r['id'] ?>">
<input type="hidden" name="action" value="deny">
<?php csrf_input(); ?>
<button class="btn red small" type="submit">Deny</button>
</form>
<?php elseif ($r['status'] === 'confirmed'): ?>
<form method="post" action="booking_cancel.php" onsubmit="return confirm('Are you sure you want to cancel this booking?')" style="margin:0">
<input type="hidden" name="booking_id" value="<?= (int)$r['id'] ?>">
<?php csrf_input(); ?>
<button class="btn red small" type="submit">Cancel</button>
</form>
<?php else: ?>
<span class="muted small"><?= htmlspecialchars(ucfirst($r['status'])) ?></span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</section>
<?php require 'footer.php'; ?>