38394-vm/admin/donors.php
2026-02-13 10:15:56 +00:00

91 lines
3.8 KiB
PHP

<?php
require_once 'auth.php';
require_once '../db/config.php';
require_login();
$user = get_user();
$pdo = db();
// Fetch unique donors based on email, with total amount and count
$donors = $pdo->query("
SELECT
donor_email,
donor_name,
donor_phone,
SUM(amount) as total_contributed,
COUNT(*) as donation_count,
MAX(created_at) as last_donation
FROM donations
WHERE status = 'completed'
GROUP BY donor_email
ORDER BY total_contributed DESC
")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Donors CRM - <?= htmlspecialchars(get_org_name()) ?> Admin</title>
<?php if ($favicon = get_favicon_url()): ?>
<link rel="icon" type="image/x-icon" href="../<?= htmlspecialchars($favicon) ?>">
<?php endif; ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
<style>
:root { --sidebar-width: 260px; --primary-color: #059669; }
body { background-color: #f3f4f6; }
.sidebar { width: var(--sidebar-width); height: 100vh; position: fixed; left: 0; top: 0; background: #111827; color: #fff; padding: 1.5rem; }
.main-content { margin-left: var(--sidebar-width); padding: 2rem; }
.nav-link { color: #9ca3af; margin-bottom: 0.5rem; border-radius: 8px; }
.nav-link:hover, .nav-link.active { color: #fff; background: #1f2937; }
.nav-link.active { background: var(--primary-color); }
.card { border: none; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
</style>
</head>
<body>
<?php include "sidebar.php"; ?>
<div class="main-content">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="mb-0">Donor CRM</h2>
</div>
<div class="card p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th class="ps-4">Donor Name</th>
<th>Email</th>
<th>Phone</th>
<th>Donations</th>
<th>Total Amount</th>
<th>Last Donation</th>
</tr>
</thead>
<tbody>
<?php foreach ($donors as $donor): ?>
<tr>
<td class="ps-4">
<strong><?= htmlspecialchars($donor['donor_name'] ?: 'Anonymous') ?></strong>
</td>
<td><?= htmlspecialchars($donor['donor_email']) ?></td>
<td><?= htmlspecialchars($donor['donor_phone'] ?? 'N/A') ?></td>
<td><span class="badge bg-primary rounded-pill"><?= $donor['donation_count'] ?></span></td>
<td><strong>OMR <?= number_format($donor['total_contributed'], 3) ?></strong></td>
<td class="small text-muted"><?= date('M j, Y', strtotime($donor['last_donation'])) ?></td>
</tr>
<?php endforeach; ?>
<?php if (empty($donors)): ?>
<tr>
<td colspan="6" class="text-center py-4 text-muted">No donors found with completed payments.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>