36694-vm/verify.php
Flatlogic Bot c12628e2d9 v2
2025-12-05 21:07:12 +00:00

151 lines
6.4 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
// Check if user is logged in and is an admin
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
header("Location: login.php");
exit;
}
$page_title = "Verify Donors and Hospitals";
$pdo = db();
// Handle status updates
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action'])) {
$action = $_POST['action'];
$id = $_POST['id'];
$type = $_POST['type']; // 'donor' or 'hospital'
if ($action === 'approve') {
$status = 'approved';
} elseif ($action === 'reject') {
$status = 'rejected';
}
if (isset($status) && ($type === 'donor' || $type === 'hospital')) {
$table = $type . 's';
$sql = "UPDATE $table SET status = ? WHERE id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$status, $id]);
}
}
// Fetch pending donors and hospitals
$pending_donors = $pdo->query("SELECT * FROM donors WHERE status = 'pending'")->fetchAll(PDO::FETCH_ASSOC);
$pending_hospitals = $pdo->query("SELECT * FROM hospitals WHERE status = 'pending'")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($page_title) ?> - Organ Donation</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="dashboard.php">Dashboard</a>
<a class="nav-link text-white active" href="verify.php">Verify Donors/Hospitals</a>
<a class="nav-link text-white" href="run_matching.php">Run Matching</a>
<a class="nav-link text-white" href="logout.php">Logout</a>
</nav>
</div>
</header>
<main class="container my-5">
<h2 class="text-center mb-4">Verification Queue</h2>
<section id="pending_donors">
<h3>Pending Donor Registrations</h3>
<?php if (empty($pending_donors)): ?>
<p>No pending donor registrations.</p>
<?php else: ?>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Blood Type</th>
<th>Organs</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($pending_donors as $donor): ?>
<tr>
<td><?= htmlspecialchars($donor['name']) ?></td>
<td><?= htmlspecialchars($donor['email']) ?></td>
<td><?= htmlspecialchars($donor['blood_type']) ?></td>
<td><?= htmlspecialchars($donor['organs']) ?></td>
<td>
<form action="verify.php" method="POST" class="d-inline">
<input type="hidden" name="id" value="<?= $donor['id'] ?>">
<input type="hidden" name="type" value="donor">
<button type="submit" name="action" value="approve" class="btn btn-success btn-sm">Approve</button>
<button type="submit" name="action" value="reject" class="btn btn-danger btn-sm">Reject</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</section>
<hr class="my-5">
<section id="pending_hospitals">
<h3>Pending Hospital Registrations</h3>
<?php if (empty($pending_hospitals)): ?>
<p>No pending hospital registrations.</p>
<?php else: ?>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($pending_hospitals as $hospital): ?>
<tr>
<td><?= htmlspecialchars($hospital['name']) ?></td>
<td><?= htmlspecialchars($hospital['email']) ?></td>
<td><?= htmlspecialchars($hospital['phone']) ?></td>
<td><?= htmlspecialchars($hospital['address']) ?></td>
<td>
<form action="verify.php" method="POST" class="d-inline">
<input type="hidden" name="id" value="<?= $hospital['id'] ?>">
<input type="hidden" name="type" value="hospital">
<button type="submit" name="action" value="approve" class="btn btn-success btn-sm">Approve</button>
<button type="submit" name="action" value="reject" class="btn btn-danger btn-sm">Reject</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</section>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>