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

110 lines
4.8 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
// If superadmin, redirect to superadmin dashboard
if ($_SESSION['role'] === 'superadmin') {
header('Location: superadmin_dashboard.php');
exit;
}
$msp_id = $_SESSION['msp_id'];
// Stats for current MSP
$total_customers = db()->prepare("SELECT COUNT(*) FROM customers WHERE msp_id = ?");
$total_customers->execute([$msp_id]);
$total_customers = $total_customers->fetchColumn();
$onboarding_count = db()->prepare("SELECT COUNT(*) FROM customers WHERE msp_id = ? AND status = 'onboarding'");
$onboarding_count->execute([$msp_id]);
$onboarding_count = $onboarding_count->fetchColumn();
$active_count = db()->prepare("SELECT COUNT(*) FROM customers WHERE msp_id = ? AND status = 'active'");
$active_count->execute([$msp_id]);
$active_count = $active_count->fetchColumn();
// Recent Customers
$stmt = db()->prepare("SELECT * FROM customers WHERE msp_id = ? ORDER BY created_at DESC LIMIT 5");
$stmt->execute([$msp_id]);
$recent_customers = $stmt->fetchAll();
include 'header.php';
?>
<div class="container py-5">
<div class="header-section">
<h1>Dashboard</h1>
<p class="text-muted">Welcome back, <?php echo htmlspecialchars($_SESSION['user_name']); ?>. Here's what's happening with your clients.</p>
</div>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-value"><?php echo $total_customers; ?></div>
<div class="stat-label">Total Clients</div>
</div>
<div class="stat-card">
<div class="stat-value text-primary"><?php echo $onboarding_count; ?></div>
<div class="stat-label">In Onboarding</div>
</div>
<div class="stat-card">
<div class="stat-value text-success"><?php echo $active_count; ?></div>
<div class="stat-label">Active Managed</div>
</div>
</div>
<div class="row mt-5">
<div class="col-md-8">
<div class="card shadow-sm border-0 mb-4">
<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 Customers</h3>
<a href="customers.php" class="btn btn-outline btn-sm">View All</a>
</div>
<div class="list-group list-group-flush">
<?php foreach ($recent_customers as $customer): ?>
<a href="onboarding.php?id=<?php echo $customer['id']; ?>" class="list-group-item list-group-item-action border-0 px-0 py-3 d-flex justify-content-between align-items-center">
<div>
<div class="fw-bold text-primary"><?php echo htmlspecialchars($customer['name']); ?></div>
<small class="text-muted"><?php echo htmlspecialchars($customer['contact_email']); ?></small>
</div>
<span class="badge <?php echo $customer['status'] == 'active' ? 'bg-success-subtle text-success' : 'bg-primary-subtle text-primary'; ?> rounded-pill">
<?php echo ucfirst($customer['status']); ?>
</span>
</a>
<?php endforeach; ?>
<?php if (empty($recent_customers)): ?>
<p class="text-muted text-center py-4">No customers yet. <a href="add_customer.php">Add your first one!</a></p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm border-0 mb-4 bg-primary text-white">
<div class="card-body p-4">
<h4 class="fw-bold mb-3">Onboarding Help</h4>
<p class="small opacity-75">Need to streamline your client intake? Use our template builder to create custom onboarding flows.</p>
<a href="templates.php" class="btn btn-light btn-sm fw-bold">Manage Templates</a>
</div>
</div>
<div class="card shadow-sm border-0">
<div class="card-body p-4">
<h4 class="fw-bold mb-3">System Updates</h4>
<div class="small">
<div class="mb-2"><strong>v2.0</strong> - Multi-tenancy & Templates <span class="text-muted float-end">Mar 1</span></div>
<div class="mb-2"><strong>v1.5</strong> - QBR Support <span class="text-muted float-end">Feb 20</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer.php'; ?>