/
home
/
techb158
/
workloadmatch.com
/
workloadmatch.com
/
BackUp
/
Manager
/
/home/techb158/workloadmatch.com/workloadmatch.com/BackUp/Manager
mkdir
upload
Name
Size
Mode
Actions
core/
-
0755
rm
css/
-
0755
rm
data/
-
0755
rm
fonts/
-
0755
rm
Inc/
-
0755
rm
js/
-
0755
rm
php/
-
0755
rm
accesscontrol.php
16039
0644
edit
dl
rm
AddClient.php
3930
0644
edit
dl
rm
addcourse.php
17736
0644
edit
dl
rm
addcoursesession.php
20528
0644
edit
dl
rm
addcoursetime.php
17305
0644
edit
dl
rm
addgroup - Copy.php
21212
0644
edit
dl
rm
addgroup.php
22999
0644
edit
dl
rm
addgroup1.php
20667
0644
edit
dl
rm
addholiday.php
18019
0644
edit
dl
rm
addmanager.php
18765
0644
edit
dl
rm
addremediation.php
17877
0644
edit
dl
rm
addretake.php
21914
0644
edit
dl
rm
adduser.php
30079
0644
edit
dl
rm
adduser1.php
23527
0644
edit
dl
rm
Add_Course_Session.php
6529
0644
edit
dl
rm
add_event.php
1960
0644
edit
dl
rm
Add_Teacher_Unavailability.php
1746
0644
edit
dl
rm
adminreports.php
16219
0644
edit
dl
rm
AI_Generate_Schedule - Copy.php
12217
0644
edit
dl
rm
AI_Generate_Schedule.php
10731
0644
edit
dl
rm
ajax_course_group_Backup.php
17270
0644
edit
dl
rm
ajax_course_group_Backup_1.php
18742
0644
edit
dl
rm
ajax_fetch_schedule.php
3760
0644
edit
dl
rm
ajax_get_group_slots.php
872
0644
edit
dl
rm
ajax_replace_saturday -Completed.php
18739
0644
edit
dl
rm
ajax_replace_saturday - Copy (2).php
18739
0644
edit
dl
rm
ajax_replace_saturday - Copy (3).php
26554
0644
edit
dl
rm
ajax_replace_saturday - Copy (4).php
26615
0644
edit
dl
rm
ajax_replace_saturday - Copy (5).php
28374
0644
edit
dl
rm
ajax_replace_saturday - Copy.php
13452
0644
edit
dl
rm
ajax_replace_saturday - Good.php
17270
0644
edit
dl
rm
ajax_replace_saturday.php
30779
0644
edit
dl
rm
ajax_swap_courses.php
4279
0644
edit
dl
rm
assign_course_group-BackUp.php
21331
0644
edit
dl
rm
assign_course_group - Copy (BackUp).php
18315
0644
edit
dl
rm
assign_course_group - Copy.php
21318
0644
edit
dl
rm
assign_course_group.php
18315
0644
edit
dl
rm
assign_course_group1.php
20962
0644
edit
dl
rm
Assign_Course_Report.php
1375
0644
edit
dl
rm
assign_teacher_manual-1.php
21095
0644
edit
dl
rm
assign_teacher_manual - Copy (2).php
22328
0644
edit
dl
rm
assign_teacher_manual - Copy.php
22388
0644
edit
dl
rm
assign_teacher_manual-Not work.php
20585
0644
edit
dl
rm
assign_teacher_manual.php
22328
0644
edit
dl
rm
assign_teacher_manual_force_conflicts.php
22359
0644
edit
dl
rm
availableteacherreport.php
13718
0644
edit
dl
rm
Available_Teacher_Report - Copy.php
2236
0644
edit
dl
rm
Available_Teacher_Report.php
7691
0644
edit
dl
rm
brokerreports.php
16318
0644
edit
dl
rm
calendar - Copy (2).php
16891
0644
edit
dl
rm
calendar - Copy.php
23193
0644
edit
dl
rm
calendar.php
30653
0644
edit
dl
rm
changestatus.php
865
0644
edit
dl
rm
Check_if_Teacher_Report.php
1587
0644
edit
dl
rm
complete_schedule_report_by_teacher.php
19312
0644
edit
dl
rm
courseflagtime.php
3411
0644
edit
dl
rm
Create_Group_Schedule_Algorithm.php
3828
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (2).php
41412
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (3).php
46352
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (4).php
53569
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (5).php
67956
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (6).php
71134
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (7).php
72529
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (8).php
73084
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (9).php
73577
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (10).php
76505
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (11).php
76764
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (12).php
86324
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (13).php
83133
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (14).php
87274
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (get info only).php
69747
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy (with 2 course 2nd SPECIAL ).php
82314
0644
edit
dl
rm
Create_Schedule_Algorithm - Copy.php
40581
0644
edit
dl
rm
Create_Schedule_Algorithm.php
88276
0644
edit
dl
rm
Create_Schedule_Algorithm_1.php
41412
0644
edit
dl
rm
Create_Schedule_Algorithm_2.php
76505
0644
edit
dl
rm
Create_Schedule_Algorithm_2_combined.php
89764
0644
edit
dl
rm
Create_Schedule_Algorithm_2_combined_both_slots.php
91932
0644
edit
dl
rm
Create_Schedule_Algorithm_2_fixed.php
76829
0644
edit
dl
rm
Create_Schedule_Algorithm_3.php
87274
0644
edit
dl
rm
Create_Schedule_Algorithm_4.php
87274
0644
edit
dl
rm
dashboard-BackUp.php
18806
0644
edit
dl
rm
dashboard.php
22507
0644
edit
dl
rm
deleteschedulefromgroup.php
16819
0644
edit
dl
rm
delete_course.php
580
0644
edit
dl
rm
delete_course_from_teacher.php
4990
0644
edit
dl
rm
delete_course_from_teacher_backup.php
3094
0644
edit
dl
rm
delete_event.php
1212
0644
edit
dl
rm
delete_group.php
1858
0644
edit
dl
rm
delete_holiday.php
715
0644
edit
dl
rm
delete_retake.php
1276
0644
edit
dl
rm
delete_schedule_from_group-1.php
1870
0644
edit
dl
rm
delete_schedule_from_group.php
1850
0644
edit
dl
rm
delete_teacher_level.php
798
0644
edit
dl
rm
delete_teacher_unavailability.php
1347
0644
edit
dl
rm
delete_timeslot.php
597
0644
edit
dl
rm
display_schedule-1.php
18846
0644
edit
dl
rm
display_schedule.php
18846
0644
edit
dl
rm
do_remove_saturday.php
6170
0644
edit
dl
rm
edit_event.php
1612
0644
edit
dl
rm
error_log
74070
0644
edit
dl
rm
examschedulereport.php
16267
0644
edit
dl
rm
Exam_Schedule_Report.php
2677
0644
edit
dl
rm
export_absences.php
1221
0644
edit
dl
rm
fetch_all_scheduled_courses.php
6318
0644
edit
dl
rm
fetch_courses - BackUp.php
9711
0644
edit
dl
rm
fetch_courses - Copy.php
7719
0644
edit
dl
rm
fetch_courses.php
9167
0644
edit
dl
rm
fetch_courses_for_program.php
788
0644
edit
dl
rm
fetch_courses_for_program_by_schedule - Copy.php
2297
0644
edit
dl
rm
fetch_courses_for_program_by_schedule.php
3935
0644
edit
dl
rm
fetch_courses_teacher_preference.php
3852
0644
edit
dl
rm
fetch_course_for_added_group.php
897
0644
edit
dl
rm
fetch_course_hours.php
691
0644
edit
dl
rm
fetch_disabled_dates.php
518
0644
edit
dl
rm
fetch_events.php
975
0644
edit
dl
rm
fetch_exist_dates.php
1099
0644
edit
dl
rm
fetch_groups_exist_in_schedule.php
956
0644
edit
dl
rm
fetch_groups_for_program.php
843
0644
edit
dl
rm
fetch_group_timeslot.php
847
0644
edit
dl
rm
fetch_reserve_courses.php
7429
0644
edit
dl
rm
fetch_retake_courses.php
923
0644
edit
dl
rm
fetch_scheduled_courses.php
2178
0644
edit
dl
rm
fetch_schedule_report_by_group.php
5440
0644
edit
dl
rm
fetch_teachers_by_group.php
4421
0644
edit
dl
rm
fetch_teachers_by_program.php
1821
0644
edit
dl
rm
fetch_teachers_for_group.php
3170
0644
edit
dl
rm
fetch_teacher_assignment.php
24776
0644
edit
dl
rm
fetch_teacher_by_course.php
3880
0644
edit
dl
rm
fetch_teacher_conflicts.php
5682
0644
edit
dl
rm
fetch_teacher_conflicts_only.php
7665
0644
edit
dl
rm
fetch_teacher_conflicts_only_force_conflicts.php
7114
0644
edit
dl
rm
fetch_teacher_conflicts_showonly.php
10447
0644
edit
dl
rm
fetch_teacher_load.php
1482
0644
edit
dl
rm
fetch_teacher_prefrence_courses_accounting.php
1606
0644
edit
dl
rm
find_replacement-1.php
16075
0644
edit
dl
rm
find_replacement.php
18161
0644
edit
dl
rm
followup.php
16160
0644
edit
dl
rm
Generate Group Schedule.php
16987
0644
edit
dl
rm
Generate Group Schedule 1.php
18121
0644
edit
dl
rm
generateschedule.php
15706
0644
edit
dl
rm
Generate_Schedule.php
33620
0644
edit
dl
rm
generate_schedule_handler.php
7095
0644
edit
dl
rm
Generate_Schedule_Script.php
29731
0644
edit
dl
rm
getlang.php
326
0644
edit
dl
rm
getrefer.php
4349
0644
edit
dl
rm
getstatus.php
1260
0644
edit
dl
rm
get_groups_by_program.php
608
0644
edit
dl
rm
get_schedule_ai-1.php
37755
0644
edit
dl
rm
get_schedule_ai - Copy.php
36459
0644
edit
dl
rm
get_schedule_ai.php
36855
0644
edit
dl
rm
get_schedule_report.php
2393
0644
edit
dl
rm
group_schedule_form - Copy.php
16994
0644
edit
dl
rm
group_schedule_form.php
16994
0644
edit
dl
rm
main-header-inc.php
1196
0644
edit
dl
rm
main-header.php
16671
0644
edit
dl
rm
managecategory.php
9233
0644
edit
dl
rm
managerreports.php
25056
0644
edit
dl
rm
Preference_Accounting.php
22503
0644
edit
dl
rm
profile.php
20680
0644
edit
dl
rm
reference_list.php
8207
0644
edit
dl
rm
remove_saturday_course.php
19503
0644
edit
dl
rm
report_absence.php
19287
0644
edit
dl
rm
report_absence_1.php
6160
0644
edit
dl
rm
reserve_course.php
18957
0644
edit
dl
rm
rewrite_ajax_replace_saturday.php
12800
0644
edit
dl
rm
rewrite_Create_Schedule_Algorithm.php
88318
0644
edit
dl
rm
rewrite_Create_Schedule_Algorithm_2.php
88900
0644
edit
dl
rm
save_schedule.php
2970
0644
edit
dl
rm
save_schedule_group_course.php
25367
0644
edit
dl
rm
schedulereportbygroup.php
17731
0644
edit
dl
rm
schedulereportbyteacher.php
19111
0644
edit
dl
rm
scheduleteacherbygroupreport - Copy.php
31986
0644
edit
dl
rm
scheduleteacherbygroupreport.php
36556
0644
edit
dl
rm
scheduleteacherreport.php
28150
0644
edit
dl
rm
schedule_report.php
17664
0644
edit
dl
rm
Schedule_Report_by_Group.php
3647
0644
edit
dl
rm
Schedule_Report_by_Teacher.php
92433
0644
edit
dl
rm
selectuser.php
1172
0644
edit
dl
rm
swapcourses.php
19469
0644
edit
dl
rm
teacher_preference.php
18182
0644
edit
dl
rm
teacher_preference_by_course.php
19244
0644
edit
dl
rm
teacher_unavailability.php
17835
0644
edit
dl
rm
test.php
13895
0644
edit
dl
rm
test1.php
21837
0644
edit
dl
rm
transfer_reference.php
27288
0644
edit
dl
rm
unassigncoursereport.php
16029
0644
edit
dl
rm
unassign_course.php
19011
0644
edit
dl
rm
Unassign_Course_Report.php
1697
0644
edit
dl
rm
unscheduledgroupreport.php
15675
0644
edit
dl
rm
Unscheduled_Group_Report.php
2007
0644
edit
dl
rm
updateclient.php
14765
0644
edit
dl
rm
updatecourse.php
21626
0644
edit
dl
rm
updatecoursesessionhours.php
18197
0644
edit
dl
rm
updatecoursetime.php
21831
0644
edit
dl
rm
updategroup - Copy.php
24534
0644
edit
dl
rm
updategroup.php
18001
0644
edit
dl
rm
updateholiday.php
22493
0644
edit
dl
rm
updateteacherlevel.php
24532
0644
edit
dl
rm
updateteacherunavailability.php
14184
0644
edit
dl
rm
UpdateUser.php
18214
0644
edit
dl
rm
Update_Course_Hours.php
2135
0644
edit
dl
rm
Update_Follow_Up.php
4618
0644
edit
dl
rm
update_reserve_course.php
1934
0644
edit
dl
rm
update_teacher_level
2508
0644
edit
dl
rm
update_teacher_level.php
2430
0644
edit
dl
rm
useraccesslist.php
12875
0644
edit
dl
rm
users.php
9049
0644
edit
dl
rm
view_swap_log.php
894
0644
edit
dl
rm
Edit:
/home/techb158/workloadmatch.com/workloadmatch.com/BackUp/Manager/Schedule_Report_by_Teacher.php
(92433B)
<?php /* include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); function format_time_slot_label($slot, $day) { if (strtolower($day) === 'saturday') { return 'Morning (Sat)'; } return ucwords(strtolower(trim($slot))); } function format_saturday_time_override($day) { return (strtolower($day) === 'saturday') ? '09:00 AM - 01:00 PM' : null; } function get_group_slot_time($groupId, $slot, $mysqli) { $slotFormatted = ucwords(strtolower(trim($slot))); $stmt = $mysqli->prepare("SELECT Time_From, Time_To FROM Group_Slot_Mapping WHERE Group_ID = ? AND LOWER(TRIM(Time_Slot)) = LOWER(TRIM(?)) LIMIT 1"); $stmt->bind_param("is", $groupId, $slotFormatted); $stmt->execute(); $res = $stmt->get_result()->fetch_assoc(); $stmt->close(); if ($res) { return date('h:i A', strtotime($res['Time_From'])) . ' - ' . date('h:i A', strtotime($res['Time_To'])); } return '-'; } if (isset($_POST['Program_ID'], $_POST['Group_ID'], $_POST['Teacher_ID'])) { $Program_ID = intval($_POST['Program_ID']); $Group_ID = intval($_POST['Group_ID']); $Teacher_ID = intval($_POST['Teacher_ID']); $stmt = $mysqli->prepare("SELECT class_days FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"); $stmt->bind_param("ii", $Group_ID, $Program_ID); $stmt->execute(); $groupData = $stmt->get_result()->fetch_assoc(); $stmt->close(); if (!$groupData) die("Group not found."); $groupClassDays = array_map('trim', explode(',', $groupData['class_days'])); $stmt = $mysqli->prepare("SELECT scg.*, c.Course_Name FROM Schedule_Course_for_Group scg JOIN Courses c ON scg.Course_ID = c.Course_ID WHERE scg.Program_ID = ? AND scg.Group_ID = ? AND scg.Assigned = 1 AND EXISTS (SELECT 1 FROM Teacher_Course_Assignments WHERE Teacher_ID = ? AND Schedule_ID = scg.Schedule_ID)"); $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); $stmt->execute(); $scheduledRows = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); $stmt = $mysqli->prepare("SELECT tra.Schedule_ID, tra.Replacement_From, tra.Replacement_To, tca.Course_ID, c.Course_Name, scg.Time_Slot, scg.Start_Date FROM Teacher_Replacement_Assignments tra JOIN Teacher_Course_Assignments tca ON tra.Schedule_ID = tca.Schedule_ID JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Schedule_Course_for_Group scg ON scg.Schedule_ID = tca.Schedule_ID WHERE tra.Replacing_Teacher_ID = ? AND scg.Group_ID = ? AND scg.Program_ID = ?"); $stmt->bind_param("iii", $Teacher_ID, $Group_ID, $Program_ID); $stmt->execute(); $replacementsRaw = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); $seenReplacements = []; foreach ($replacementsRaw as $r) { $stmt = $mysqli->prepare("SELECT DISTINCT Start_Date FROM Schedule_Course_for_Group WHERE Schedule_ID = ? AND Start_Date BETWEEN ? AND ?"); $stmt->bind_param("iss", $r['Schedule_ID'], $r['Replacement_From'], $r['Replacement_To']); $stmt->execute(); $replacementDays = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); foreach ($replacementDays as $rd) { $dateKey = $rd['Start_Date'] . '-' . $r['Schedule_ID']; if (!isset($seenReplacements[$dateKey])) { $seenReplacements[$dateKey] = true; $scheduledRows[] = [ 'Start_Date' => $rd['Start_Date'], 'Course_Name' => $r['Course_Name'], 'Time_Slot' => $r['Time_Slot'], 'Course_ID' => $r['Course_ID'], 'Replacement_Mode' => true ]; } } } $absentDates = []; $stmt = $mysqli->prepare("SELECT Replacement_From, Replacement_To FROM Teacher_Replacement_Assignments WHERE Absent_Teacher_ID = ?"); $stmt->bind_param("i", $Teacher_ID); $stmt->execute(); $absents = $stmt->get_result(); while ($rep = $absents->fetch_assoc()) { $start = new DateTime($rep['Replacement_From']); $end = (new DateTime($rep['Replacement_To']))->modify('+1 day'); foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $d) { $absentDates[$d->format('Y-m-d')] = true; } } $stmt->close(); $examDates = []; $stmt = $mysqli->prepare("SELECT Course_ID, MAX(Start_Date) AS ExamDate FROM Schedule_Course_for_Group WHERE Program_ID = ? AND Group_ID = ? GROUP BY Course_ID"); $stmt->bind_param("ii", $Program_ID, $Group_ID); $stmt->execute(); $stmt->bind_result($cid, $examDate); while ($stmt->fetch()) { $examDates[$cid] = $examDate; } $stmt->close(); $holidays = []; $res = $mysqli->query("SELECT Event_Title, Event_Start, Event_End, Event_Color FROM Events"); while ($row = $res->fetch_assoc()) { $start = new DateTime($row['Event_Start']); $end = new DateTime($row['Event_End']); while ($start <= $end) { $d = $start->format('Y-m-d'); $holidays[$d] = [ 'title' => $row['Event_Title'], 'color' => $row['Event_Color'] ?: '#FFD700' ]; $start->modify('+1 day'); } } $retakes = []; $stmt = $mysqli->prepare("SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"); $stmt->bind_param("ii", $Program_ID, $Group_ID); $stmt->execute(); $stmt->bind_result($rDate); while ($stmt->fetch()) { $retakes[$rDate] = 'Retake'; } $stmt->close(); echo "<div class='box-body table-responsive no-padding'>"; echo "<table id='example2' class='table table-bordered table-striped'><thead><tr><th>Date</th><th>Course</th><th>Time Slot</th><th>Time</th><th>Type</th></tr></thead><tbody>"; $allDates = []; foreach ($scheduledRows as $row) { $allDates[$row['Start_Date']][] = $row; } $extraDates = array_merge(array_keys($holidays), array_keys($retakes)); foreach ($extraDates as $d) { if (!isset($allDates[$d])) { $allDates[$d] = []; } } ksort($allDates); foreach ($allDates as $currentDate => $sessions) { $day = (new DateTime($currentDate))->format('l'); if (isset($holidays[$currentDate]) && empty($sessions)) { $h = $holidays[$currentDate]; echo "<tr style='background-color:{$h['color']}'><td>$currentDate</td><td>{$h['title']}</td><td>-</td><td>-</td><td>Holiday</td></tr>"; continue; } if (isset($retakes[$currentDate]) && empty($sessions)) { echo "<tr style='background-color:#D9EDF7'><td>$currentDate</td><td>Retake</td><td>-</td><td>-</td><td>Retake</td></tr>"; continue; } foreach ($sessions as $row) { $isAbsent = isset($absentDates[$currentDate]) && empty($row['Replacement_Mode']); $type = ($examDates[$row['Course_ID']] === $currentDate) ? 'Exam Day' : ($isAbsent ? 'Absent' : (isset($row['Replacement_Mode']) ? 'Replacement' : 'Regular')); $style = ''; if ($type === 'Exam Day') $style = "style='background-color:#FFCCCC;'"; elseif ($type === 'Replacement') $style = "style='background-color:#ccffcc;'"; elseif ($type === 'Absent') $style = "style='background-color:#ffcccc;'"; $slotLabel = format_time_slot_label($row['Time_Slot'], $day); $time = format_saturday_time_override($day) ?: get_group_slot_time($Group_ID, $row['Time_Slot'], $mysqli); echo "<tr $style><td>$currentDate</td><td>{$row['Course_Name']}</td><td>$slotLabel</td><td>$time</td><td>$type</td></tr>"; } } echo "</tbody></table></div>"; } */ include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); function format_time_slot_label($slot, $day) { if (strtolower($day) === 'saturday') { return 'Morning (Sat)'; } return ucwords(strtolower(trim($slot))); } function format_saturday_time_override($day) { return (strtolower($day) === 'saturday') ? '09:00 AM - 01:00 PM' : null; } function get_group_slot_time($groupId, $slot, $mysqli) { $stmt = $mysqli->prepare("SELECT Time_From, Time_To FROM Group_Slot_Mapping WHERE Group_ID = ? AND LOWER(TRIM(Time_Slot)) = LOWER(TRIM(?)) LIMIT 1"); $stmt->bind_param("is", $groupId, $slot); $stmt->execute(); $res = $stmt->get_result()->fetch_assoc(); $stmt->close(); if ($res) { return date('h:i A', strtotime($res['Time_From'])) . ' - ' . date('h:i A', strtotime($res['Time_To'])); } return '-'; } if (isset($_POST['Program_ID'], $_POST['Group_ID'], $_POST['Teacher_ID'])) { $Program_ID = intval($_POST['Program_ID']); $Group_ID = intval($_POST['Group_ID']); $Teacher_ID = intval($_POST['Teacher_ID']); // Get class days $stmt = $mysqli->prepare("SELECT class_days FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"); $stmt->bind_param("ii", $Group_ID, $Program_ID); $stmt->execute(); $groupData = $stmt->get_result()->fetch_assoc(); $stmt->close(); if (!$groupData) die("Group not found."); $groupClassDays = array_map('trim', explode(',', $groupData['class_days'])); // Main teacher assignments $stmt = $mysqli->prepare(" SELECT scg.*, c.Course_Name FROM Schedule_Course_for_Group scg JOIN Courses c ON scg.Course_ID = c.Course_ID JOIN Teacher_Course_Assignments tca ON scg.Schedule_ID = tca.Schedule_ID WHERE scg.Program_ID = ? AND scg.Group_ID = ? AND scg.Assigned = 1 AND tca.Teacher_ID = ? "); $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); $stmt->execute(); $scheduledRows = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); // Teacher replacements $stmt = $mysqli->prepare(" SELECT tra.Schedule_ID, tra.Replacement_From, tra.Replacement_To, tca.Course_ID, c.Course_Name, scg.Time_Slot, scg.Start_Date FROM Teacher_Replacement_Assignments tra JOIN Teacher_Course_Assignments tca ON tra.Schedule_ID = tca.Schedule_ID JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Schedule_Course_for_Group scg ON scg.Schedule_ID = tca.Schedule_ID WHERE tra.Replacing_Teacher_ID = ? AND scg.Group_ID = ? AND scg.Program_ID = ? "); $stmt->bind_param("iii", $Teacher_ID, $Group_ID, $Program_ID); $stmt->execute(); $replacementsRaw = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); $seenReplacements = []; foreach ($replacementsRaw as $r) { $stmt = $mysqli->prepare("SELECT DISTINCT Start_Date FROM Schedule_Course_for_Group WHERE Schedule_ID = ? AND Start_Date BETWEEN ? AND ?"); $stmt->bind_param("iss", $r['Schedule_ID'], $r['Replacement_From'], $r['Replacement_To']); $stmt->execute(); $replacementDays = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); foreach ($replacementDays as $rd) { $dateKey = $rd['Start_Date'] . '-' . $r['Schedule_ID']; if (!isset($seenReplacements[$dateKey])) { $seenReplacements[$dateKey] = true; $scheduledRows[] = [ 'Start_Date' => $rd['Start_Date'], 'Course_Name' => $r['Course_Name'], 'Time_Slot' => $r['Time_Slot'], 'Course_ID' => $r['Course_ID'], 'Replacement_Mode' => true ]; } } } // Teacher absences $absentDates = []; $stmt = $mysqli->prepare("SELECT Replacement_From, Replacement_To FROM Teacher_Replacement_Assignments WHERE Absent_Teacher_ID = ?"); $stmt->bind_param("i", $Teacher_ID); $stmt->execute(); $absents = $stmt->get_result(); while ($rep = $absents->fetch_assoc()) { $start = new DateTime($rep['Replacement_From']); $end = (new DateTime($rep['Replacement_To']))->modify('+1 day'); foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $d) { $absentDates[$d->format('Y-m-d')] = true; } } $stmt->close(); // Exam days (last day per course) $examDates = []; $stmt = $mysqli->prepare("SELECT Course_ID, MAX(Start_Date) AS ExamDate FROM Schedule_Course_for_Group WHERE Program_ID = ? AND Group_ID = ? GROUP BY Course_ID"); $stmt->bind_param("ii", $Program_ID, $Group_ID); $stmt->execute(); $stmt->bind_result($cid, $examDate); while ($stmt->fetch()) { $examDates[$cid] = $examDate; } $stmt->close(); // Holidays $holidays = []; $res = $mysqli->query("SELECT Event_Title, Event_Start, Event_End, Event_Color FROM Events"); while ($row = $res->fetch_assoc()) { $start = new DateTime($row['Event_Start']); $end = new DateTime($row['Event_End']); while ($start <= $end) { $d = $start->format('Y-m-d'); $holidays[$d] = [ 'title' => $row['Event_Title'], 'color' => $row['Event_Color'] ?: '#FFD700' ]; $start->modify('+1 day'); } } // Retakes $retakes = []; $stmt = $mysqli->prepare("SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"); $stmt->bind_param("ii", $Program_ID, $Group_ID); $stmt->execute(); $stmt->bind_result($rDate); while ($stmt->fetch()) { $retakes[$rDate] = 'Retake'; } $stmt->close(); // Output HTML table echo "<div class='box-body table-responsive no-padding'>"; echo "<table id='example2' class='table table-bordered table-striped'><thead><tr><th>Date</th><th>Course</th><th>Time Slot</th><th>Time</th><th>Type</th></tr></thead><tbody>"; $allDates = []; foreach ($scheduledRows as $row) { $allDates[$row['Start_Date']][] = $row; } $extraDates = array_merge(array_keys($holidays), array_keys($retakes)); foreach ($extraDates as $d) { if (!isset($allDates[$d])) { $allDates[$d] = []; } } ksort($allDates); foreach ($allDates as $currentDate => $sessions) { $day = (new DateTime($currentDate))->format('l'); if (isset($holidays[$currentDate]) && empty($sessions)) { $h = $holidays[$currentDate]; echo "<tr style='background-color:{$h['color']}'><td>$currentDate</td><td>{$h['title']}</td><td>-</td><td>-</td><td>Holiday</td></tr>"; continue; } if (isset($retakes[$currentDate]) && empty($sessions)) { echo "<tr style='background-color:#D9EDF7'><td>$currentDate</td><td>Retake</td><td>-</td><td>-</td><td>Retake</td></tr>"; continue; } foreach ($sessions as $row) { $isAbsent = isset($absentDates[$currentDate]) && empty($row['Replacement_Mode']); $type = ($examDates[$row['Course_ID']] === $currentDate) ? 'Exam Day' : ($isAbsent ? 'Absent' : (isset($row['Replacement_Mode']) ? 'Replacement' : 'Regular')); $style = ''; if ($type === 'Exam Day') $style = "style='background-color:#FFCCCC;'"; elseif ($type === 'Replacement') $style = "style='background-color:#ccffcc;'"; elseif ($type === 'Absent') $style = "style='background-color:#ffcccc;'"; $slotLabel = format_time_slot_label($row['Time_Slot'], $day); $time = format_saturday_time_override($day) ?: get_group_slot_time($Group_ID, $row['Time_Slot'], $mysqli); echo "<tr $style><td>$currentDate</td><td>{$row['Course_Name']}</td><td>$slotLabel</td><td>$time</td><td>$type</td></tr>"; } } echo "</tbody></table></div>"; } /***********************Orgenal Code**************************** include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); function format_time_slot_label($slot, $day) { if ($day === 'Saturday') { if (stripos($slot, 'evening') !== false) return 'Morning (Sat)'; if (stripos($slot, 'morning') !== false) return 'Morning'; } return $slot; } function format_time_slot_range($slot, $start, $end, $day) { if ($day === 'Saturday') { if (stripos($slot, 'morning') !== false) return "08:30 AM - 12:30 PM"; if (stripos($slot, 'evening') !== false) return "09:00 AM - 01:00 PM"; } return date('h:i A', strtotime($start)) . ' - ' . date('h:i A', strtotime($end)); } if (isset($_POST['Program_ID'], $_POST['Group_ID'], $_POST['Teacher_ID'])) { $Program_ID = intval($_POST['Program_ID']); $Group_ID = intval($_POST['Group_ID']); $Teacher_ID = intval($_POST['Teacher_ID']); // 1. Get group details $stmt = $mysqli->prepare("SELECT class_days FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"); $stmt->bind_param("ii", $Group_ID, $Program_ID); $stmt->execute(); $groupData = $stmt->get_result()->fetch_assoc(); $stmt->close(); if (!$groupData) die("Group not found."); $groupClassDays = array_map('trim', explode(',', $groupData['class_days'])); // 2. Get teacher assignments $stmt = $mysqli->prepare("SELECT tca.*, c.Course_Name, cg.Time_Slot, cg.Start_Time AS Schedule_Start_Time, cg.End_Time AS Schedule_End_Time FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Course_Group_Schedule cg ON tca.Schedule_ID = cg.Schedule_ID WHERE tca.Program_ID = ? AND tca.Group_ID = ? AND tca.Teacher_ID = ?"); $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); $stmt->execute(); $assignments = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); // 3. Replacements $stmt = $mysqli->prepare("SELECT tra.Replacement_From, tra.Replacement_To, tca.*, c.Course_Name, cg.Time_Slot, cg.Start_Time AS Schedule_Start_Time, cg.End_Time AS Schedule_End_Time FROM Teacher_Replacement_Assignments tra JOIN Teacher_Course_Assignments tca ON tra.Schedule_ID = tca.Schedule_ID JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Course_Group_Schedule cg ON cg.Schedule_ID = tca.Schedule_ID WHERE tra.Replacing_Teacher_ID = ? AND cg.Group_ID = ? AND cg.Program_ID = ?"); $stmt->bind_param("iii", $Teacher_ID, $Group_ID, $Program_ID); $stmt->execute(); $replacements = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); foreach ($replacements as &$r) { $r['Replacement_Mode'] = true; } // 4. Absences $absentDates = []; $stmt = $mysqli->prepare("SELECT Replacement_From, Replacement_To FROM Teacher_Replacement_Assignments WHERE Absent_Teacher_ID = ?"); $stmt->bind_param("i", $Teacher_ID); $stmt->execute(); $absents = $stmt->get_result(); while ($rep = $absents->fetch_assoc()) { $start = new DateTime($rep['Replacement_From']); $end = (new DateTime($rep['Replacement_To']))->modify('+1 day'); foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $d) { $absentDates[$d->format('Y-m-d')] = true; } } $stmt->close(); // 5. Holidays $holidayMapping = []; $res = $mysqli->query("SELECT Event_Title, Event_Start, Event_End, Event_Color FROM Events"); while ($event = $res->fetch_assoc()) { $start = new DateTime($event['Event_Start']); $end = (new DateTime($event['Event_End']))->modify('+1 day'); foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $d) { $holidayMapping[$d->format('Y-m-d')][] = [ 'title' => $event['Event_Title'], 'color' => $event['Event_Color'] ]; } } // 6. Retakes $retakes = []; $stmt = $mysqli->prepare("SELECT rr.Retake_Date, tsp.Time_Slot FROM Retake_Records rr JOIN Time_Slot_Programs tsp ON rr.Time_Slot_Programs_ID = tsp.Time_Slot_Programs_ID WHERE rr.Program_ID = ? AND rr.Group_ID = ?"); $stmt->bind_param("ii", $Program_ID, $Group_ID); $stmt->execute(); $retakes = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); // 7. Build date range $combined = array_merge($assignments, $replacements); $dates = []; foreach ($combined as $a) { $s = new DateTime($a['Replacement_Mode'] ? $a['Replacement_From'] : $a['Start_Date']); $e = new DateTime($a['Replacement_Mode'] ? $a['Replacement_To'] : $a['End_Date']); $dates[] = $s->format('Y-m-d'); $dates[] = $e->format('Y-m-d'); } $start = new DateTime(min($dates)); $end = (new DateTime(max($dates)))->modify('+1 day'); $range = new DatePeriod($start, new DateInterval('P1D'), $end); // 8. Output report echo "<div class='box-body table-responsive no-padding'>"; echo "<table id='example2' class='table table-bordered table-striped'> <thead><tr><th>Date</th><th>Course</th><th>Time Slot</th><th>Time</th><th>Type</th></tr></thead><tbody>"; foreach ($range as $date) { $day = $date->format('l'); $currentDate = $date->format('Y-m-d'); // Holiday if (isset($holidayMapping[$currentDate])) { foreach ($holidayMapping[$currentDate] as $event) { echo "<tr style='background-color:{$event['color']}'><td>$currentDate</td><td>{$event['title']}</td><td>-</td><td>-</td><td>Holiday</td></tr>"; } continue; } // Retakes foreach ($retakes as $r) { if ($r['Retake_Date'] === $currentDate) { $label = format_time_slot_label($r['Time_Slot'], $day); echo "<tr style='background-color:lightgray'><td>$currentDate</td><td>Retake</td><td>$label</td><td>-</td><td>Retake</td></tr>"; } } // Classes foreach ($combined as $a) { $s = new DateTime($a['Replacement_Mode'] ? $a['Replacement_From'] : $a['Start_Date']); $e = new DateTime($a['Replacement_Mode'] ? $a['Replacement_To'] : $a['End_Date']); $e->modify('+1 day'); if ($date >= $s && $date < $e) { if (!in_array($day, $groupClassDays) && $currentDate != $a['End_Date']) continue; $skip = false; foreach ($retakes as $r) { if ($r['Retake_Date'] === $currentDate && strtolower(trim($r['Time_Slot'])) === strtolower(trim($a['Time_Slot']))) { $skip = true; break; } } if ($skip) continue; //$type = $a['Replacement_Mode'] ? 'Replacement' : (($currentDate == $a['End_Date']) ? 'Exam Day' : 'Regular'); //$bg = $a['Replacement_Mode'] ? "style='background-color:#ccffcc'" : (isset($absentDates[$currentDate]) ? "style='background-color:#ffcccc'" : ""); $type = $a['Replacement_Mode'] ? 'Replacement' : (($currentDate == $a['End_Date']) ? 'Exam Day' : 'Regular'); // Set background color based on type if (isset($absentDates[$currentDate]) && !$a['Replacement_Mode']) { $type = 'Absent'; $bg = "style='background-color:#ffcccc'"; // Light red } elseif ($type === 'Exam Day') { $bg = "style='background-color:#fff3cd'"; // Light yellow } elseif ($a['Replacement_Mode']) { $bg = "style='background-color:#ccffcc'"; // Light green } else { $bg = ""; // No background } $slotLabel = format_time_slot_label($a['Time_Slot'], $day); $time = format_time_slot_range($a['Time_Slot'], $a['Schedule_Start_Time'], $a['Schedule_End_Time'], $day); echo "<tr $bg><td>$currentDate</td><td>{$a['Course_Name']}</td><td>$slotLabel</td><td>$time</td><td>$type</td></tr>"; // echo "<tr $bg><td>$currentDate</td><td>{$a['Course_Name']}</td><td>$slotLabel</td><td>$time</td><td>$type</td></tr>"; } } } echo "</tbody></table></div>"; } **/ /* if (isset($_POST['Program_ID']) && isset($_POST['Group_ID']) && isset($_POST['Teacher_ID'])) { $Program_ID = intval($_POST['Program_ID']); $Group_ID = intval($_POST['Group_ID']); $Teacher_ID = intval($_POST['Teacher_ID']); // 1. Group Details $stmtGroup = $mysqli->prepare("SELECT * FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"); $stmtGroup->bind_param("ii", $Group_ID, $Program_ID); $stmtGroup->execute(); $groupData = $stmtGroup->get_result()->fetch_assoc(); $stmtGroup->close(); if (!$groupData) die("Group not found."); $groupClassDays = explode(',', trim($groupData['class_days'])); // 2. Teacher Assignments $stmt = $mysqli->prepare("SELECT tca.*, c.Course_Name, cg.Start_Time AS Schedule_Start_Time, cg.End_Time AS Schedule_End_Time FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Course_Group_Schedule cg ON tca.Schedule_ID = cg.Schedule_ID WHERE tca.Program_ID = ? AND tca.Group_ID = ? AND tca.Teacher_ID = ?"); $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); $stmt->execute(); $assignments = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); // 3. Replacements WHERE teacher is replacing someone $replacementAssignments = []; $stmt = $mysqli->prepare("SELECT tra.Replacement_From, tra.Replacement_To, tca.*, c.Course_Name, cg.Start_Time AS Schedule_Start_Time, cg.End_Time AS Schedule_End_Time FROM Teacher_Replacement_Assignments tra JOIN Teacher_Course_Assignments tca ON tra.Schedule_ID = tca.Schedule_ID JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Course_Group_Schedule cg ON cg.Schedule_ID = tca.Schedule_ID WHERE tra.Replacing_Teacher_ID = ? AND cg.Group_ID = ? AND cg.Program_ID = ?"); $stmt->bind_param("iii", $Teacher_ID, $Group_ID, $Program_ID); $stmt->execute(); $reps = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); foreach ($reps as $r) { $r['Replacement_Mode'] = true; $replacementAssignments[] = $r; } // 4. Absence dates WHERE teacher is absent $absentDates = []; $stmt = $mysqli->prepare("SELECT Replacement_From, Replacement_To FROM Teacher_Replacement_Assignments WHERE Absent_Teacher_ID = ?"); $stmt->bind_param("i", $Teacher_ID); $stmt->execute(); $absents = $stmt->get_result(); while ($rep = $absents->fetch_assoc()) { $start = new DateTime($rep['Replacement_From']); $end = (new DateTime($rep['Replacement_To']))->modify('+1 day'); foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $d) { $absentDates[$d->format('Y-m-d')] = true; } } $stmt->close(); // 5. Holidays $holidayMapping = []; $stmt = $mysqli->prepare("SELECT Event_Title, Event_Color, Event_Start, Event_End FROM Events"); $stmt->execute(); $events = $stmt->get_result(); while ($event = $events->fetch_assoc()) { $start = new DateTime($event['Event_Start']); $end = (new DateTime($event['Event_End']))->modify('+1 day'); foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $d) { $holidayMapping[$d->format('Y-m-d')][] = [ 'title' => $event['Event_Title'], 'color' => $event['Event_Color'] ]; } } $stmt->close(); // 6. Retakes $retakes = []; $stmt = $mysqli->prepare("SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"); $stmt->bind_param("ii", $Program_ID, $Group_ID); $stmt->execute(); $retakes = array_column($stmt->get_result()->fetch_all(MYSQLI_ASSOC), 'Retake_Date'); $stmt->close(); // 7. Build total schedule list $assignments = array_merge($assignments, $replacementAssignments); $dates = []; foreach ($assignments as $a) { $s = new DateTime($a['Replacement_Mode'] ? $a['Replacement_From'] : $a['Start_Date']); $e = new DateTime($a['Replacement_Mode'] ? $a['Replacement_To'] : $a['End_Date']); $dates[] = $s->format('Y-m-d'); $dates[] = $e->format('Y-m-d'); } $start = !empty($dates) ? new DateTime(min($dates)) : new DateTime(); $end = !empty($dates) ? (new DateTime(max($dates)))->modify('+1 day') : (clone $start)->modify('+30 days'); $range = new DatePeriod($start, new DateInterval('P1D'), $end); foreach ($range as $date) { $day = $date->format('l'); $currentDate = $date->format('Y-m-d'); if (!in_array($day, array_map('trim', $groupClassDays))) continue; if (isset($holidayMapping[$currentDate])) { foreach ($holidayMapping[$currentDate] as $event) { echo "<tr style='background-color:{$event['color']}'><td>$currentDate</td><td>{$event['title']}</td><td>-</td><td>-</td><td>Holiday</td></tr>"; } continue; } if (in_array($currentDate, $retakes)) { echo "<tr style='background-color:lightgray;'><td>$currentDate</td><td>Retake Day</td><td>-</td><td>-</td><td>Retake</td></tr>"; continue; } $shown = false; foreach ($assignments as $a) { $s = new DateTime($a['Replacement_Mode'] ? $a['Replacement_From'] : $a['Start_Date']); $e = new DateTime($a['Replacement_Mode'] ? $a['Replacement_To'] : $a['End_Date']); $e->modify('+1 day'); if ($date >= $s && $date < $e) { $type = $a['Replacement_Mode'] ? 'Replacement' : (($currentDate == $a['End_Date']) ? 'Exam Day' : 'Regular'); $bg = $a['Replacement_Mode'] ? "background-color:#ccffcc" : (isset($absentDates[$currentDate]) ? "background-color:#ffcccc" : ""); if (isset($absentDates[$currentDate]) && !$a['Replacement_Mode']) { $type = 'Absent'; } $rangeTime = date('h:i A', strtotime($a['Schedule_Start_Time'])) . ' - ' . date('h:i A', strtotime($a['Schedule_End_Time'])); echo "<tr style='$bg'><td>$currentDate</td><td>{$a['Course_Name']}</td><td>{$a['Time_Slot']}</td><td>$rangeTime</td><td>$type</td></tr>"; $shown = true; } } if (!$shown) { echo "<tr style='background-color:#e0f7fa;'><td>$currentDate</td><td>No Class</td><td>-</td><td>-</td><td>Free</td></tr>"; } } } */ /* include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); if (isset($_POST["Program_ID"]) && isset($_POST["Group_ID"]) && isset($_POST["Teacher_ID"])) { $Program_ID = $_POST['Program_ID']; $Group_ID = $_POST['Group_ID']; $Teacher_ID = $_POST['Teacher_ID']; if ($Program_ID <= 0 || $Group_ID <= 0 || $Teacher_ID <= 0) { die("Invalid parameters."); } // 1. Retrieve group details $stmtGroup = $mysqli->prepare("SELECT * FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"); if (!$stmtGroup) die("Error preparing group query: " . $mysqli->error); $stmtGroup->bind_param("ii", $Group_ID, $Program_ID); $stmtGroup->execute(); $groupData = $stmtGroup->get_result()->fetch_assoc(); $stmtGroup->close(); if (!$groupData) die("Group not found."); $groupTimeSlot = trim($groupData['Time_Slot']); $groupStartTime = $groupData['Time_From']; $groupEndTime = $groupData['Time_To']; $weekendClass = intval($groupData['Weekend_Class'] ?? 0); $groupClassDays = trim($groupData['class_days']); // 2. Fetch main assignments $stmt = $mysqli->prepare("SELECT tca.*, c.Course_Name, cg.Start_Time AS Schedule_Start_Time, cg.End_Time AS Schedule_End_Time FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Course_Group_Schedule cg ON tca.Schedule_ID = cg.Schedule_ID WHERE tca.Program_ID = ? AND tca.Group_ID = ? AND tca.Teacher_ID = ?"); if (!$stmt) die("Error preparing assignment query: " . $mysqli->error); $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); $stmt->execute(); $assignments = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); // 3. Retrieve holiday events $holidayMapping = []; $stmtEvent = $mysqli->prepare("SELECT Event_Title, Event_Color, Event_Start, Event_End FROM Events"); if ($stmtEvent) { $stmtEvent->execute(); $events = $stmtEvent->get_result(); while ($event = $events->fetch_assoc()) { $start = new DateTime($event['Event_Start']); $end = (new DateTime($event['Event_End']))->modify('+1 day'); foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $d) { $holidayMapping[$d->format('Y-m-d')][] = [ 'title' => $event['Event_Title'], 'color' => $event['Event_Color'] ]; } } $stmtEvent->close(); } // 4. Fetch retake days $retakes = []; $stmtRetake = $mysqli->prepare("SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"); if ($stmtRetake) { $stmtRetake->bind_param("ii", $Program_ID, $Group_ID); $stmtRetake->execute(); $retakes = array_column($stmtRetake->get_result()->fetch_all(MYSQLI_ASSOC), 'Retake_Date'); $stmtRetake->close(); } // 5. Fetch replacement dates for this teacher $replacementDates = []; $stmtRepl = $mysqli->prepare("SELECT Replacement_From, Replacement_To FROM Teacher_Replacement_Assignments WHERE Absent_Teacher_ID = ?"); if ($stmtRepl) { $stmtRepl->bind_param("i", $Teacher_ID); $stmtRepl->execute(); $replacements = $stmtRepl->get_result(); while ($rep = $replacements->fetch_assoc()) { $start = new DateTime($rep['Replacement_From']); $end = (new DateTime($rep['Replacement_To']))->modify('+1 day'); foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $d) { $replacementDates[$d->format('Y-m-d')] = true; } } $stmtRepl->close(); } // 6. Determine the report date range if (!empty($assignments)) { $startDates = array_column($assignments, 'Start_Date'); $endDates = array_column($assignments, 'End_Date'); $globalStart = new DateTime(min($startDates)); $globalEnd = (new DateTime(max($endDates)))->modify('+1 day'); } else { $globalStart = new DateTime(); $globalEnd = (clone $globalStart)->modify('+30 days'); } $period = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); // 7. Generate schedule rows foreach ($period as $date) { $currentDate = $date->format('Y-m-d'); $dayName = $date->format('l'); $dayOfWeek = $date->format('N'); // Check class days if (!in_array($dayName, array_map('trim', explode(',', $groupClassDays)))) continue; // Display holiday if (isset($holidayMapping[$currentDate])) { foreach ($holidayMapping[$currentDate] as $event) { echo "<tr style='background-color:" . $event['color'] . "'> <td>$currentDate</td><td>{$event['title']}</td><td>-</td><td>-</td><td>Holiday</td></tr>"; } continue; } // Display retake day if (in_array($currentDate, $retakes)) { echo "<tr style='background-color:lightgray;'> <td>$currentDate</td><td>Retake Day</td><td>-</td><td>-</td><td>Retake</td></tr>"; continue; } // Check if it's an assigned or replaced day $found = false; foreach ($assignments as $a) { $start = new DateTime($a['Start_Date']); $end = (new DateTime($a['End_Date']))->modify('+1 day'); if ($date >= $start && $date < $end) { $type = ($currentDate === $a['End_Date']) ? 'Exam Day' : (isset($replacementDates[$currentDate]) ? 'Replaced' : 'Regular'); $bgColor = $type === 'Replaced' ? "style='background-color:#ffcccc;'" : ""; $timeRange = date('h:i A', strtotime($a['Schedule_Start_Time'])) . ' - ' . date('h:i A', strtotime($a['Schedule_End_Time'])); echo "<tr $bgColor><td>$currentDate</td><td>{$a['Course_Name']}</td><td>{$a['Time_Slot']}</td><td>$timeRange</td><td>$type</td></tr>"; $found = true; } } if (!$found) { echo "<tr style='background-color:#e0f7fa;'> <td>$currentDate</td><td>No Class</td><td>-</td><td>-</td><td>Free</td></tr>"; } } } */ /* include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); if (isset($_POST["Program_ID"]) && isset($_POST["Group_ID"]) && isset($_POST["Teacher_ID"])) { // Get and validate parameters. $Program_ID = $_POST['Program_ID']; $Group_ID = $_POST['Group_ID']; $Teacher_ID = $_POST['Teacher_ID']; if ($Program_ID <= 0 || $Group_ID <= 0 || $Teacher_ID <= 0) { die("Invalid parameters."); } // --------------------------------------------------- // 1. Retrieve group details from Manager_Group_Name. // --------------------------------------------------- $groupQuery = "SELECT * FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"; $stmtGroup = $mysqli->prepare($groupQuery); if (!$stmtGroup) { die("Error preparing group query: " . $mysqli->error); } $stmtGroup->bind_param("ii", $Group_ID, $Program_ID); $stmtGroup->execute(); $resultGroup = $stmtGroup->get_result(); $groupData = $resultGroup->fetch_assoc(); $stmtGroup->close(); if (!$groupData) { die("Group not found."); } // Retrieve group details. $groupTimeSlot = trim($groupData['Time_Slot']); // e.g., "Morning,Afternoon" $groupStartTime = $groupData['Time_From']; // e.g., "08:30:00" $groupEndTime = $groupData['Time_To']; // e.g., "15:30:00" $weekendClass = isset($groupData['Weekend_Class']) ? intval($groupData['Weekend_Class']) : 0; // 0 = no Saturday class $groupClassDays = trim($groupData['class_days']); // e.g., "Monday,Tuesday,Wednesday,Thursday,Friday" // --------------------------------------------------- // 2. Retrieve assignments for this teacher. // --------------------------------------------------- // Now join with Course_Group_Schedule (alias: cg). Note that the table contains Start_Time and End_Time. $assignmentQuery = "SELECT tca.*, c.Course_Name, c.Course_Time, cg.Start_Time AS Schedule_Start_Time, cg.End_Time AS Schedule_End_Time FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Course_Group_Schedule cg ON tca.Schedule_ID = cg.Schedule_ID WHERE tca.Program_ID = ? AND tca.Group_ID = ? AND tca.Teacher_ID = ? ORDER BY tca.Assigned_At DESC"; $stmt = $mysqli->prepare($assignmentQuery); if (!$stmt) { die("Error preparing assignment query: " . $mysqli->error); } $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); if (!$stmt->execute()) { die("Error executing assignment query: " . $stmt->error); } $result = $stmt->get_result(); $assignments = []; while ($row = $result->fetch_assoc()) { $assignments[] = $row; } $stmt->close(); // --------------------------------------------------- // 3. Retrieve holiday events from the Events table. // --------------------------------------------------- $eventQuery = "SELECT Event_Title, Event_Color, Event_Start, Event_End FROM Events"; $stmtEvent = $mysqli->prepare($eventQuery); if ($stmtEvent) { $stmtEvent->execute(); $eventResult = $stmtEvent->get_result(); $holidayMapping = []; // key: date (Y-m-d) => array of event details. while ($event = $eventResult->fetch_assoc()) { $startEvent = new DateTime($event['Event_Start']); $endEvent = new DateTime($event['Event_End']); $endEvent->modify('+1 day'); // Include the last day. $interval = new DateInterval('P1D'); $period = new DatePeriod($startEvent, $interval, $endEvent); foreach ($period as $dt) { $d = $dt->format('Y-m-d'); $holidayMapping[$d][] = [ 'title' => $event['Event_Title'], 'color' => $event['Event_Color'] ]; } } $stmtEvent->close(); } else { $holidayMapping = []; } // --------------------------------------------------- // 4. Retrieve retake dates from the Retake_Records table. // --------------------------------------------------- $retakeQuery = "SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"; $stmtRetake = $mysqli->prepare($retakeQuery); if ($stmtRetake) { $stmtRetake->bind_param("ii", $Program_ID, $Group_ID); $stmtRetake->execute(); $retakeResult = $stmtRetake->get_result(); $retakes = []; while ($r = $retakeResult->fetch_assoc()) { $retakes[] = $r['Retake_Date']; } $stmtRetake->close(); } else { $retakes = []; } // --------------------------------------------------- // 5. Determine a global date range for the report (based on assignments). // --------------------------------------------------- if (!empty($assignments)) { $globalStart = new DateTime($assignments[0]['Start_Date']); $globalEnd = new DateTime($assignments[0]['End_Date']); foreach ($assignments as $assignment) { $d1 = new DateTime($assignment['Start_Date']); $d2 = new DateTime($assignment['End_Date']); if ($d1 < $globalStart) { $globalStart = $d1; } if ($d2 > $globalEnd) { $globalEnd = $d2; } } $globalEnd->modify('+1 day'); // Make the end date inclusive. $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } else { $globalStart = new DateTime(); $globalEnd = clone $globalStart; $globalEnd->modify('+30 days'); $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } // --------------------------------------------------- // 6. Generate the day-by-day report. // --------------------------------------------------- // Break group time slot into periods (if defined). $groupPeriods = array_map('trim', explode(',', $groupTimeSlot)); // Always define $singlePeriodStart and $singlePeriodEnd using the overall group times. if (!empty($groupStartTime) && !empty($groupEndTime)) { try { $singlePeriodStart = new DateTime($groupStartTime); $singlePeriodEnd = new DateTime($groupEndTime); } catch (Exception $e) { $singlePeriodStart = new DateTime("08:00:00"); $singlePeriodEnd = new DateTime("15:00:00"); } } else { $singlePeriodStart = new DateTime("08:00:00"); $singlePeriodEnd = new DateTime("15:00:00"); } // Loop through each day in the global period. foreach ($globalPeriod as $date) { if (!($date instanceof DateTime)) { continue; } $currentDate = $date->format('Y-m-d'); $dayOfWeek = $date->format('N'); // 1 (Monday) to 7 (Sunday) $currentDay = $date->format('l'); // e.g., "Monday" // --- Custom Class Days Check --- if (!empty($groupClassDays)) { $customDays = array_map('trim', explode(',', $groupClassDays)); if (!in_array($currentDay, $customDays)) { continue; // Skip this date if it is not one of the custom class days. } } else { if ($dayOfWeek == 7) { continue; } if ($dayOfWeek == 6 && $weekendClass == 0) { continue; } } // --- Exclusion Check: Holidays and Retake Days --- if (isset($holidayMapping[$currentDate])) { foreach ($holidayMapping[$currentDate] as $event) { echo "<tr style='background-color:" . htmlspecialchars($event['color']) . ";'> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($event['title']) . "</td> <td>-</td> <td>-</td> <td>Holiday</td> </tr>"; } continue; } if (in_array($currentDate, $retakes)) { echo "<tr style='background-color:lightgray;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>Retake Day</td> <td>-</td> <td>-</td> <td>Retake</td> </tr>"; continue; } // --- Regular Class Days --- $foundAssignment = false; foreach ($assignments as $assignment) { $assignStart = new DateTime($assignment['Start_Date']); $assignEnd = new DateTime($assignment['End_Date']); $assignEnd->modify('+1 day'); // Make the assignment period inclusive. if ($date >= $assignStart && $date < $assignEnd) { // Try to use the Schedule times from Course_Group_Schedule first. $slotStart = null; $slotEnd = null; if (!empty($assignment['Schedule_Start_Time']) && !empty($assignment['Schedule_End_Time'])) { try { $slotStart = new DateTime($assignment['Schedule_Start_Time']); $slotEnd = new DateTime($assignment['Schedule_End_Time']); } catch (Exception $e) { // If parsing fails, leave them as null to trigger fallback. $slotStart = null; $slotEnd = null; } } // If schedule times are not available, or if they were invalid, fall back on group-defined times if (empty($slotStart) || empty($slotEnd)) { $slot = strtolower(trim($assignment['Time_Slot'])); switch ($slot) { case 'morning': if (!empty($groupData['Morning_From']) && !empty($groupData['Morning_To'])) { try { $slotStart = new DateTime($groupData['Morning_From']); $slotEnd = new DateTime($groupData['Morning_To']); } catch (Exception $e) { $slotStart = new DateTime("08:30:00"); $slotEnd = new DateTime("12:00:00"); } } else { $slotStart = new DateTime("08:30:00"); $slotEnd = new DateTime("12:00:00"); } break; case 'afternoon': if (!empty($groupData['Afternoon_From']) && !empty($groupData['Afternoon_To'])) { try { $slotStart = new DateTime($groupData['Afternoon_From']); $slotEnd = new DateTime($groupData['Afternoon_To']); } catch (Exception $e) { $slotStart = new DateTime("01:00:00"); $slotEnd = new DateTime("05:00:00"); } } else { $slotStart = new DateTime("01:00:00"); $slotEnd = new DateTime("05:00:00"); } break; case 'evening': if (!empty($groupData['Evening_From']) && !empty($groupData['Evening_To'])) { try { $slotStart = new DateTime($groupData['Evening_From']); $slotEnd = new DateTime($groupData['Evening_To']); } catch (Exception $e) { $slotStart = new DateTime("05:30:00"); $slotEnd = new DateTime("09:00:00"); } } else { $slotStart = new DateTime("05:30:00"); $slotEnd = new DateTime("09:00:00"); } break; default: // For unknown or missing time slot values, fallback to overall group times. $slotStart = $singlePeriodStart; $slotEnd = $singlePeriodEnd; break; } } // Format the time range. $timeRange = $slotStart->format("h:i A") . " - " . $slotEnd->format("h:i A"); // Determine the type: if current date equals the actual End_Date, mark as Exam Day. $actualEnd = new DateTime($assignment['End_Date']); $type = "Regular"; if ($currentDate === $actualEnd->format("Y-m-d")) { $type = "Exam Day"; } echo "<tr> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($assignment['Course_Name']) . "</td> <td>" . htmlspecialchars($assignment['Time_Slot']) . "</td> <td>" . htmlspecialchars($timeRange) . "</td> <td>" . htmlspecialchars($type) . "</td> </tr>"; $foundAssignment = true; } } if (!$foundAssignment) { // Output a row for free days. echo "<tr style='background-color:#e0f7fa;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>No Class</td> <td>-</td> <td>-</td> <td>Free</td> </tr>"; } } } */ /* include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); if (isset($_POST["Program_ID"]) && isset($_POST["Group_ID"]) && isset($_POST["Teacher_ID"])) { // Get and validate parameters. $Program_ID = $_POST['Program_ID']; $Group_ID = $_POST['Group_ID']; $Teacher_ID = $_POST['Teacher_ID']; if ($Program_ID <= 0 || $Group_ID <= 0 || $Teacher_ID <= 0) { die("Invalid parameters."); } // --------------------------------------------------- // 1. Retrieve group details from Manager_Group_Name. // --------------------------------------------------- $groupQuery = "SELECT * FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"; $stmtGroup = $mysqli->prepare($groupQuery); if (!$stmtGroup) { die("Error preparing group query: " . $mysqli->error); } $stmtGroup->bind_param("ii", $Group_ID, $Program_ID); $stmtGroup->execute(); $resultGroup = $stmtGroup->get_result(); $groupData = $resultGroup->fetch_assoc(); $stmtGroup->close(); if (!$groupData) { die("Group not found."); } // Retrieve group details. $groupTimeSlot = trim($groupData['Time_Slot']); // e.g., "Morning,Afternoon" $groupStartTime = $groupData['Time_From']; // e.g., "08:30:00" $groupEndTime = $groupData['Time_To']; // e.g., "15:30:00" $weekendClass = isset($groupData['Weekend_Class']) ? intval($groupData['Weekend_Class']) : 0; // 0 = no Saturday class $groupClassDays = trim($groupData['class_days']); // e.g., "Monday,Tuesday,Wednesday,Thursday,Friday" // --------------------------------------------------- // 2. Retrieve assignments for this teacher. // --------------------------------------------------- $query = "SELECT tca.*, c.Course_Name, c.Course_Time FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID WHERE tca.Program_ID = ? AND tca.Group_ID = ? AND tca.Teacher_ID = ? ORDER BY tca.Assigned_At DESC"; $stmt = $mysqli->prepare($query); if (!$stmt) { die("Error preparing assignment query: " . $mysqli->error); } $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); if (!$stmt->execute()) { die("Error executing assignment query: " . $stmt->error); } $result = $stmt->get_result(); $assignments = []; while ($row = $result->fetch_assoc()) { $assignments[] = $row; } $stmt->close(); // --------------------------------------------------- // 3. Retrieve holiday events from the Events table. // --------------------------------------------------- $eventQuery = "SELECT Event_Title, Event_Color, Event_Start, Event_End FROM Events"; $stmtEvent = $mysqli->prepare($eventQuery); if ($stmtEvent) { $stmtEvent->execute(); $eventResult = $stmtEvent->get_result(); $holidayMapping = []; // key: date (Y-m-d) => array of event details. while ($event = $eventResult->fetch_assoc()) { $startEvent = new DateTime($event['Event_Start']); $endEvent = new DateTime($event['Event_End']); $endEvent->modify('+1 day'); // Include the last day. $interval = new DateInterval('P1D'); $period = new DatePeriod($startEvent, $interval, $endEvent); foreach ($period as $dt) { $d = $dt->format('Y-m-d'); $holidayMapping[$d][] = [ 'title' => $event['Event_Title'], 'color' => $event['Event_Color'] ]; } } $stmtEvent->close(); } else { $holidayMapping = []; } // --------------------------------------------------- // 4. Retrieve retake dates from the Retake_Records table. // --------------------------------------------------- $retakeQuery = "SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"; $stmtRetake = $mysqli->prepare($retakeQuery); if ($stmtRetake) { $stmtRetake->bind_param("ii", $Program_ID, $Group_ID); $stmtRetake->execute(); $retakeResult = $stmtRetake->get_result(); $retakes = []; while ($r = $retakeResult->fetch_assoc()) { $retakes[] = $r['Retake_Date']; } $stmtRetake->close(); } else { $retakes = []; } // --------------------------------------------------- // 5. Determine a global date range for the report (based on assignments). // --------------------------------------------------- if (!empty($assignments)) { $globalStart = new DateTime($assignments[0]['Start_Date']); $globalEnd = new DateTime($assignments[0]['End_Date']); foreach ($assignments as $assignment) { $d1 = new DateTime($assignment['Start_Date']); $d2 = new DateTime($assignment['End_Date']); if ($d1 < $globalStart) { $globalStart = $d1; } if ($d2 > $globalEnd) { $globalEnd = $d2; } } $globalEnd->modify('+1 day'); // Make the end date inclusive. $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } else { $globalStart = new DateTime(); $globalEnd = clone $globalStart; $globalEnd->modify('+30 days'); $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } // --------------------------------------------------- // 6. Generate the day-by-day report. // --------------------------------------------------- // Break group time slot into periods (if defined). $groupPeriods = array_map('trim', explode(',', $groupTimeSlot)); // Always define $singlePeriodStart and $singlePeriodEnd using the group's overall times. if (!empty($groupStartTime) && !empty($groupEndTime)) { try { $singlePeriodStart = new DateTime($groupStartTime); $singlePeriodEnd = new DateTime($groupEndTime); } catch (Exception $e) { $singlePeriodStart = new DateTime("08:00:00"); $singlePeriodEnd = new DateTime("15:00:00"); } } else { $singlePeriodStart = new DateTime("08:00:00"); $singlePeriodEnd = new DateTime("15:00:00"); } // Loop through each day in the global period. foreach ($globalPeriod as $date) { if (!($date instanceof DateTime)) { continue; } $currentDate = $date->format('Y-m-d'); $dayOfWeek = $date->format('N'); // 1 (Monday) to 7 (Sunday) $currentDay = $date->format('l'); // e.g., "Monday" // --- Custom Class Days Check --- if (!empty($groupClassDays)) { $customDays = array_map('trim', explode(',', $groupClassDays)); if (!in_array($currentDay, $customDays)) { continue; } } else { if ($dayOfWeek == 7) { continue; } if ($dayOfWeek == 6 && $weekendClass == 0) { continue; } } // --- Exclusion Check: Holidays and Retake Days --- if (isset($holidayMapping[$currentDate])) { foreach ($holidayMapping[$currentDate] as $event) { echo "<tr style='background-color:" . htmlspecialchars($event['color']) . ";'> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($event['title']) . "</td> <td>-</td> <td>-</td> <td>Holiday</td> </tr>"; } continue; } if (in_array($currentDate, $retakes)) { echo "<tr style='background-color:lightgray;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>Retake Day</td> <td>-</td> <td>-</td> <td>Retake</td> </tr>"; continue; } //// --- Regular Class Days --- //$foundAssignment = false; //foreach ($assignments as $assignment) { // $assignStart = new DateTime($assignment['Start_Date']); // $assignEnd = new DateTime($assignment['End_Date']); // $assignEnd->modify('+1 day'); // Make the assignment period inclusive. // if ($date >= $assignStart && $date < $assignEnd) { // if ($dayOfWeek == 6) { // $timeRange = "09:00 AM - 01:00 PM"; // } else { // $timeRange = $singlePeriodStart->format("h:i A") . " - " . $singlePeriodEnd->format("h:i A"); // } // echo "<tr> // <td>" . htmlspecialchars($currentDate) . "</td> // <td>" . htmlspecialchars($assignment['Course_Name']) . "</td> // <td>" . htmlspecialchars($assignment['Time_Slot']) . "</td> // <td>" . htmlspecialchars($timeRange) . "</td> // <td>Regular</td> // </tr>"; // $foundAssignment = true; // } //} // --- Regular Class Days --- $foundAssignment = false; foreach ($assignments as $assignment) { $assignStart = new DateTime($assignment['Start_Date']); $assignEnd = new DateTime($assignment['End_Date']); $assignEnd->modify('+1 day'); // Make the assignment period inclusive. if ($date >= $assignStart && $date < $assignEnd) { // Determine the time range. if ($dayOfWeek == 6) { $timeRange = "09:00 AM - 01:00 PM"; } else { $timeRange = $singlePeriodStart->format("h:i A") . " - " . $singlePeriodEnd->format("h:i A"); } // Determine the course type: if current date is the final day of the course, mark it as Exam Day. $actualEnd = new DateTime($assignment['End_Date']); // Actual last day of the course. $type = "Regular"; if ($currentDate === $actualEnd->format("Y-m-d")) { $type = "Exam Day"; } echo "<tr> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($assignment['Course_Name']) . "</td> <td>" . htmlspecialchars($assignment['Time_Slot']) . "</td> <td>" . htmlspecialchars($timeRange) . "</td> <td>" . htmlspecialchars($type) . "</td> </tr>"; $foundAssignment = true; } } if (!$foundAssignment) { echo "<tr style='background-color:#e0f7fa;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>No Class</td> <td>-</td> <td>-</td> <td>Free</td> </tr>"; } } } */ /* include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); if (isset($_POST["Program_ID"]) && isset($_POST["Group_ID"]) && isset($_POST["Teacher_ID"])) { // Get and validate parameters $Program_ID = $_POST['Program_ID']; $Group_ID = $_POST['Group_ID']; $Teacher_ID = $_POST['Teacher_ID']; if ($Program_ID <= 0 || $Group_ID <= 0 || $Teacher_ID <= 0) { die("Invalid parameters."); } // --------------------------------------------------- // 1. Retrieve group details from Manager_Group_Name // --------------------------------------------------- $groupQuery = "SELECT * FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"; $stmtGroup = $mysqli->prepare($groupQuery); if (!$stmtGroup) { die("Error preparing group query: " . $mysqli->error); } $stmtGroup->bind_param("ii", $Group_ID, $Program_ID); $stmtGroup->execute(); $resultGroup = $stmtGroup->get_result(); $groupData = $resultGroup->fetch_assoc(); $stmtGroup->close(); if (!$groupData) { die("Group not found."); } // Retrieve group details. $groupTimeSlot = trim($groupData['Time_Slot']); // e.g., "Morning,Afternoon" $groupStartTime = $groupData['Time_From']; // e.g., "08:30:00" $groupEndTime = $groupData['Time_To']; // e.g., "15:30:00" $weekendClass = isset($groupData['Weekend_Class']) ? intval($groupData['Weekend_Class']) : 0; // 0 = no Saturday class $groupClassDays = trim($groupData['class_days']); // e.g., "Monday,Tuesday,Wednesday,Thursday,Friday" // --------------------------------------------------- // 2. Retrieve assignments for this teacher // --------------------------------------------------- $query = "SELECT tca.*, c.Course_Name, c.Course_Time FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID WHERE tca.Program_ID = ? AND tca.Group_ID = ? AND tca.Teacher_ID = ? ORDER BY tca.Assigned_At DESC"; $stmt = $mysqli->prepare($query); if (!$stmt) { die("Error preparing assignment query: " . $mysqli->error); } $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); if (!$stmt->execute()) { die("Error executing assignment query: " . $stmt->error); } $result = $stmt->get_result(); $assignments = []; while ($row = $result->fetch_assoc()) { $assignments[] = $row; } $stmt->close(); // --------------------------------------------------- // 3. Retrieve holiday events from the Events table // --------------------------------------------------- $eventQuery = "SELECT Event_Title, Event_Color, Event_Start, Event_End FROM Events"; $stmtEvent = $mysqli->prepare($eventQuery); if ($stmtEvent) { $stmtEvent->execute(); $eventResult = $stmtEvent->get_result(); $holidayMapping = []; // key: date (Y-m-d) => array of event details while ($event = $eventResult->fetch_assoc()) { $startEvent = new DateTime($event['Event_Start']); $endEvent = new DateTime($event['Event_End']); $endEvent->modify('+1 day'); // include the last day $interval = new DateInterval('P1D'); $period = new DatePeriod($startEvent, $interval, $endEvent); foreach ($period as $dt) { $d = $dt->format('Y-m-d'); $holidayMapping[$d][] = [ 'title' => $event['Event_Title'], 'color' => $event['Event_Color'] ]; } } $stmtEvent->close(); } else { $holidayMapping = []; } // --------------------------------------------------- // 4. Retrieve retake dates from Retake_Records table. // --------------------------------------------------- $retakeQuery = "SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"; $stmtRetake = $mysqli->prepare($retakeQuery); if ($stmtRetake) { $stmtRetake->bind_param("ii", $Program_ID, $Group_ID); $stmtRetake->execute(); $retakeResult = $stmtRetake->get_result(); $retakes = []; while ($r = $retakeResult->fetch_assoc()) { $retakes[] = $r['Retake_Date']; } $stmtRetake->close(); } else { $retakes = []; } // --------------------------------------------------- // 5. Determine a global date range for the report (based on assignments). // --------------------------------------------------- if (!empty($assignments)) { $globalStart = new DateTime($assignments[0]['Start_Date']); $globalEnd = new DateTime($assignments[0]['End_Date']); foreach ($assignments as $assignment) { $d1 = new DateTime($assignment['Start_Date']); $d2 = new DateTime($assignment['End_Date']); if ($d1 < $globalStart) { $globalStart = $d1; } if ($d2 > $globalEnd) { $globalEnd = $d2; } } $globalEnd->modify('+1 day'); // Make inclusive $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } else { $globalStart = new DateTime(); $globalEnd = clone $globalStart; $globalEnd->modify('+30 days'); $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } // --------------------------------------------------- // 6. Generate the day-by-day report. // --------------------------------------------------- // Before looping the days, define fallback period variables if necessary. if (!isset($groupPeriods)) { $groupPeriods = array_map('trim', explode(',', $groupTimeSlot)); } // When there's only one period defined in the group, we use the group's overall times: if (count($groupPeriods) <= 1) { $singlePeriodStart = new DateTime($groupStartTime); $singlePeriodEnd = new DateTime($groupEndTime); } // If there are at least 2 periods and they are defined elsewhere, they should be defined in your code. // (In your current snippet, variables like $firstPeriodStr, $firstPeriodStart etc. are not defined if not set.) foreach ($globalPeriod as $date) { // Ensure $date is a valid DateTime object. if (!($date instanceof DateTime)) { continue; } $currentDate = $date->format('Y-m-d'); $dayOfWeek = $date->format('N'); // 1 (Monday) to 7 (Sunday) $currentDay = $date->format('l'); // Full day name // --- Custom Days Check --- if (!empty($groupClassDays)) { $customDays = array_map('trim', explode(',', $groupClassDays)); if (!in_array($currentDay, $customDays)) { continue; // Skip this date if not in custom days. } } else { // Default: Skip Sunday and Saturday if weekendClass is not enabled. if ($dayOfWeek == 7) { continue; } if ($dayOfWeek == 6 && $weekendClass == 0) { continue; } } // --- Exclusion Check: Holidays and Retakes --- if (isset($holidayMapping[$currentDate])) { foreach ($holidayMapping[$currentDate] as $event) { echo "<tr style='background-color:" . htmlspecialchars($event['color']) . ";'> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($event['title']) . "</td> <td>-</td> <td>-</td> <td>Holiday</td> </tr>"; } continue; } if (in_array($currentDate, $retakes)) { echo "<tr style='background-color:lightgray;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>Retake Day</td> <td>-</td> <td>-</td> <td>Retake</td> </tr>"; continue; } // --- Regular Class Days --- $foundAssignment = false; foreach ($assignments as $assignment) { $assignStart = new DateTime($assignment['Start_Date']); $assignEnd = new DateTime($assignment['End_Date']); $assignEnd->modify('+1 day'); // inclusive if ($date >= $assignStart && $date < $assignEnd) { // Determine time range. // If today is Saturday, force the time range to be Morning from 09:00 AM to 01:00 PM. if ($dayOfWeek == 6) { $timeRange = "09:00 AM - 01:00 PM"; } else { // If more than one period is defined, you may have custom logic. // In this snippet, if only one period exists, use the single period defined. $timeRange = $singlePeriodStart->format("h:i A") . " - " . $singlePeriodEnd->format("h:i A"); // (If you have custom period logic for multi-period days, implement accordingly.) } echo "<tr> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($assignment['Course_Name']) . "</td> <td>" . htmlspecialchars($assignment['Time_Slot']) . "</td> <td>" . htmlspecialchars($timeRange) . "</td> <td>Regular</td> </tr>"; $foundAssignment = true; } } if (!$foundAssignment) { // For Free days, output a row in a different color (e.g., light blue). echo "<tr style='background-color:#e0f7fa;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>No Class</td> <td>-</td> <td>-</td> <td>Free</td> </tr>"; } } } */ /* include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); if (isset($_POST["Program_ID"]) && isset($_POST["Group_ID"]) && isset($_POST["Teacher_ID"])) { // Retrieve POST parameters. $Program_ID = $_POST['Program_ID']; $Group_ID = $_POST['Group_ID']; $Teacher_ID = $_POST['Teacher_ID']; if ($Program_ID <= 0 || $Group_ID <= 0 || $Teacher_ID <= 0) { die("Invalid parameters."); } // --------------------------------------------------- // 1. Retrieve group details from Manager_Group_Name // --------------------------------------------------- $groupQuery = "SELECT * FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"; $stmtGroup = $mysqli->prepare($groupQuery); if (!$stmtGroup) { die("Error preparing group query: " . $mysqli->error); } $stmtGroup->bind_param("ii", $Group_ID, $Program_ID); $stmtGroup->execute(); $resultGroup = $stmtGroup->get_result(); $groupData = $resultGroup->fetch_assoc(); $stmtGroup->close(); if (!$groupData) { die("Group not found."); } // Retrieve group details. $groupTimeSlot = trim($groupData['Time_Slot']); // e.g., "Morning,Afternoon" $groupStartTime = $groupData['Time_From']; // e.g., "08:30:00" $groupEndTime = $groupData['Time_To']; // e.g., "15:30:00" $weekendClass = isset($groupData['Weekend_Class']) ? intval($groupData['Weekend_Class']) : 0; // 0 = no Saturday // New custom days field (comma‑separated string) $groupClassDays = trim($groupData['class_days']); // e.g., "Monday,Wednesday,Friday" or default ("Monday,Tuesday,Wednesday,Thursday,Friday") // --------------------------------------------------- // 2. Retrieve assignments for this teacher // --------------------------------------------------- $query = "SELECT tca.*, c.Course_Name, c.Course_Time FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID WHERE tca.Program_ID = ? AND tca.Group_ID = ? AND tca.Teacher_ID = ? ORDER BY tca.Assigned_At DESC"; $stmt = $mysqli->prepare($query); if (!$stmt) { die("Error preparing assignment query: " . $mysqli->error); } $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); if (!$stmt->execute()) { die("Error executing assignment query: " . $stmt->error); } $result = $stmt->get_result(); $assignments = []; while ($row = $result->fetch_assoc()) { $assignments[] = $row; } $stmt->close(); // --------------------------------------------------- // 3. Retrieve holiday events from the Events table // --------------------------------------------------- $eventQuery = "SELECT Event_Title, Event_Color, Event_Start, Event_End FROM Events"; $stmtEvent = $mysqli->prepare($eventQuery); if ($stmtEvent) { $stmtEvent->execute(); $eventResult = $stmtEvent->get_result(); $holidayMapping = []; // key: date (Y-m-d) => array of event details while ($event = $eventResult->fetch_assoc()) { $startEvent = new DateTime($event['Event_Start']); $endEvent = new DateTime($event['Event_End']); $endEvent->modify('+1 day'); // include last day $interval = new DateInterval('P1D'); $period = new DatePeriod($startEvent, $interval, $endEvent); foreach ($period as $dt) { $d = $dt->format('Y-m-d'); $holidayMapping[$d][] = [ 'title' => $event['Event_Title'], 'color' => $event['Event_Color'] ]; } } $stmtEvent->close(); } else { $holidayMapping = []; } // --------------------------------------------------- // 4. Retrieve retake dates from Retake_Records table. // --------------------------------------------------- $retakeQuery = "SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"; $stmtRetake = $mysqli->prepare($retakeQuery); if ($stmtRetake) { $stmtRetake->bind_param("ii", $Program_ID, $Group_ID); $stmtRetake->execute(); $retakeResult = $stmtRetake->get_result(); $retakes = []; while ($r = $retakeResult->fetch_assoc()) { $retakes[] = $r['Retake_Date']; } $stmtRetake->close(); } else { $retakes = []; } // --------------------------------------------------- // 5. Determine a global date range for the report (based on assignments). // --------------------------------------------------- if (!empty($assignments)) { $globalStart = new DateTime($assignments[0]['Start_Date']); $globalEnd = new DateTime($assignments[0]['End_Date']); foreach ($assignments as $assignment) { $d1 = new DateTime($assignment['Start_Date']); $d2 = new DateTime($assignment['End_Date']); if ($d1 < $globalStart) { $globalStart = $d1; } if ($d2 > $globalEnd) { $globalEnd = $d2; } } $globalEnd->modify('+1 day'); // inclusive $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } else { $globalStart = new DateTime(); $globalEnd = clone $globalStart; $globalEnd->modify('+30 days'); $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } // --------------------------------------------------- // 6. Generate the day-by-day report. // --------------------------------------------------- // Loop through each day in the global date period. foreach ($globalPeriod as $date) { // Ensure $date is a valid DateTime object. if (!($date instanceof DateTime)) { continue; } $currentDate = $date->format('Y-m-d'); $dayOfWeek = $date->format('N'); // 1 (Monday) to 7 (Sunday) $currentDay = $date->format('l'); // Full day name, e.g., "Monday" // --- Custom Days Check --- // If groupClassDays is defined (non-empty) then we only process this day if it is in that list. if (!empty($groupClassDays)) { $customDays = array_map('trim', explode(',', $groupClassDays)); if (!in_array($currentDay, $customDays)) { continue; // Skip this date } } else { // No custom days defined; use default: // Always skip Sunday. if ($dayOfWeek == 7) { continue; } // Skip Saturday if weekendClass is not enabled. if ($dayOfWeek == 6 && $weekendClass == 0) { continue; } } // --- Exclusion Check for Holidays and Retakes --- if (isset($holidayMapping[$currentDate])) { foreach ($holidayMapping[$currentDate] as $event) { echo "<tr style='background-color:" . htmlspecialchars($event['color']) . ";'> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($event['title']) . "</td> <td>-</td> <td>-</td> <td>Holiday</td> </tr>"; } continue; } if (in_array($currentDate, $retakes)) { echo "<tr style='background-color:lightgray;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>Retake Day</td> <td>-</td> <td>-</td> <td>Retake</td> </tr>"; continue; } // --- Regular Class Days --- $foundAssignment = false; foreach ($assignments as $assignment) { $assignStart = new DateTime($assignment['Start_Date']); $assignEnd = new DateTime($assignment['End_Date']); $assignEnd->modify('+1 day'); // inclusive if ($date >= $assignStart && $date < $assignEnd) { // Determine time range based on assignment’s Time_Slot. $timeRange = ""; if (isset($groupPeriods) && count($groupPeriods) > 1) { if ($assignment['Time_Slot'] === $firstPeriodStr) { $timeRange = $firstPeriodStart->format("h:i A") . " - " . $firstPeriodEnd->format("h:i A"); } elseif ($assignment['Time_Slot'] === $secondPeriodStr) { $timeRange = $secondPeriodStart->format("h:i A") . " - " . $secondPeriodEnd->format("h:i A"); } else { $timeRange = "N/A"; } } else { // Define singlePeriodStart and singlePeriodEnd if not already defined. // For example, use the group's overall start and end times: $singlePeriodStart = new DateTime($groupStartTime); $singlePeriodEnd = new DateTime($groupEndTime); $timeRange = $singlePeriodStart->format("h:i A") . " - " . $singlePeriodEnd->format("h:i A"); } echo "<tr> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($assignment['Course_Name']) . "</td> <td>" . htmlspecialchars($assignment['Time_Slot']) . "</td> <td>" . htmlspecialchars($timeRange) . "</td> <td>Regular</td> </tr>"; $foundAssignment = true; // If multiple assignments apply, additional rows could be output. } } if (!$foundAssignment) { // For Free days, output a row in a different color (e.g., light blue). echo "<tr style='background-color:#e0f7fa;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>No Class</td> <td>-</td> <td>-</td> <td>Free</td> </tr>"; } } } */ /* if (isset($_POST["Program_ID"]) && isset($_POST["Group_ID"])&& isset($_POST["Teacher_ID"])) { // Get parameters via GET (or fixed for testing) //$Program_ID = isset($_GET['Program_ID']) ? intval($_GET['Program_ID']) : 1; //$Group_ID = isset($_GET['Group_ID']) ? intval($_GET['Group_ID']) : 4; //$Teacher_ID = isset($_GET['Teacher_ID']) ? intval($_GET['Teacher_ID']) : 250598; $Program_ID = $_POST['Program_ID']; $Group_ID = $_POST['Group_ID']; $Teacher_ID = $_POST['Teacher_ID']; if ($Program_ID <= 0 || $Group_ID <= 0 || $Teacher_ID <= 0) { die("Invalid parameters."); } // --------------------------------------------------- // 1. Retrieve group details from Manager_Group_Name // --------------------------------------------------- $groupQuery = "SELECT * FROM Manager_Group_Name WHERE Group_ID = ? AND Program_ID = ?"; $stmtGroup = $mysqli->prepare($groupQuery); if (!$stmtGroup) { die("Error preparing group query: " . $mysqli->error); } $stmtGroup->bind_param("ii", $Group_ID, $Program_ID); $stmtGroup->execute(); $resultGroup = $stmtGroup->get_result(); $groupData = $resultGroup->fetch_assoc(); $stmtGroup->close(); if (!$groupData) { die("Group not found."); } // Expected columns: Time_Slot, Time_From, Time_To, Weekend_Class $groupTimeSlot = trim($groupData['Time_Slot']); // e.g., "Morning,Afternoon" or "Morning" $groupStartTime = $groupData['Time_From']; // e.g., "08:30:00" $groupEndTime = $groupData['Time_To']; // e.g., "15:30:00" $weekendClass = isset($groupData['Weekend_Class']) ? intval($groupData['Weekend_Class']) : 0; // 0 = no Saturday class // Split the group's time slot field into periods. $groupPeriods = array_map('trim', explode(',', $groupTimeSlot)); if (count($groupPeriods) > 1) { $firstPeriodStr = $groupPeriods[0]; // e.g., "Morning" $secondPeriodStr = $groupPeriods[1]; // e.g., "Afternoon" $groupStartDT = new DateTime($groupStartTime); $groupEndDT = new DateTime($groupEndTime); // For the first period, assume duration of 3 hours from group start. $firstPeriodStart = clone $groupStartDT; $firstPeriodEnd = clone $groupStartDT; $firstPeriodEnd->modify('+3 hours'); // e.g., 08:30 -> 11:30 // For the second period, assume duration of 3 hours before group end. $secondPeriodEnd = clone $groupEndDT; $secondPeriodStart = clone $groupEndDT; $secondPeriodStart->modify('-3 hours'); // e.g., 15:30 -> 12:30 } else { $singlePeriod = $groupPeriods[0]; // e.g., "Morning" $singlePeriodStart = new DateTime($groupStartTime); $singlePeriodEnd = new DateTime($groupEndTime); } // --------------------------------------------------- // 2. Retrieve assignments for this teacher // --------------------------------------------------- $query = "SELECT tca.*, c.Course_Name, c.Course_Time FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID WHERE tca.Program_ID = ? AND tca.Group_ID = ? AND tca.Teacher_ID = ? ORDER BY tca.Assigned_At DESC"; $stmt = $mysqli->prepare($query); if (!$stmt) { die("Error preparing assignment query: " . $mysqli->error); } $stmt->bind_param("iii", $Program_ID, $Group_ID, $Teacher_ID); if (!$stmt->execute()) { die("Error executing assignment query: " . $stmt->error); } $result = $stmt->get_result(); $assignments = []; while ($row = $result->fetch_assoc()) { $assignments[] = $row; } $stmt->close(); // --------------------------------------------------- // 3. Retrieve holiday events from the Events table // --------------------------------------------------- $eventQuery = "SELECT Event_Title, Event_Color, Event_Start, Event_End FROM Events"; $stmtEvent = $mysqli->prepare($eventQuery); if ($stmtEvent) { //$stmtEvent->bind_param("i", $Program_ID); $stmtEvent->execute(); $eventResult = $stmtEvent->get_result(); $holidayMapping = []; // key: date (Y-m-d) => array of event details while ($event = $eventResult->fetch_assoc()) { // Generate dates from Event_Start to Event_End (inclusive) $startEvent = new DateTime($event['Event_Start']); $endEvent = new DateTime($event['Event_End']); $endEvent->modify('+1 day'); // include the last day $interval = new DateInterval('P1D'); $period = new DatePeriod($startEvent, $interval, $endEvent); foreach ($period as $dt) { $d = $dt->format('Y-m-d'); $holidayMapping[$d][] = [ 'title' => $event['Event_Title'], 'color' => $event['Event_Color'] ]; } } $stmtEvent->close(); } else { $holidayMapping = []; } // --------------------------------------------------- // 4. Retrieve retake dates from Retake_Records table. // --------------------------------------------------- $retakeQuery = "SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"; $stmtRetake = $mysqli->prepare($retakeQuery); if ($stmtRetake) { $stmtRetake->bind_param("ii", $Program_ID, $Group_ID); $stmtRetake->execute(); $retakeResult = $stmtRetake->get_result(); $retakes = []; while ($r = $retakeResult->fetch_assoc()) { $retakes[] = $r['Retake_Date']; } $stmtRetake->close(); } else { $retakes = []; } // --------------------------------------------------- // 5. Determine a global date range for the report (based on assignments). // --------------------------------------------------- if (!empty($assignments)) { $globalStart = new DateTime($assignments[0]['Start_Date']); $globalEnd = new DateTime($assignments[0]['End_Date']); foreach ($assignments as $assignment) { $d1 = new DateTime($assignment['Start_Date']); $d2 = new DateTime($assignment['End_Date']); if ($d1 < $globalStart) { $globalStart = $d1; } if ($d2 > $globalEnd) { $globalEnd = $d2; } } $globalEnd->modify('+1 day'); // Make inclusive $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } else { $globalStart = new DateTime(); $globalEnd = clone $globalStart; $globalEnd->modify('+30 days'); $globalPeriod = new DatePeriod($globalStart, new DateInterval('P1D'), $globalEnd); } // --------------------------------------------------- // 6. Generate the day-by-day report. // --------------------------------------------------- //echo "<h2>Daily Course Schedule Report for Teacher $Teacher_ID, Group $Group_ID, Program $Program_ID</h2>"; //echo "<table border='1' cellspacing='0' cellpadding='5'>"; //echo "<tr> // <th>Date</th> // <th>Course Name / Status</th> // <th>Time Slot</th> // <th>Time</th> // <th>Type</th> // </tr>"; foreach ($globalPeriod as $date) { $currentDate = $date->format('Y-m-d'); $dayOfWeek = $date->format('N'); // ISO-8601: 6 = Saturday, 7 = Sunday // --- Weekend Check --- if ($dayOfWeek == 7) { // Always skip Sunday. continue; } if ($dayOfWeek == 6 && $weekendClass == 0) { continue; } // --- Exclusion Check: If current date is a holiday or retake, output those rows and skip class row. if (isset($holidayMapping[$currentDate])) { foreach ($holidayMapping[$currentDate] as $event) { echo "<tr style='background-color:" . htmlspecialchars($event['color']) . ";'> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($event['title']) . "</td> <td>-</td> <td>-</td> <td>Holiday</td> </tr>"; } // Skip regular class row for this date. continue; } if (in_array($currentDate, $retakes)) { echo "<tr style='background-color:lightgray;'> <td>" . htmlspecialchars($currentDate) . "</td> <td>Retake Day</td> <td>-</td> <td>-</td> <td>Retake</td> </tr>"; continue; } // --- Regular Class Days --- $foundAssignment = false; foreach ($assignments as $assignment) { $assignStart = new DateTime($assignment['Start_Date']); $assignEnd = new DateTime($assignment['End_Date']); $assignEnd->modify('+1 day'); // Make inclusive if ($date >= $assignStart && $date < $assignEnd) { // Determine time range based on assignment's Time_Slot. $timeRange = ""; if (count($groupPeriods) > 1) { if ($assignment['Time_Slot'] === $firstPeriodStr) { $timeRange = $firstPeriodStart->format("h:i A") . " - " . $firstPeriodEnd->format("h:i A"); } elseif ($assignment['Time_Slot'] === $secondPeriodStr) { $timeRange = $secondPeriodStart->format("h:i A") . " - " . $secondPeriodEnd->format("h:i A"); } else { $timeRange = "N/A"; } } else { $timeRange = $singlePeriodStart->format("h:i A") . " - " . $singlePeriodEnd->format("h:i A"); } echo "<tr> <td>" . htmlspecialchars($currentDate) . "</td> <td>" . htmlspecialchars($assignment['Course_Name']) . "</td> <td>" . htmlspecialchars($assignment['Time_Slot']) . "</td> <td>" . htmlspecialchars($timeRange) . "</td> <td>Regular</td> </tr>"; $foundAssignment = true; // If multiple assignments apply, additional rows could be output. } } if (!$foundAssignment) { echo "<tr> <td>" . htmlspecialchars($currentDate) . "</td> <td>No Class</td> <td>-</td> <td>-</td> <td>Free</td> </tr>"; } } //echo "</table>"; } */ ?>
Save
cmd:
run