160 lines
6.6 KiB
PHP
160 lines
6.6 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
session_start();
|
|
|
|
// Auth Check
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'Super Admin') {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
$pageTitle = 'Super Admin | SOMS';
|
|
$message = '';
|
|
|
|
// Handle School Addition
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|
if ($_POST['action'] === 'add_school') {
|
|
try {
|
|
$stmt = $db->prepare("INSERT INTO schools (name, province, district) VALUES (?, ?, ?)");
|
|
$stmt->execute([$_POST['name'], $_POST['province'], $_POST['district']]);
|
|
$message = "New school onboarded successfully.";
|
|
} catch (Exception $e) {
|
|
$message = "Error: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Stats
|
|
$total_schools = $db->query("SELECT COUNT(*) FROM schools")->fetchColumn();
|
|
$total_learners = $db->query("SELECT COUNT(*) FROM learners")->fetchColumn();
|
|
$schools = $db->query("SELECT * FROM schools ORDER BY name ASC")->fetchAll();
|
|
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<div class="container pb-5">
|
|
<div class="row mb-4">
|
|
<div class="col">
|
|
<h2 class="h4 mb-1">Super Admin Dashboard</h2>
|
|
<p class="text-muted small">Platform-wide oversight and school management</p>
|
|
</div>
|
|
<div class="col-auto">
|
|
<button class="btn btn-primary shadow-sm" data-bs-toggle="modal" data-bs-target="#addSchoolModal">
|
|
<i class="bi bi-plus-circle me-2"></i> Onboard New School
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-info alert-dismissible fade show shadow-sm" role="alert">
|
|
<?= htmlspecialchars($message) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Platform Stats -->
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-3">
|
|
<div class="card p-3 stats-card shadow-sm">
|
|
<p class="text-muted mb-1">Total Schools</p>
|
|
<h3 class="mb-0"><?= $total_schools ?></h3>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card p-3 stats-card shadow-sm" style="border-left: 4px solid #0288D1;">
|
|
<p class="text-muted mb-1">Total Learners</p>
|
|
<h3 class="mb-0"><?= $total_learners ?></h3>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card p-3 stats-card shadow-sm" style="border-left: 4px solid #2E7D32;">
|
|
<p class="text-muted mb-1">System Uptime</p>
|
|
<h3 class="mb-0">99.9%</h3>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card p-3 stats-card shadow-sm" style="border-left: 4px solid #FFA000;">
|
|
<p class="text-muted mb-1">Storage Used</p>
|
|
<h3 class="mb-0">12 MB</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm border-0">
|
|
<div class="card-header bg-white py-3">
|
|
<h5 class="mb-0 fw-bold">Managed Schools</h5>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover mb-0">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th class="ps-4">School Name</th>
|
|
<th>Province</th>
|
|
<th>District</th>
|
|
<th>Status</th>
|
|
<th class="text-end pe-4">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($schools as $school): ?>
|
|
<tr>
|
|
<td class="ps-4">
|
|
<strong><?= htmlspecialchars($school['name']) ?></strong>
|
|
</td>
|
|
<td><?= htmlspecialchars($school['province']) ?></td>
|
|
<td><?= htmlspecialchars($school['district']) ?></td>
|
|
<td><span class="badge bg-success-subtle text-success">Active</span></td>
|
|
<td class="text-end pe-4">
|
|
<button class="btn btn-sm btn-outline-primary">Manage</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add School Modal -->
|
|
<div class="modal fade" id="addSchoolModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<form method="POST" class="modal-content border-0 shadow-lg">
|
|
<div class="modal-header bg-primary text-white">
|
|
<h5 class="modal-title fw-bold">Onboard New School</h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body p-4">
|
|
<input type="hidden" name="action" value="add_school">
|
|
<div class="mb-3">
|
|
<label class="form-label small fw-bold">School Name</label>
|
|
<input type="text" name="name" class="form-control" required placeholder="e.g. Luthuli High School">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label small fw-bold">Province</label>
|
|
<select name="province" class="form-select" required>
|
|
<option value="Gauteng">Gauteng</option>
|
|
<option value="Western Cape">Western Cape</option>
|
|
<option value="Eastern Cape">Eastern Cape</option>
|
|
<option value="KwaZulu-Natal">KwaZulu-Natal</option>
|
|
<option value="Free State">Free State</option>
|
|
<option value="Limpopo">Limpopo</option>
|
|
<option value="Mpumalanga">Mpumalanga</option>
|
|
<option value="North West">North West</option>
|
|
<option value="Northern Cape">Northern Cape</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label small fw-bold">District</label>
|
|
<input type="text" name="district" class="form-control" required placeholder="e.g. Sedibeng East">
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer bg-light">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" class="btn btn-primary px-4 fw-bold">Onboard School</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|