37684-vm/admin_dashboard.php
2026-03-01 00:04:22 +00:00

190 lines
11 KiB
PHP

<?php
session_start();
if (!isset($_SESSION["user_id"]) || ($_SESSION["user_role"] ?? '') !== 'Super User') {
header("Location: login.php");
exit;
}
require_once 'db/config.php';
$project_name = $_SERVER['PROJECT_NAME'] ?? 'LPA Online';
$users_count = 0;
$lpas_count = 0;
$users = [];
$lpas = [];
try {
// Get stats
$users_count = db()->query("SELECT COUNT(*) FROM users")->fetchColumn();
$lpas_count = db()->query("SELECT COUNT(*) FROM lpa_applications")->fetchColumn();
// Get all users
$users = db()->query("SELECT * FROM users ORDER BY created_at DESC LIMIT 50")->fetchAll();
// Get all LPAs
$lpas = db()->query("SELECT * FROM lpa_applications ORDER BY created_at DESC LIMIT 50")->fetchAll();
} catch (PDOException $e) {
error_log($e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard — <?php echo htmlspecialchars($project_name); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/custom.css" rel="stylesheet">
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-lg bg-white border-bottom shadow-sm">
<div class="container">
<a class="navbar-brand d-flex align-items-center" href="/">
<img src="assets/pasted-20260228-235417-eedda424.png" alt="<?php echo htmlspecialchars($project_name); ?>" height="40">
</a>
<div class="d-flex align-items-center">
<span class="me-3 d-none d-md-inline text-muted small">Logged in as Admin: <?php echo htmlspecialchars($_SESSION['user_name'] ?? $_SESSION['user_email']); ?></span>
<a href="/logout.php" class="btn btn-outline-secondary btn-sm px-3 rounded-pill">Logout</a>
</div>
</div>
</nav>
<div class="container py-5">
<div class="row mb-5">
<div class="col">
<h1 class="h3 fw-bold mb-1">System Administration</h1>
<p class="text-muted small mb-0">Overview of all users and applications in the system.</p>
</div>
</div>
<div class="row g-4 mb-5">
<div class="col-md-6">
<div class="card border-0 shadow-sm p-4">
<div class="d-flex align-items-center">
<div class="bg-primary-subtle text-primary p-3 rounded-3 me-3">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>
</div>
<div>
<h6 class="text-muted small text-uppercase fw-bold mb-1">Total Users</h6>
<h2 class="fw-bold mb-0"><?php echo number_format($users_count); ?></h2>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card border-0 shadow-sm p-4">
<div class="d-flex align-items-center">
<div class="bg-success-subtle text-success p-3 rounded-3 me-3">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>
</div>
<div>
<h6 class="text-muted small text-uppercase fw-bold mb-1">Total Applications</h6>
<h2 class="fw-bold mb-0"><?php echo number_format($lpas_count); ?></h2>
</div>
</div>
</div>
</div>
</div>
<div class="row g-4">
<div class="col-lg-12">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white py-3 border-bottom-0">
<h5 class="fw-bold mb-0">Recent Users</h5>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="bg-light">
<tr class="small text-uppercase tracking-wider">
<th class="ps-4">Name</th>
<th>Email</th>
<th>Role</th>
<th>Verified</th>
<th class="text-end pe-4">Joined</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $u): ?>
<tr>
<td class="ps-4 fw-medium"><?php echo htmlspecialchars($u['name'] ?? 'N/A'); ?></td>
<td><?php echo htmlspecialchars($u['email']); ?></td>
<td>
<span class="badge rounded-pill <?php echo $u['role'] === 'Super User' ? 'bg-danger-subtle text-danger' : 'bg-secondary-subtle text-secondary'; ?>">
<?php echo htmlspecialchars($u['role']); ?>
</span>
</td>
<td>
<?php if ($u['is_verified']): ?>
<span class="text-success small">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="me-1"><polyline points="20 6 9 17 4 12"></polyline></svg>Yes
</span>
<?php else: ?>
<span class="text-muted small">No</span>
<?php endif; ?>
</td>
<td class="text-end pe-4 text-muted small"><?php echo date('M d, Y', strtotime($u['created_at'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-lg-12 mt-5">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white py-3 border-bottom-0">
<h5 class="fw-bold mb-0">Recent Applications</h5>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="bg-light">
<tr class="small text-uppercase tracking-wider">
<th class="ps-4">Type</th>
<th>Donor</th>
<th>Progress</th>
<th>Status</th>
<th class="text-end pe-4">Actions</th>
</tr>
</thead>
<tbody>
<?php if (count($lpas) > 0): ?>
<?php foreach ($lpas as $lpa): ?>
<tr>
<td class="ps-4">
<div class="fw-bold mb-0"><?php echo htmlspecialchars($lpa['lpa_type']); ?></div>
<div class="text-muted small">ID: #<?php echo $lpa['id']; ?></div>
</td>
<td>
<div class="fw-medium"><?php echo htmlspecialchars($lpa['donor_name']); ?></div>
<div class="text-muted small"><?php echo htmlspecialchars($lpa['customer_email']); ?></div>
</td>
<td>
<div class="progress" style="height: 6px; width: 100px;">
<?php $percent = round(($lpa['step_reached'] / 14) * 100); ?>
<div class="progress-bar bg-primary" role="progressbar" style="width: <?php echo $percent; ?>%"></div>
</div>
<span class="small text-muted"><?php echo $percent; ?>%</span>
</td>
<td>
<span class="badge rounded-pill bg-info-subtle text-info"><?php echo ucfirst($lpa['status']); ?></span>
</td>
<td class="text-end pe-4">
<a href="api/generate_pdf.php?id=<?php echo $lpa['id']; ?>" class="btn btn-sm btn-outline-primary px-3 rounded-pill">PDF</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr><td colspan="5" class="text-center py-4">No applications found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>