113 lines
5.1 KiB
PHP
113 lines
5.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
session_start();
|
|
|
|
$error = '';
|
|
$success = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$school_name = $_POST['school_name'] ?? '';
|
|
$province = $_POST['province'] ?? '';
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if ($school_name && $email && $password) {
|
|
$db = db();
|
|
try {
|
|
$db->beginTransaction();
|
|
|
|
// 1. Create School
|
|
$stmt = $db->prepare("INSERT INTO schools (name, province) VALUES (:name, :province)");
|
|
$stmt->execute(['name' => $school_name, 'province' => $province]);
|
|
$school_id = $db->lastInsertId();
|
|
|
|
// 2. Create Admin User
|
|
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
|
$stmt = $db->prepare("INSERT INTO users (email, password, role, school_id) VALUES (:email, :password, 'Admin', :school_id)");
|
|
$stmt->execute([
|
|
'email' => $email,
|
|
'password' => $hashedPassword,
|
|
'school_id' => $school_id
|
|
]);
|
|
|
|
$db->commit();
|
|
$success = "School registered successfully! You can now login.";
|
|
} catch (Exception $e) {
|
|
$db->rollBack();
|
|
$error = "Registration failed: " . $e->getMessage();
|
|
}
|
|
} else {
|
|
$error = "Please fill in all required fields.";
|
|
}
|
|
}
|
|
|
|
$pageTitle = 'Register School | SOMS Platform';
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<div class="container py-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6">
|
|
<div class="card shadow-lg border-0">
|
|
<div class="card-body p-5">
|
|
<div class="text-center mb-4">
|
|
<h2 class="fw-bold">Register Your School</h2>
|
|
<p class="text-muted">Join the SOMS digital ecosystem</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger small"><?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success small"><?= htmlspecialchars($success) ?></div>
|
|
<div class="text-center"><a href="login.php" class="btn btn-primary">Go to Login</a></div>
|
|
<?php else: ?>
|
|
<form method="POST">
|
|
<h5 class="mb-3 fw-bold text-primary">School Information</h5>
|
|
<div class="mb-3">
|
|
<label class="form-label small fw-bold">School Name</label>
|
|
<input type="text" name="school_name" class="form-control" placeholder="e.g., Thabong Secondary School" required>
|
|
</div>
|
|
<div class="mb-4">
|
|
<label class="form-label small fw-bold">Province</label>
|
|
<select name="province" class="form-select">
|
|
<option value="Gauteng">Gauteng</option>
|
|
<option value="Western Cape">Western Cape</option>
|
|
<option value="KwaZulu-Natal">KwaZulu-Natal</option>
|
|
<option value="Limpopo">Limpopo</option>
|
|
<option value="Mpumalanga">Mpumalanga</option>
|
|
<option value="North West">North West</option>
|
|
<option value="Eastern Cape">Eastern Cape</option>
|
|
<option value="Free State">Free State</option>
|
|
<option value="Northern Cape">Northern Cape</option>
|
|
</select>
|
|
</div>
|
|
|
|
<hr class="my-4">
|
|
|
|
<h5 class="mb-3 fw-bold text-primary">Admin Account</h5>
|
|
<div class="mb-3">
|
|
<label class="form-label small fw-bold">Admin Email</label>
|
|
<input type="email" name="email" class="form-control" placeholder="e.g., principal@school.edu.za" required>
|
|
</div>
|
|
<div class="mb-4">
|
|
<label class="form-label small fw-bold">Admin Password</label>
|
|
<input type="password" name="password" class="form-control" placeholder="••••••••" required>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary w-100 py-2 fw-bold">Register & Continue</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<div class="mt-4 text-center">
|
|
<p class="text-muted small">Already registered? <a href="login.php" class="text-primary fw-bold">Login here</a></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|