Spaces:
Configuration error
Configuration error
File size: 15,564 Bytes
8df07b6 | 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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | ```php
<?php
include 'includes/auth.php';
redirectIfNotLoggedIn();
include 'config/database.php';
$db = new Database();
$connection = $db->getConnection();
if (isAdmin()) {
// Admin dashboard data
$statsQueries = [
'total_reports' => "SELECT COUNT(*) as count FROM reports",
'pending_verifications' => "SELECT COUNT(*) as count FROM verifications WHERE result = 'pending'",
'pending_claims' => "SELECT COUNT(*) as count FROM claims WHERE status = 'pending'",
'total_users' => "SELECT COUNT(*) as count FROM users"
];
$stats = [];
foreach ($statsQueries as $key => $query) {
$stmt = $connection->prepare($query);
$stmt->execute();
$stats[$key] = $stmt->fetch(PDO::FETCH_ASSOC)['count'];
}
// Recent activities
$activitiesQuery = "
(SELECT 'report' as type, reportID as id, timestamp as date, 'New report submitted' as description
FROM reports ORDER BY timestamp DESC LIMIT 5)
UNION
(SELECT 'claim' as type, claimId as id, createdAt as date, 'New claim submitted' as description
FROM claims ORDER BY createdAt DESC LIMIT 5)
ORDER BY date DESC LIMIT 10
";
$activitiesStmt = $connection->prepare($activitiesQuery);
$activitiesStmt->execute();
$activities = $activitiesStmt->fetchAll(PDO::FETCH_ASSOC);
} elseif (isFinder()) {
// Finder dashboard data
$userId = $_SESSION['user_id'];
// User's reports
$reportsQuery = "SELECT * FROM reports WHERE userId = :userId ORDER BY timestamp DESC LIMIT 5";
$reportsStmt = $connection->prepare($reportsQuery);
$reportsStmt->bindParam(':userId', $userId);
$reportsStmt->execute();
$userReports = $reportsStmt->fetchAll(PDO::FETCH_ASSOC);
// Notifications
$notificationsQuery = "SELECT * FROM notifications WHERE userId = :userId ORDER BY createdAt DESC LIMIT 5";
$notificationsStmt = $connection->prepare($notificationsQuery);
$notificationsStmt->bindParam(':userId', $userId);
$notificationsStmt->execute();
$notifications = $notificationsStmt->fetchAll(PDO::FETCH_ASSOC);
} elseif (isOwner()) {
// Owner dashboard data
$userId = $_SESSION['user_id'];
// User's claims
$claimsQuery = "
SELECT c.*, i.description, i.category
FROM claims c
JOIN items i ON c.itemID = i.itemID
WHERE c.ownerUserId = :userId
ORDER BY c.createdAt DESC LIMIT 5
";
$claimsStmt = $connection->prepare($claimsQuery);
$claimsStmt->bindParam(':userId', $userId);
$claimsStmt->execute();
$userClaims = $claimsStmt->fetchAll(PDO::FETCH_ASSOC);
// Notifications
$notificationsQuery = "SELECT * FROM notifications WHERE userId = :userId ORDER BY createdAt DESC LIMIT 5";
$notificationsStmt = $connection->prepare($notificationsQuery);
$notificationsStmt->bindParam(':userId', $userId);
$notificationsStmt->execute();
$notifications = $notificationsStmt->fetchAll(PDO::FETCH_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Lost & Found</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<div class="container">
<nav>
<div class="logo">Lost & Found Pro</div>
<ul class="nav-links">
<li><a href="home.php">Home</a></li>
<li><a href="items.php">Browse Items</a></li>
<li><a href="dashboard.php">Dashboard</a></li>
<?php if (isAdmin()): ?>
<li><a href="admin.php">Admin</a></li>
<li><a href="verifications.php">Verifications</a></li>
<li><a href="storage.php">Storage</a></li>
<?php endif; ?>
<?php if (isFinder()): ?>
<li><a href="report_item.php">Report Item</a></li>
<?php endif; ?>
<li><a href="notifications.php">Notifications</a></li>
<li><a href="profile.php">Profile</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
</div>
</header>
<main class="container">
<div class="card">
<div class="card-header">
<h1>Dashboard</h1>
<p>Welcome back, <?php echo isAdmin() ? $_SESSION['admin_name'] : $_SESSION['user_name']; ?>!</p>
</div>
<?php if (isAdmin()): ?>
<!-- Admin Dashboard -->
<div class="row mt-3">
<div class="col-3">
<div class="card text-center">
<h3><?php echo $stats['total_reports']; ?></h3>
<p>Total Reports</p>
</div>
</div>
<div class="col-3">
<div class="card text-center">
<h3><?php echo $stats['pending_verifications']; ?></h3>
<p>Pending Verifications</p>
</div>
</div>
<div class="col-3">
<div class="card text-center">
<h3><?php echo $stats['pending_claims']; ?></h3>
<p>Pending Claims</p>
</div>
</div>
<div class="col-3">
<div class="card text-center">
<h3><?php echo $stats['total_users']; ?></h3>
<p>Total Users</p>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-6">
<div class="card">
<h3>Recent Activities</h3>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($activities as $activity): ?>
<tr>
<td><?php echo ucfirst($activity['type']); ?></td>
<td><?php echo $activity['description']; ?></td>
<td><?php echo date('M j, Y g:i A', strtotime($activity['date'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<h3>Quick Actions</h3>
<div class="d-flex flex-column gap-2">
<a href="verifications.php" class="btn btn-primary">Manage Verifications</a>
<a href="storage.php" class="btn btn-success">Manage Storage</a>
<a href="admin.php" class="btn btn-secondary">Admin Panel</a>
</div>
</div>
</div>
</div>
<?php elseif (isFinder()): ?>
<!-- Finder Dashboard -->
<div class="row mt-3">
<div class="col-8">
<div class="card">
<h3>My Recent Reports</h3>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Report ID</th>
<th>Location Found</th>
<th>Status</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($userReports as $report): ?>
<tr>
<td>#<?php echo $report['reportID']; ?></td>
<td><?php echo $report['locationFound']; ?></td>
<td>
<span class="badge badge-<?php
switch($report['status']) {
case 'verified': echo 'success'; break;
case 'rejected': echo 'danger'; break;
default: echo 'warning';
}
?>">
<?php echo ucfirst(str_replace('_', ' ', $report['status'])); ?>
</span>
</td>
<td><?php echo date('M j, Y', strtotime($report['timestamp'])); ?></td>
<td>
<a href="report_item.php?id=<?php echo $report['reportID']; ?>" class="btn btn-sm btn-primary">View</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="report_item.php" class="btn btn-primary mt-2">Submit New Report</a>
</div>
</div>
<div class="col-4">
<div class="card">
<h3>Recent Notifications</h3>
<?php foreach ($notifications as $notification): ?>
<div class="p-2 border-bottom">
<p><?php echo $notification['message']; ?></p>
<small><?php echo date('M j, g:i A', strtotime($notification['createdAt'])); ?></small>
</div>
<?php endforeach; ?>
<a href="notifications.php" class="btn btn-secondary mt-2">View All</a>
</div>
</div>
</div>
<?php elseif (isOwner()): ?>
<!-- Owner Dashboard -->
<div class="row mt-3">
<div class="col-8">
<div class="card">
<h3>My Recent Claims</h3>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Item</th>
<th>Category</th>
<th>Status</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($userClaims as $claim): ?>
<tr>
<td><?php echo substr($claim['description'], 0, 50); ?>...</td>
<td><?php echo $claim['category']; ?></td>
<td>
<span class="badge badge-<?php
switch($claim['status']) {
case 'approved': echo 'success'; break;
case 'rejected': echo 'danger'; break;
default: echo 'warning';
}
?>">
<?php echo ucfirst($claim['status']); ?>
</span>
</td>
<td><?php echo date('M j, Y', strtotime($claim['createdAt'])); ?></td>
<td>
<a href="items.php?item=<?php echo $claim['itemID']; ?>" class="btn btn-sm btn-primary">View</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<a href="items.php" class="btn btn-primary mt-2">Browse Items</a>
</div>
</div>
<div class="col-4">
<div class="card">
<h3>Recent Notifications</h3>
<?php foreach ($notifications as $notification): ?>
<div class="p-2 border-bottom">
<p><?php echo $notification['message']; ?></p>
<small><?php echo date('M j, g:i A', strtotime($notification['createdAt'])); ?></small>
</div>
<?php endforeach; ?>
<a href="notifications.php" class="btn btn-secondary mt-2">View All</a>
</div>
</div>
</div>
<?php endif; ?>
</div>
</main>
<footer>
<div class="container">
<div class="footer-content">
<div class="logo">Lost & Found Pro</div>
<p>© 2024 Lost & Found Management System. All rights reserved.</p>
</div>
</div>
</footer>
</body>
</html>
``` |