128 lines
6.0 KiB
PHP
128 lines
6.0 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
// Simulate a logged-in volunteer
|
|
$volunteer_id = 1; // In a real app, this would come from a session
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Fetch the volunteer's details
|
|
$sql_volunteer = "SELECT name FROM volunteers WHERE id = :volunteer_id";
|
|
$stmt_volunteer = $pdo->prepare($sql_volunteer);
|
|
$stmt_volunteer->bindParam(':volunteer_id', $volunteer_id, PDO::PARAM_INT);
|
|
$stmt_volunteer->execute();
|
|
$volunteer = $stmt_volunteer->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch listings assigned to this volunteer
|
|
$sql_listings = "SELECT l.id, l.name, l.quantity, l.status, l.pickup_by, n.name as ngo_name
|
|
FROM food_listings as l
|
|
JOIN volunteer_assignments as va ON l.id = va.listing_id
|
|
LEFT JOIN ngos as n ON l.ngo_id = n.id
|
|
WHERE va.volunteer_id = :volunteer_id
|
|
ORDER BY l.pickup_by DESC";
|
|
$stmt_listings = $pdo->prepare($sql_listings);
|
|
$stmt_listings->bindParam(':volunteer_id', $volunteer_id, PDO::PARAM_INT);
|
|
$stmt_listings->execute();
|
|
$assignments = $stmt_listings->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
} catch (PDOException $e) {
|
|
$volunteer = false;
|
|
$assignments = [];
|
|
// error_log($e->getMessage());
|
|
}
|
|
|
|
function getStatusBadge($status) {
|
|
$badges = [
|
|
'assigned' => '<span class="badge bg-primary">Assigned</span>',
|
|
'collected' => '<span class="badge bg-info">Collected</span>',
|
|
'en-route' => '<span class="badge bg-warning text-dark">En Route</span>',
|
|
'delivered' => '<span class="badge bg-success">Delivered</span>',
|
|
];
|
|
return $badges[$status] ?? '<span class="badge bg-secondary">Unknown</span>';
|
|
}
|
|
|
|
function getNextAction($status, $listing_id) {
|
|
$actions = [
|
|
'assigned' => '<button type="submit" name="status" value="collected" class="btn btn-sm btn-primary">Mark Collected</button>',
|
|
'collected' => '<button type="submit" name="status" value="en-route" class="btn btn-sm btn-warning">Mark En Route</button>',
|
|
'en-route' => '<button type="submit" name="status" value="delivered" class="btn btn-sm btn-success">Mark Delivered</button>',
|
|
];
|
|
if (isset($actions[$status])) {
|
|
return '<form action="update_pickup_status.php" method="POST" class="d-inline"><input type="hidden" name="listing_id" value="'.$listing_id.'">'.$actions[$status].'</form>';
|
|
}
|
|
return '-';
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Volunteer 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" 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 active" 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" href="admin_panel.php">Admin Panel</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container my-5">
|
|
<h1 class="h2 mb-4">Dashboard: <?= $volunteer ? htmlspecialchars($volunteer['name']) : 'Volunteer' ?></h1>
|
|
|
|
<?php if (empty($assignments)): ?>
|
|
<div class="card p-5 text-center">
|
|
<p class="mb-0 text-muted">You have no assigned pickups. Visit the <a href="volunteer_hub_old.php">Volunteer Hub</a> to find available jobs.</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>Destination NGO</th>
|
|
<th>Pickup By</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($assignments as $assignment): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($assignment['name']) ?></td>
|
|
<td><?= htmlspecialchars($assignment['ngo_name']) ?></td>
|
|
<td><?= date('M d, Y h:i A', strtotime($assignment['pickup_by'])) ?></td>
|
|
<td><?= getStatusBadge($assignment['status']) ?></td>
|
|
<td><?= getNextAction($assignment['status'], $assignment['id']) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="mt-4 text-center">
|
|
<a href="volunteer_hub_old.php" class="btn btn-outline-primary">Find New Pickups</a>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|