42 lines
1.1 KiB
PHP
42 lines
1.1 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;
|
|
}
|
|
|
|
// Check if listing_id is provided
|
|
if (!isset($_GET['listing_id']) || !is_numeric($_GET['listing_id'])) {
|
|
header("Location: dashboard.php?error=invalid_listing");
|
|
exit;
|
|
}
|
|
|
|
$listing_id = $_GET['listing_id'];
|
|
$ngo_id = $_SESSION['user_id'];
|
|
|
|
$pdo = db();
|
|
|
|
// Check if the listing exists and is available
|
|
$stmt = $pdo->prepare("SELECT * FROM food_listings WHERE id = ? AND status = 'listed'");
|
|
$stmt->execute([$listing_id]);
|
|
$listing = $stmt->fetch();
|
|
|
|
if (!$listing) {
|
|
header("Location: dashboard.php?error=listing_not_available");
|
|
exit;
|
|
}
|
|
|
|
// Update the listing to mark it as claimed
|
|
$stmt = $pdo->prepare("UPDATE food_listings SET status = 'claimed', claimed_by_id = ? WHERE id = ?");
|
|
$success = $stmt->execute([$ngo_id, $listing_id]);
|
|
|
|
if ($success) {
|
|
header("Location: dashboard.php?success=claimed");
|
|
} else {
|
|
header("Location: dashboard.php?error=claim_failed");
|
|
}
|
|
exit;
|