109 lines
5.0 KiB
PHP
109 lines
5.0 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Ensure user is logged in and is an NGO
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'ngo') {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
$ngo_id = $_SESSION['user_id'];
|
|
|
|
// Fetch available food listings
|
|
$stmt_available = $pdo->prepare("
|
|
SELECT fl.*, u.name AS restaurant_name
|
|
FROM food_listings fl
|
|
JOIN users u ON fl.user_id = u.id
|
|
WHERE fl.status = 'listed'
|
|
ORDER BY fl.pickup_deadline ASC
|
|
");
|
|
$stmt_available->execute();
|
|
$available_listings = $stmt_available->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch listings claimed by the current NGO
|
|
$stmt_claimed = $pdo->prepare("
|
|
SELECT fl.*, u.name AS restaurant_name
|
|
FROM food_listings fl
|
|
JOIN users u ON fl.user_id = u.id
|
|
WHERE fl.status = 'claimed' AND fl.claimed_by_id = ?
|
|
ORDER BY fl.pickup_deadline ASC
|
|
");
|
|
$stmt_claimed->execute([$ngo_id]);
|
|
$claimed_listings = $stmt_claimed->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
<?php include 'partials/header.php'; ?>
|
|
|
|
<div class="container py-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="mb-0">NGO Dashboard</h2>
|
|
<a href="logout.php" class="btn btn-danger">Logout</a>
|
|
</div>
|
|
|
|
<p>Welcome, <strong><?php echo htmlspecialchars($_SESSION['user_name']); ?></strong>! Here are the current listings.</p>
|
|
|
|
<?php if (isset($_GET['success']) && $_GET['success'] == 'claimed'): ?>
|
|
<div class="alert alert-success">Donation claimed successfully! You can see it in your claimed donations list below.</div>
|
|
<?php elseif (isset($_GET['error'])): ?>
|
|
<div class="alert alert-danger">There was an error. The donation might have already been claimed.</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Claimed Listings -->
|
|
<hr class="my-5">
|
|
<h3 class="mb-4">My Claimed Donations</h3>
|
|
<div class="row">
|
|
<?php if (empty($claimed_listings)): ?>
|
|
<div class="col-12">
|
|
<div class="alert alert-secondary">You have not claimed any donations yet.</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($claimed_listings as $listing): ?>
|
|
<div class="col-md-6 col-lg-4 mb-4">
|
|
<div class="card h-100 border-primary">
|
|
<div class="card-header bg-primary text-white">Claimed</div>
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($listing['title']); ?></h5>
|
|
<h6 class="card-subtitle mb-2 text-muted">From: <?php echo htmlspecialchars($listing['restaurant_name']); ?></h6>
|
|
<p class="card-text"><?php echo htmlspecialchars($listing['description']); ?></p>
|
|
<ul class="list-group list-group-flush mt-auto">
|
|
<li class="list-group-item"><strong>Pickup By:</strong> <span class="fw-bold"><?php echo date('g:i A, M j', strtotime($listing['pickup_deadline'])); ?></span></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Available Listings -->
|
|
<hr class="my-5">
|
|
<h3 class="mb-4">Available Food Donations</h3>
|
|
<div class="row">
|
|
<?php if (empty($available_listings)): ?>
|
|
<div class="col-12">
|
|
<div class="alert alert-info">There are no available food donations at the moment. Please check back later.</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($available_listings as $listing): ?>
|
|
<div class="col-md-6 col-lg-4 mb-4">
|
|
<div class="card h-100">
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($listing['title']); ?></h5>
|
|
<h6 class="card-subtitle mb-2 text-muted">From: <?php echo htmlspecialchars($listing['restaurant_name']); ?></h6>
|
|
<p class="card-text"><?php echo htmlspecialchars($listing['description']); ?></p>
|
|
<ul class="list-group list-group-flush mt-auto">
|
|
<li class="list-group-item"><strong>Quantity:</strong> <?php echo htmlspecialchars($listing['quantity']); ?></li>
|
|
<li class="list-group-item"><strong>Pickup By:</strong> <span class="text-danger fw-bold"><?php echo date('g:i A, M j', strtotime($listing['pickup_deadline'])); ?></span></li>
|
|
</ul>
|
|
<a href="claim.php?listing_id=<?php echo $listing['id']; ?>" class="btn btn-success mt-3" onclick="return confirm('Are you sure you want to claim this donation?');">Claim Donation</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'partials/footer.php'; ?>
|