Spaces:
Configuration error

lost-found-tracker-pro / dashboard.php
brucelloyd1's picture
You are a professional full-stack web developer assistant.
8df07b6 verified
Raw History Blame Contribute Delete
15.6 kB
```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>&copy; 2024 Lost & Found Management System. All rights reserved.</p>
</div>
</div>
</footer>
</body>
</html>
```