-
Analyzing your requirements and generating your website…
-
- Loading…
-
-
= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.
-
This page will update automatically as the plan is implemented.
-
Runtime: PHP = htmlspecialchars($phpVersion) ?> — UTC = htmlspecialchars($now) ?>
+
+
+
+
+
SchoolAdmin
+
Effortless school management for modern educators.
+
+
+
-
-
+
+
+
diff --git a/login.php b/login.php
new file mode 100644
index 0000000..e2df8a5
--- /dev/null
+++ b/login.php
@@ -0,0 +1,33 @@
+prepare("SELECT * FROM users WHERE email = ?");
+ $stmt->execute([$email]);
+ $user = $stmt->fetch();
+
+ if ($user && password_verify($password, $user['password'])) {
+ // Add this block to check user status
+ if ($user['status'] !== 'active') {
+ $_SESSION['login_error'] = 'Your account is inactive. Please contact an administrator.';
+ header('Location: index.php');
+ exit;
+ }
+
+ $_SESSION['user_id'] = $user['id'];
+ $_SESSION['user_name'] = $user['name'];
+ $_SESSION['user_role'] = $user['role'];
+ header('Location: admin.php');
+ exit;
+ } else {
+ $_SESSION['login_error'] = 'Invalid email or password.';
+ header('Location: index.php');
+ exit;
+ }
+}
\ No newline at end of file
diff --git a/logout.php b/logout.php
new file mode 100644
index 0000000..d9d3d93
--- /dev/null
+++ b/logout.php
@@ -0,0 +1,8 @@
+prepare($sql);
+ $stmt->execute([$school_name, $school_name]);
+
+ $_SESSION['success_message'] = 'School settings saved successfully.';
+
+ } catch (PDOException $e) {
+ $_SESSION['error_message'] = 'Database error: ' . $e->getMessage();
+ }
+}
+
+header('Location: school_settings.php');
+exit;
diff --git a/save_user.php b/save_user.php
new file mode 100644
index 0000000..fb62f77
--- /dev/null
+++ b/save_user.php
@@ -0,0 +1,84 @@
+prepare("SELECT id FROM users WHERE email = ?");
+ $stmt->execute([$email]);
+ if ($stmt->fetch()) {
+ $errors['email'] = 'Email already exists.';
+ }
+ } catch (PDOException $e) {
+ $errors['db'] = "Database error: " . $e->getMessage();
+ }
+ }
+
+ if (empty($password)) {
+ $errors['password'] = 'Password is required.';
+ } elseif (strlen($password) < 8) {
+ $errors['password'] = 'Password must be at least 8 characters long.';
+ }
+
+ // Check for role uniqueness: Bursar and Assistant Bursar
+ if ($role === 'Bursar' || $role === 'Assistant Bursar') {
+ try {
+ $pdo = db();
+ $stmt = $pdo->prepare("SELECT id FROM users WHERE role = ?");
+ $stmt->execute([$role]);
+ if ($stmt->fetch()) {
+ // Using 'db' to show a general form error, as there's no specific field for this.
+ $errors['db'] = "A user with the role '{$role}' already exists. Only one is allowed.";
+ }
+ } catch (PDOException $e) {
+ $errors['db'] = "Database error while checking role uniqueness: " . $e->getMessage();
+ }
+ }
+
+ if (empty($errors)) {
+ try {
+ $pdo = db();
+ $hashed_password = password_hash($password, PASSWORD_DEFAULT);
+ $sql = "INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute([$name, $email, $hashed_password, $role]);
+
+ $_SESSION['success_message'] = 'User created successfully.';
+ header("Location: users.php");
+ exit;
+ } catch (PDOException $e) {
+ $errors['db'] = "Database error: " . $e->getMessage();
+ }
+ }
+
+ $_SESSION['errors'] = $errors;
+ $_SESSION['old_input'] = $_POST;
+ header("Location: add_user.php");
+ exit;
+}
+
+header("Location: add_user.php");
+exit;
diff --git a/school_settings.php b/school_settings.php
new file mode 100644
index 0000000..acc0358
--- /dev/null
+++ b/school_settings.php
@@ -0,0 +1,162 @@
+exec(file_get_contents('db/migrations/005_create_school_settings_table.sql'));
+ }
+ if (file_exists('db/migrations/006_create_grading_scales_table.sql')) {
+ $pdo->exec(file_get_contents('db/migrations/006_create_grading_scales_table.sql'));
+ }
+
+ $stmt = $pdo->query("SELECT setting_key, setting_value FROM school_settings");
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $settings[$row['setting_key']] = $row['setting_value'];
+ }
+} catch (Exception $e) {
+ die("Could not connect to the database: " . $e->getMessage());
+}
+$school_name = $settings['school_name'] ?? '';
+
+// Grading Scales
+$grading_scales = [];
+try {
+ $stmt = $pdo->query("SELECT id, section, grade_name, min_score, max_score FROM grading_scales ORDER BY section, min_score DESC");
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $grading_scales[$row['section']][] = $row;
+ }
+} catch (Exception $e) {
+ die("Could not fetch grading scales: " . $e->getMessage());
+}
+
+$sections = ['Nursery', 'Primary', 'Secondary'];
+
+?>
+
+
+
+
+
+
School Settings - Admin Dashboard
+
+
+
+
+
+
+
+
+
+
+ = htmlspecialchars($_SESSION['success_message']) ?>
+
+
+
+
+ = htmlspecialchars($_SESSION['error_message']) ?>
+
+
+
+
+
+
+
+
+
+
+
= htmlspecialchars($section) ?>
+
+
+
+ | Grade |
+ Min Score |
+ Max Score |
+ Actions |
+
+
+
+
+
+
+ | = htmlspecialchars($grade['grade_name']) ?> |
+ = htmlspecialchars($grade['min_score']) ?> |
+ = htmlspecialchars($grade['max_score']) ?> |
+
+ Edit
+ Delete
+ |
+
+
+
+
+ | No grades defined for this section. |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/subjects_classes.php b/subjects_classes.php
new file mode 100644
index 0000000..3e52b85
--- /dev/null
+++ b/subjects_classes.php
@@ -0,0 +1,148 @@
+exec(file_get_contents('db/migrations/007_create_classes_table.sql'));
+ }
+ if (file_exists('db/migrations/008_create_subjects_table.sql')) {
+ $pdo->exec(file_get_contents('db/migrations/008_create_subjects_table.sql'));
+ }
+
+ // Fetch classes
+ $stmt_classes = $pdo->query("SELECT id, name FROM classes ORDER BY name");
+ $classes = $stmt_classes->fetchAll();
+
+ // Fetch subjects
+ $stmt_subjects = $pdo->query("SELECT id, name FROM subjects ORDER BY name");
+ $subjects = $stmt_subjects->fetchAll();
+
+} catch (Exception $e) {
+ die("Could not connect to the database: " . $e->getMessage());
+}
+
+?>
+
+
+
+
+
+
Subjects & Classes - Admin Dashboard
+
+
+
+
+
+
+
+
+
+
+ = htmlspecialchars($_SESSION['success_message']) ?>
+
+
+
+
+ = htmlspecialchars($_SESSION['error_message']) ?>
+
+
+
+
+
+
+
+
+
+
+
+ | Class Name |
+ Actions |
+
+
+
+
+
+ | = htmlspecialchars($class['name']) ?> |
+
+ Edit
+ Delete
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | Subject Name |
+ Actions |
+
+
+
+
+
+ | = htmlspecialchars($subject['name']) ?> |
+
+ Edit
+ Delete
+ |
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/update_grade.php b/update_grade.php
new file mode 100644
index 0000000..c442582
--- /dev/null
+++ b/update_grade.php
@@ -0,0 +1,48 @@
+= $max_score) {
+ $_SESSION['error_message'] = 'Min score must be less than max score.';
+ header('Location: school_settings.php');
+ exit;
+ }
+
+ try {
+ $pdo = db();
+ $sql = "UPDATE grading_scales SET grade_name = ?, min_score = ?, max_score = ? WHERE id = ?";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute([$grade_name, $min_score, $max_score, $id]);
+
+ $_SESSION['success_message'] = 'Grade updated successfully.';
+
+ } catch (PDOException $e) {
+ if ($e->errorInfo[1] == 1062) { // Duplicate entry
+ $_SESSION['error_message'] = "A grade with that name already exists in this section.";
+ } else {
+ $_SESSION['error_message'] = 'Database error: ' . $e->getMessage();
+ }
+ }
+}
+
+header('Location: school_settings.php');
+exit;
diff --git a/update_user.php b/update_user.php
new file mode 100644
index 0000000..044eac0
--- /dev/null
+++ b/update_user.php
@@ -0,0 +1,74 @@
+prepare("SELECT id FROM users WHERE email = ? AND id != ?");
+ $stmt->execute([$email, $id]);
+ if ($stmt->fetch()) {
+ $errors['email'] = 'Email already exists.';
+ }
+ } catch (PDOException $e) {
+ $errors['db'] = "Database error: " . $e->getMessage();
+ }
+ }
+
+ if (!empty($password) && strlen($password) < 8) {
+ $errors['password'] = 'Password must be at least 8 characters long.';
+ }
+
+ if (empty($errors)) {
+ try {
+ $pdo = db();
+ if ($password) {
+ $hashed_password = password_hash($password, PASSWORD_DEFAULT);
+ $sql = "UPDATE users SET name = ?, email = ?, password = ?, role = ? WHERE id = ?";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute([$name, $email, $hashed_password, $role, $id]);
+ } else {
+ $sql = "UPDATE users SET name = ?, email = ?, role = ? WHERE id = ?";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute([$name, $email, $role, $id]);
+ }
+
+ $_SESSION['success_message'] = 'User updated successfully.';
+ header("Location: users.php");
+ exit;
+ } catch (PDOException $e) {
+ $errors['db'] = "Database error: " . $e->getMessage();
+ }
+ }
+
+ $_SESSION['errors'] = $errors;
+ $_SESSION['old_input'] = $_POST;
+ header("Location: edit_user.php?id=" . $id);
+ exit;
+}
+
+header("Location: users.php");
+exit;
\ No newline at end of file
diff --git a/update_user_status.php b/update_user_status.php
new file mode 100644
index 0000000..485c98e
--- /dev/null
+++ b/update_user_status.php
@@ -0,0 +1,43 @@
+prepare($sql);
+ $stmt->execute([$status, $id]);
+
+ $_SESSION['success_message'] = 'User status updated successfully.';
+ } catch (PDOException $e) {
+ $_SESSION['error_message'] = 'Database error: ' . $e->getMessage();
+ }
+}
+
+header('Location: users.php');
+exit;
diff --git a/users.php b/users.php
new file mode 100644
index 0000000..5eb3759
--- /dev/null
+++ b/users.php
@@ -0,0 +1,119 @@
+query("SELECT id, name, role, email, status FROM users");
+ $users = $stmt->fetchAll();
+
+} catch (PDOException $e) {
+ if (strpos($e->getMessage(), "Unknown column 'status'") !== false) {
+ try {
+ $sql = file_get_contents('db/migrations/004_add_status_to_users.sql');
+ $pdo->exec($sql);
+ header("Location: users.php"); // Refresh the page after migration
+ exit;
+ } catch (Exception $me) {
+ die("Could not apply migration and connect to the database: " . $me->getMessage());
+ }
+ } else {
+ die("Could not connect to the database: " . $e->getMessage());
+ }
+}
+?>
+
+
+
+
+
+
User Management - Admin Dashboard
+
+
+
+
+
+
+
+
+ User Management
+ Add New User
+
+
+
+ = htmlspecialchars($success_message) ?>
+
+
+
+ = htmlspecialchars($error_message) ?>
+
+
+
+
+
+
+
+
+
+ | Name |
+ Role |
+ Email |
+ Status |
+ Actions |
+
+
+
+
+
+ | = htmlspecialchars($user['name']) ?> |
+ = htmlspecialchars($user['role']) ?> |
+ = htmlspecialchars($user['email']) ?> |
+ = htmlspecialchars(ucfirst($user['status'])) ?> |
+
+ Edit
+ Delete
+
+ Deactivate
+
+ Activate
+
+ |
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file