168 lines
6.4 KiB
PHP
168 lines
6.4 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$sql = "SELECT id, name, quantity, pickup_by, description, status FROM food_listings WHERE status = 'available' ORDER BY pickup_by ASC";
|
|
$stmt = $pdo->query($sql);
|
|
$listings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$listings = [];
|
|
// In a real app, log this error
|
|
// error_log($e->getMessage());
|
|
}
|
|
|
|
function time_ago($datetime) {
|
|
$now = new DateTime;
|
|
$ago = new DateTime($datetime);
|
|
$diff = $now->diff($ago);
|
|
|
|
$diff->w = floor($diff->d / 7);
|
|
$diff->d -= $diff->w * 7;
|
|
|
|
$string = array(
|
|
'y' => 'year',
|
|
'm' => 'month',
|
|
'w' => 'week',
|
|
'd' => 'day',
|
|
'h' => 'hour',
|
|
'i' => 'minute',
|
|
's' => 'second',
|
|
);
|
|
foreach ($string as $k => &$v) {
|
|
if ($diff->$k) {
|
|
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
|
|
} else {
|
|
unset($string[$k]);
|
|
}
|
|
}
|
|
|
|
$string = array_slice($string, 0, 1);
|
|
return $string ? implode(', ', $string) . ' ago' : 'just now';
|
|
}
|
|
|
|
?>
|
|
<!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 rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<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;
|
|
color: #212529;
|
|
}
|
|
.navbar {
|
|
box-shadow: 0 2px 4px rgba(0,0,0,.1);
|
|
}
|
|
.card {
|
|
border-radius: 0.5rem;
|
|
border: none;
|
|
box-shadow: 0 4px 8px rgba(0,0,0,.1);
|
|
transition: transform .2s;
|
|
}
|
|
.card:hover {
|
|
transform: translateY(-5px);
|
|
}
|
|
.card-title {
|
|
font-weight: 600;
|
|
}
|
|
.btn-success {
|
|
background-color: #28a745;
|
|
border-color: #28a745;
|
|
}
|
|
.btn-success:hover {
|
|
background-color: #218838;
|
|
border-color: #1e7e34;
|
|
}
|
|
.badge {
|
|
font-size: 0.9em;
|
|
}
|
|
</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>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<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_hub.php">Volunteer Hub</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="distribution_map.php">Distribution Map</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container my-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h2">Available Food Donations</h1>
|
|
<?php if (isset($_GET['status']) && $_GET['status'] == 'claimed'): ?>
|
|
<div class="alert alert-success mb-0 py-2">Donation claimed!</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="row gy-4">
|
|
<?php if (empty($listings)): ?>
|
|
<div class="col-12">
|
|
<div class="card p-5 text-center">
|
|
<p class="mb-0 text-muted">There are currently no available food donations. Please check back later.</p>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($listings as $listing): ?>
|
|
<div class="col-md-6 col-lg-4">
|
|
<div class="card h-100">
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title"><?= htmlspecialchars($listing['name']) ?></h5>
|
|
<p class="card-text text-muted">Quantity: <?= htmlspecialchars($listing['quantity']) ?></p>
|
|
<p class="card-text"><?= htmlspecialchars($listing['description']) ?></p>
|
|
<div class="mt-auto">
|
|
<p class="card-text">
|
|
<small class="text-danger">Pickup by: <?= date('M d, Y h:i A', strtotime($listing['pickup_by'])) ?></small>
|
|
</p>
|
|
<form action="accept_listing.php" method="POST" class="d-grid">
|
|
<input type="hidden" name="id" value="<?= $listing['id'] ?>">
|
|
<button type="submit" class="btn btn-success">Accept Donation</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<div class="card-footer bg-transparent border-0 text-end">
|
|
<small class="text-muted">Posted <?= time_ago($listing['created_at']) ?></small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|