still trying to fix
This commit is contained in:
parent
14a23a9f38
commit
be54ee0bce
@ -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);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user