35867-vm/school_settings.php
Flatlogic Bot 6d48e88ec8 V1.0
2025-11-20 11:10:15 +00:00

162 lines
7.6 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: index.php');
exit;
}
require_once 'db/config.php';
// School Name Setting
$settings = [];
try {
$pdo = db();
// Auto-apply migrations
if (file_exists('db/migrations/005_create_school_settings_table.sql')) {
$pdo->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'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>School Settings - Admin Dashboard</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&family=Open+Sans&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body class="admin-body">
<div class="admin-container">
<aside class="sidebar">
<div class="sidebar-header">
<h2>School Admin</h2>
</div>
<nav class="sidebar-nav">
<a href="admin.php">Dashboard</a>
<a href="users.php">User Management</a>
<a href="school_settings.php" class="active">School Settings</a>
<a href="#">Subjects & Classes</a>
<a href="#">Student Promotions</a>
<a href="#">Reports</a>
<a href="logout.php" class="logout">Logout</a>
</nav>
</aside>
<main class="main-content">
<header class="main-header">
<h1>School Settings</h1>
</header>
<?php if (isset($_SESSION['success_message'])): ?>
<div class="alert alert-success"><?= htmlspecialchars($_SESSION['success_message']) ?></div>
<?php unset($_SESSION['success_message']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['error_message'])): ?>
<div class="alert alert-danger"><?= htmlspecialchars($_SESSION['error_message']) ?></div>
<?php unset($_SESSION['error_message']); ?>
<?php endif; ?>
<div class="content-grid">
<div class="card full-width-card">
<div class="card-header">
<h3>General Settings</h3>
</div>
<div class="card-body">
<form action="save_school_settings.php" method="POST">
<div class="form-group">
<label for="school_name">School Name</label>
<input type="text" id="school_name" name="school_name" class="form-control" value="<?= htmlspecialchars($school_name) ?>" required>
</div>
<button type="submit" class="btn btn-primary">Save Settings</button>
</form>
</div>
</div>
<div class="card full-width-card">
<div class="card-header">
<h3>Grading Scales</h3>
</div>
<div class="card-body">
<?php foreach ($sections as $section): ?>
<div class="grading-section">
<h4><?= htmlspecialchars($section) ?></h4>
<table class="user-table">
<thead>
<tr>
<th>Grade</th>
<th>Min Score</th>
<th>Max Score</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (isset($grading_scales[$section])): ?>
<?php foreach ($grading_scales[$section] as $grade): ?>
<tr>
<td><?= htmlspecialchars($grade['grade_name']) ?></td>
<td><?= htmlspecialchars($grade['min_score']) ?></td>
<td><?= htmlspecialchars($grade['max_score']) ?></td>
<td>
<a href="edit_grade.php?id=<?= $grade['id'] ?>" class="action-link">Edit</a>
<a href="delete_grade.php?id=<?= $grade['id'] ?>" class="action-link" onclick="return confirm('Are you sure?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="4">No grades defined for this section.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<form action="add_grade.php" method="POST" class="add-grade-form">
<input type="hidden" name="section" value="<?= htmlspecialchars($section) ?>">
<div class="form-group">
<label>Grade Name</label>
<input type="text" name="grade_name" class="form-control" required>
</div>
<div class="form-group">
<label>Min Score</label>
<input type="number" name="min_score" class="form-control" required>
</div>
<div class="form-group">
<label>Max Score</label>
<input type="number" name="max_score" class="form-control" required>
</div>
<button type="submit" class="btn btn-secondary">Add Grade</button>
</form>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</main>
</div>
</body>
</html>