36695-vm/admin/donors.php
2025-12-07 18:31:47 +00:00

77 lines
3.6 KiB
PHP

<?php
$pageTitle = "Manage Donors";
require_once __DIR__ . '/../db/config.php';
require_once __DIR__ . '/partials/header.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, name, age, blood_type, status, created_at FROM donors ORDER BY created_at DESC");
$donors = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// In a real app, you'd log this error and show a user-friendly message.
die("Error: Could not fetch donors. " . $e->getMessage());
}
?>
<div class="container mt-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="display-5">Donor Registrations</h1>
</div>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-dark">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Blood Type</th>
<th>Status</th>
<th>Registered At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($donors)): ?>
<tr>
<td colspan="7" class="text-center">No donor registrations found.</td>
</tr>
<?php else: ?>
<?php foreach ($donors as $donor): ?>
<tr>
<td><?php echo htmlspecialchars($donor['id']); ?></td>
<td><?php echo htmlspecialchars($donor['name']); ?></td>
<td><?php echo htmlspecialchars($donor['age']); ?></td>
<td><?php echo htmlspecialchars($donor['blood_type']); ?></td>
<td>
<span class="badge <?php echo $donor['status'] === 'Pending Verification' ? 'bg-warning' : 'bg-success'; ?>">
<?php echo htmlspecialchars($donor['status']); ?>
</span>
</td>
<td><?php echo htmlspecialchars($donor['created_at']); ?></td>
<td>
<?php if ($donor['status'] === 'Pending Verification'): ?>
<form action="update_donor_status.php" method="POST" class="d-inline">
<input type="hidden" name="donor_id" value="<?php echo $donor['id']; ?>">
<input type="hidden" name="status" value="Active">
<button type="submit" class="btn btn-sm btn-success">Approve</button>
</form>
<form action="update_donor_status.php" method="POST" class="d-inline">
<input type="hidden" name="donor_id" value="<?php echo $donor['id']; ?>">
<input type="hidden" name="status" value="Rejected">
<button type="submit" class="btn btn-sm btn-danger">Reject</button>
</form>
<?php else: ?>
<span class="text-muted">N/A</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<?php require_once __DIR__ . '/partials/footer.php'; ?>