120 lines
5.3 KiB
PHP
120 lines
5.3 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
// Simulate a logged-in NGO
|
|
$ngo_id = 1; // In a real app, this would come from a session
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Fetch the NGO's details
|
|
$sql_ngo = "SELECT name FROM ngos WHERE id = :ngo_id";
|
|
$stmt_ngo = $pdo->prepare($sql_ngo);
|
|
$stmt_ngo->bindParam(':ngo_id', $ngo_id, PDO::PARAM_INT);
|
|
$stmt_ngo->execute();
|
|
$ngo = $stmt_ngo->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch listings claimed by this NGO
|
|
$sql_listings = "SELECT l.id, l.name, l.quantity, l.status, l.pickup_by, v.name as volunteer_name
|
|
FROM food_listings as l
|
|
LEFT JOIN volunteer_assignments as va ON l.id = va.listing_id
|
|
LEFT JOIN volunteers as v ON va.volunteer_id = v.id
|
|
WHERE l.ngo_id = :ngo_id
|
|
ORDER BY l.pickup_by DESC";
|
|
$stmt_listings = $pdo->prepare($sql_listings);
|
|
$stmt_listings->bindParam(':ngo_id', $ngo_id, PDO::PARAM_INT);
|
|
$stmt_listings->execute();
|
|
$listings = $stmt_listings->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
} catch (PDOException $e) {
|
|
$ngo = false;
|
|
$listings = [];
|
|
// error_log($e->getMessage());
|
|
}
|
|
|
|
function getStatusBadge($status) {
|
|
switch ($status) {
|
|
case 'claimed':
|
|
return '<span class="badge bg-warning text-dark">Awaiting Volunteer</span>';
|
|
case 'assigned':
|
|
return '<span class="badge bg-info">Volunteer Assigned</span>';
|
|
case 'collected':
|
|
return '<span class="badge bg-success">Collected</span>';
|
|
default:
|
|
return '<span class="badge bg-secondary">Unknown</span>';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>NGO Dashboard - 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 active" href="ngo_dashboard.php">NGO Dashboard</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="volunteer_signup.php">Volunteer Signup</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="volunteer_hub_old.php">Find Pickups</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" href="admin_panel.php">Admin Panel</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container my-5">
|
|
<h1 class="h2 mb-4">Dashboard: <?= $ngo ? htmlspecialchars($ngo['name']) : 'NGO' ?></h1>
|
|
|
|
<?php if (empty($listings)): ?>
|
|
<div class="card p-5 text-center">
|
|
<p class="mb-0 text-muted">You have not claimed any donations yet. Visit the <a href="ngo_dashboard_old.php">public listings</a> to find available food.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Food Item</th>
|
|
<th>Quantity</th>
|
|
<th>Pickup By</th>
|
|
<th>Status</th>
|
|
<th>Volunteer</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($listings as $listing): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($listing['name']) ?></td>
|
|
<td><?= htmlspecialchars($listing['quantity']) ?></td>
|
|
<td><?= date('M d, Y h:i A', strtotime($listing['pickup_by'])) ?></td>
|
|
<td><?= getStatusBadge($listing['status']) ?></td>
|
|
<td><?= $listing['volunteer_name'] ? htmlspecialchars($listing['volunteer_name']) : '-' ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="mt-4 text-center">
|
|
<a href="ngo_dashboard_old.php" class="btn btn-outline-primary">View All Available Donations</a>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|