From be54ee0bce086b27ba9abb39b2e832c37c3f5254 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 6 Dec 2025 17:01:21 +0000 Subject: [PATCH] still trying to fix --- timetable.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/timetable.php b/timetable.php index 2679c50..eba4d74 100644 --- a/timetable.php +++ b/timetable.php @@ -316,15 +316,12 @@ function save_timetable($pdo, $class_timetables, $timeslots) { } function get_timetable_from_db($pdo, $classes, $timeslots) { - error_log("get_timetable_from_db: Fetching saved lessons..."); $stmt = $pdo->query('SELECT * FROM schedules ORDER BY id'); $saved_lessons = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($saved_lessons)) { - error_log("get_timetable_from_db: No saved lessons found in the database."); return []; } - error_log("get_timetable_from_db: Found " . count($saved_lessons) . " saved lesson records."); $days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; $periods = array_values(array_filter($timeslots, function($ts) { return !$ts['is_break']; })); @@ -339,8 +336,6 @@ function get_timetable_from_db($pdo, $classes, $timeslots) { foreach($periods as $idx => $period) { $timeslot_id_to_period_idx[$period['id']] = $idx; } - error_log("get_timetable_from_db: Timeslot to Period Index Map: " . print_r($timeslot_id_to_period_idx, true)); - foreach ($saved_lessons as $lesson) { $class_id = $lesson['class_id']; @@ -348,11 +343,9 @@ function get_timetable_from_db($pdo, $classes, $timeslots) { $timeslot_id = $lesson['timeslot_id']; if (!isset($timeslot_id_to_period_idx[$timeslot_id])) { - error_log("get_timetable_from_db: SKIPPING lesson ID {$lesson['id']} - could not find period index for timeslot ID {$timeslot_id}."); continue; } if (!isset($class_timetables[$class_id])) { - error_log("get_timetable_from_db: SKIPPING lesson ID {$lesson['id']} - could not find class timetable for class ID {$class_id}."); continue; } @@ -372,7 +365,6 @@ function get_timetable_from_db($pdo, $classes, $timeslots) { } } - error_log("get_timetable_from_db: Final processed timetables structure: " . print_r($class_timetables, true)); return $class_timetables; } @@ -390,10 +382,14 @@ if (isset($_POST['generate'])) { if (!empty($workloads)) { $class_timetables = generate_timetable($all_data, $days_of_week); save_timetable($pdoconn, $class_timetables, $timeslots); + // Redirect to the same page to prevent form resubmission and show the new timetable + header("Location: timetable.php"); + exit; } -} else { - $class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots); } + +// Always fetch the latest timetable from the database for display +$class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots); ?>