38921-vm/superadmin_dashboard.php
2026-03-01 22:53:30 +00:00

78 lines
3.0 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'superadmin') {
header('Location: index.php');
exit;
}
require_once 'db/config.php';
// Stats for Superadmin
$total_msps = db()->query("SELECT COUNT(*) FROM msps")->fetchColumn();
$total_customers = db()->query("SELECT COUNT(*) FROM customers")->fetchColumn();
$total_users = db()->query("SELECT COUNT(*) FROM users")->fetchColumn();
// Recent MSPs
$stmt = db()->query("SELECT m.*, p.name as plan_name FROM msps m JOIN plans p ON m.plan_id = p.id ORDER BY m.created_at DESC LIMIT 5");
$recent_msps = $stmt->fetchAll();
include 'header.php';
?>
<div class="container py-5">
<div class="header-section">
<h1>Superadmin Dashboard</h1>
<p class="text-muted">Overview of all MSPs and system health.</p>
</div>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-value"><?php echo $total_msps; ?></div>
<div class="stat-label">Total MSPs</div>
</div>
<div class="stat-card">
<div class="stat-value"><?php echo $total_customers; ?></div>
<div class="stat-label">Total Customers</div>
</div>
<div class="stat-card">
<div class="stat-value"><?php echo $total_users; ?></div>
<div class="stat-label">Total Users</div>
</div>
</div>
<div class="card mt-5 shadow-sm border-0">
<div class="card-body p-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h3 class="fw-bold mb-0">Recent MSP Registrations</h3>
<a href="manage_msps.php" class="btn btn-outline btn-sm">Manage All MSPs</a>
</div>
<table class="table">
<thead>
<tr>
<th>MSP Name</th>
<th>Plan</th>
<th>Subdomain</th>
<th>Created At</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($recent_msps as $msp): ?>
<tr>
<td class="fw-bold text-primary"><?php echo htmlspecialchars($msp['name']); ?></td>
<td><span class="badge bg-info text-dark"><?php echo htmlspecialchars($msp['plan_name']); ?></span></td>
<td><?php echo $msp['subdomain'] ? htmlspecialchars($msp['subdomain']) . '.mspconnect.com' : 'N/A'; ?></td>
<td class="text-muted"><?php echo date('Y-m-d', strtotime($msp['created_at'])); ?></td>
<td>
<a href="manage_msps.php?id=<?php echo $msp['id']; ?>" class="btn btn-outline btn-sm"><i class="bi bi-gear"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php include 'footer.php'; ?>