still trying
This commit is contained in:
parent
047da4e51b
commit
77833a9ac9
104
admin_school_settings.php
Normal file
104
admin_school_settings.php
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/auth_check.php';
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
if (!isset($_SESSION['school_id']) || $_SESSION['role'] !== 'admin') {
|
||||||
|
// Redirect non-admins or users without a school_id
|
||||||
|
header('Location: /dashboard.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$error = '';
|
||||||
|
$school_id = $_SESSION['school_id'];
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
// Handle POST request
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
if (isset($_POST['update_settings'])) {
|
||||||
|
$working_days = isset($_POST['working_days']) ? implode(',', $_POST['working_days']) : '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$stmt = $pdo->prepare("UPDATE schools SET working_days = ? WHERE id = ?");
|
||||||
|
if ($stmt->execute([$working_days, $school_id])) {
|
||||||
|
$message = 'Settings updated successfully!';
|
||||||
|
} else {
|
||||||
|
$error = 'Failed to update settings.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch school settings
|
||||||
|
$school_settings = null;
|
||||||
|
try {
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM schools WHERE id = ?");
|
||||||
|
$stmt->execute([$school_id]);
|
||||||
|
$school_settings = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$current_working_days = $school_settings ? explode(',', $school_settings['working_days']) : [];
|
||||||
|
$all_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Admin: School Settings - Haki Schedule</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php include 'includes/navbar.php'; ?>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<h1 class="h2 fw-bold mb-4">School Settings</h1>
|
||||||
|
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<div class="alert alert-success"><?php echo $message; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Working Days</h5>
|
||||||
|
<p class="card-text">Select the days your school operates. This will affect timetable generation.</p>
|
||||||
|
<form action="admin_school_settings.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<?php foreach ($all_days as $day): ?>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" name="working_days[]" value="<?php echo $day; ?>" id="day_<?php echo $day; ?>" <?php echo in_array($day, $current_working_days) ? 'checked' : ''; ?>>
|
||||||
|
<label class="form-check-label" for="day_<?php echo $day; ?>">
|
||||||
|
<?php echo $day; ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<button type="submit" name="update_settings" class="btn btn-primary">Save Settings</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-5">
|
||||||
|
<div class="container text-center">
|
||||||
|
<p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
db/migrations/023_add_working_days_to_schools.sql
Normal file
1
db/migrations/023_add_working_days_to_schools.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE `schools` ADD COLUMN `working_days` VARCHAR(255) NOT NULL DEFAULT 'Monday,Tuesday,Wednesday,Thursday,Friday';
|
||||||
@ -27,6 +27,7 @@ $role = $_SESSION['role'] ?? '';
|
|||||||
<li><a class="dropdown-item" href="/admin_timeslots.php">Timeslots</a></li>
|
<li><a class="dropdown-item" href="/admin_timeslots.php">Timeslots</a></li>
|
||||||
<li><a class="dropdown-item" href="/admin_elective_groups.php">Elective Groups</a></li>
|
<li><a class="dropdown-item" href="/admin_elective_groups.php">Elective Groups</a></li>
|
||||||
<li><hr class="dropdown-divider"></li>
|
<li><hr class="dropdown-divider"></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_school_settings.php">School Settings</a></li>
|
||||||
<li><a class="dropdown-item" href="/admin_data_management.php">Data Management</a></li>
|
<li><a class="dropdown-item" href="/admin_data_management.php">Data Management</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@ -405,7 +405,7 @@ function save_timetable($pdo, $class_timetables, $timeslots) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_timetable_from_db($pdo, $classes, $timeslots) {
|
function get_timetable_from_db($pdo, $classes, $timeslots, $days_of_week) {
|
||||||
$stmt = $pdo->query('SELECT * FROM schedules ORDER BY id');
|
$stmt = $pdo->query('SELECT * FROM schedules ORDER BY id');
|
||||||
$saved_lessons = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$saved_lessons = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
@ -413,7 +413,6 @@ function get_timetable_from_db($pdo, $classes, $timeslots) {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
|
|
||||||
$periods = array_values(array_filter($timeslots, function($ts) { return !$ts['is_break']; }));
|
$periods = array_values(array_filter($timeslots, function($ts) { return !$ts['is_break']; }));
|
||||||
$periods_per_day = count($periods);
|
$periods_per_day = count($periods);
|
||||||
|
|
||||||
@ -470,7 +469,18 @@ $classes = $all_data['classes'];
|
|||||||
$timeslots = $all_data['timeslots'];
|
$timeslots = $all_data['timeslots'];
|
||||||
$workloads = $all_data['workloads'];
|
$workloads = $all_data['workloads'];
|
||||||
|
|
||||||
$days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
|
// Fetch working days from school settings
|
||||||
|
$school_id = $_SESSION['school_id'] ?? null;
|
||||||
|
$days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; // Default
|
||||||
|
if ($school_id) {
|
||||||
|
$stmt = $pdoconn->prepare("SELECT working_days FROM schools WHERE id = ?");
|
||||||
|
$stmt->execute([$school_id]);
|
||||||
|
$school_settings = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
if ($school_settings && !empty($school_settings['working_days'])) {
|
||||||
|
$days_of_week = explode(',', $school_settings['working_days']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$class_timetables = [];
|
$class_timetables = [];
|
||||||
|
|
||||||
if (isset($_POST['generate'])) {
|
if (isset($_POST['generate'])) {
|
||||||
@ -484,7 +494,7 @@ if (isset($_POST['generate'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Always fetch the latest timetable from the database for display
|
// Always fetch the latest timetable from the database for display
|
||||||
$class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots);
|
$class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots, $days_of_week);
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user