114 lines
5.2 KiB
PHP
114 lines
5.2 KiB
PHP
<?php
|
|
// In a real application, this page should be protected by a robust authentication and authorization system.
|
|
require_once 'db/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Fetch all food listings with relations
|
|
$sql = "SELECT
|
|
l.id, l.name as food_item, l.quantity, l.status, l.pickup_by,
|
|
d.name as donor_name,
|
|
n.name as ngo_name,
|
|
v.name as volunteer_name
|
|
FROM food_listings as l
|
|
LEFT JOIN donors as d ON l.id = d.id // This is a simplification, should be a proper FK
|
|
LEFT JOIN ngos as n ON l.ngo_id = n.id
|
|
LEFT JOIN volunteer_assignments as va ON l.id = va.listing_id
|
|
LEFT JOIN volunteers as v ON va.volunteer_id = v.id
|
|
ORDER BY l.created_at DESC";
|
|
$stmt = $pdo->query($sql);
|
|
$listings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
} catch (PDOException $e) {
|
|
$listings = [];
|
|
// error_log($e->getMessage());
|
|
}
|
|
|
|
function getStatusBadge($status) {
|
|
$badges = [
|
|
'available' => '<span class="badge bg-secondary">Available</span>',
|
|
'claimed' => '<span class="badge bg-warning text-dark">Claimed</span>',
|
|
'assigned' => '<span class="badge bg-primary">Assigned</span>',
|
|
'collected' => '<span class="badge bg-info">Collected</span>',
|
|
'en-route' => '<span class="badge bg-info text-dark">En Route</span>',
|
|
'delivered' => '<span class="badge bg-success">Delivered</span>',
|
|
];
|
|
return $badges[$status] ?? '<span class="badge bg-light text-dark">Unknown</span>';
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Admin Panel - Food Rescue</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
|
|
<style>
|
|
body { font-family: 'Poppins', sans-serif; background-color: #f8f9fa; }
|
|
.navbar { box-shadow: 0 2px 4px rgba(0,0,0,.1); }
|
|
.table { background-color: #fff; box-shadow: 0 4px 8px rgba(0,0,0,.1); }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="index.php" style="font-weight: 600;">Food Rescue</a>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item"><a class="nav-link" href="index.php">Home</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="add_listing.php">Add Listing</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="ngo_dashboard.php">NGO Dashboard</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="volunteer_dashboard.php">Volunteer Dashboard</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="distribution_map.php">Distribution Map</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="admin_panel.php">Admin Panel</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container-fluid my-5">
|
|
<h1 class="h2 mb-4">Admin Panel: System-Wide View</h1>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
All Food Listings
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Food Item</th>
|
|
<th>Status</th>
|
|
<th>NGO</th>
|
|
<th>Volunteer</th>
|
|
<th>Pickup By</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($listings)): ?>
|
|
<tr><td colspan="6" class="text-center text-muted">No listings found.</td></tr>
|
|
<?php else: ?>
|
|
<?php foreach ($listings as $listing): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($listing['id']) ?></td>
|
|
<td><?= htmlspecialchars($listing['food_item']) ?></td>
|
|
<td><?= getStatusBadge($listing['status']) ?></td>
|
|
<td><?= htmlspecialchars($listing['ngo_name'] ?? '-') ?></td>
|
|
<td><?= htmlspecialchars($listing['volunteer_name'] ?? '-') ?></td>
|
|
<td><?= date('M d, Y h:i A', strtotime($listing['pickup_by'])) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|