155 lines
6.1 KiB
PHP
155 lines
6.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$db = db();
|
|
$current_role = 'Super Admin';
|
|
$pageTitle = 'Super Admin | Township Schools Platform';
|
|
$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" 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" 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">
|
|
<p>Total Schools</p>
|
|
<h3><?= $total_schools ?></h3>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card p-3 stats-card" style="border-left-color: #0288D1;">
|
|
<p>Total Learners</p>
|
|
<h3><?= $total_learners ?></h3>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card p-3 stats-card" style="border-left-color: #2E7D32;">
|
|
<p>System Uptime</p>
|
|
<h3>99.9%</h3>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card p-3 stats-card" style="border-left-color: #FFA000;">
|
|
<p>Storage Used</p>
|
|
<h3>12 MB</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header bg-white py-3">
|
|
<h5 class="mb-0">Managed Schools</h5>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover mb-0">
|
|
<thead>
|
|
<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">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Onboard New School</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<input type="hidden" name="action" value="add_school">
|
|
<div class="mb-3">
|
|
<label class="form-label">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">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">District</label>
|
|
<input type="text" name="district" class="form-control" required placeholder="e.g. Sedibeng East">
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" class="btn btn-primary">Onboard School</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|