diff --git a/admin_school_settings.php b/admin_school_settings.php new file mode 100644 index 0000000..9efcea6 --- /dev/null +++ b/admin_school_settings.php @@ -0,0 +1,104 @@ +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']; + +?> + + + + + + Admin: School Settings - Haki Schedule + + + + + + +
+
+
+

School Settings

+ + +
+ + +
+ + +
+
+
Working Days
+

Select the days your school operates. This will affect timetable generation.

+
+
+ +
+ > + +
+ +
+ +
+
+
+ +
+
+
+ + + + + + diff --git a/db/migrations/023_add_working_days_to_schools.sql b/db/migrations/023_add_working_days_to_schools.sql new file mode 100644 index 0000000..04947a7 --- /dev/null +++ b/db/migrations/023_add_working_days_to_schools.sql @@ -0,0 +1 @@ +ALTER TABLE `schools` ADD COLUMN `working_days` VARCHAR(255) NOT NULL DEFAULT 'Monday,Tuesday,Wednesday,Thursday,Friday'; \ No newline at end of file diff --git a/includes/navbar.php b/includes/navbar.php index ff78aae..ed47aeb 100644 --- a/includes/navbar.php +++ b/includes/navbar.php @@ -27,6 +27,7 @@ $role = $_SESSION['role'] ?? '';
  • Timeslots
  • Elective Groups
  • +
  • School Settings
  • Data Management
  • diff --git a/timetable.php b/timetable.php index b5be1c1..8456928 100644 --- a/timetable.php +++ b/timetable.php @@ -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'); $saved_lessons = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -413,7 +413,6 @@ function get_timetable_from_db($pdo, $classes, $timeslots) { return []; } - $days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; $periods = array_values(array_filter($timeslots, function($ts) { return !$ts['is_break']; })); $periods_per_day = count($periods); @@ -470,7 +469,18 @@ $classes = $all_data['classes']; $timeslots = $all_data['timeslots']; $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 = []; if (isset($_POST['generate'])) { @@ -484,7 +494,7 @@ if (isset($_POST['generate'])) { } // 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); ?>