diff --git a/timetable.php b/timetable.php index 424aa6a..b5e8023 100644 --- a/timetable.php +++ b/timetable.php @@ -507,7 +507,9 @@ if (isset($_POST['generate'])) { // Always fetch the latest timetable from the database for display $class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots, $days_of_week); + ?> + @@ -517,21 +519,24 @@ $class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots, $days_ -
-
+
+

Class Timetable

@@ -544,11 +549,32 @@ $class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots, $days_
- + +
+ + No workloads found. Please add classes, subjects, teachers, and workloads in the "Manage" section first. The "Generate Timetable" button is disabled. + + Click the "Generate Timetable" button to create a schedule. + +
+ + $period) { + $timeslot_id_to_period_idx[$period['id']] = $idx; + } + ?> - +
-

+

@@ -562,68 +588,61 @@ $class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots, $days_ $timeslot) : ?> + - $day_name) : ?> - 0) ? ($class_timetables[$class['id']][$day_idx][$period_idx - 1] ?? null) : null; - if ($lesson_above && !empty($lesson_above['is_double']) && ($lesson_above['id'] ?? 'a') === ($lesson['id'] ?? 'b')) { - continue; // This is the fix: skip the cell entirely - } + if ($current_period_idx !== -1) { + foreach ($days_of_week as $day_idx => $day_name) { + // If the cell is marked to be skipped by a rowspan above, do nothing and continue + if (!empty($skip_cells[$day_idx][$current_period_idx])) { + continue; + } - $rowspan = 1; - if ($lesson && !empty($lesson['is_double'])) { - // Check if the next timeslot is not a break to prevent rowspan over a break row - $is_next_slot_a_break = false; - $current_timeslot_index = -1; - - $timeslots_values = array_values($timeslots); - foreach ($timeslots_values as $index => $ts) { - if ($ts['id'] === $timeslot['id']) { - $current_timeslot_index = $index; - break; + $lesson = $class_timetables[$class['id']][$day_idx][$current_period_idx] ?? null; + $rowspan = 1; + + if ($lesson && !empty($lesson['is_double'])) { + // Check if the next timeslot is also not a break + $next_timeslot_is_break = isset($timeslots[$timeslot_index + 1]) && $timeslots[$timeslot_index + 1]['is_break']; + if (!$next_timeslot_is_break) { + $rowspan = 2; + // Mark the cell below this one to be skipped in the next iteration + $next_period_idx = $current_period_idx + 1; + $skip_cells[$day_idx][$next_period_idx] = true; } } - - if ($current_timeslot_index !== -1 && isset($timeslots_values[$current_timeslot_index + 1])) { - $next_timeslot = $timeslots_values[$current_timeslot_index + 1]; - if ($next_timeslot['is_break']) { - $is_next_slot_a_break = true; - } - } - - if (!$is_next_slot_a_break) { - $rowspan = 2; - } - } - ?> - - - + + @@ -632,16 +651,8 @@ $class_timetables = get_timetable_from_db($pdoconn, $classes, $timeslots, $days_ - - -
- - No workloads found. Please add classes, subjects, teachers, and workloads in the "Manage" section first. The "Generate Timetable" button is disabled. - - Click the "Generate Timetable" button to create a schedule. - -
- + +

-
Break - -
-
- -
- -
+ +
+
+ +
+ +