/home/techb158/workloadmatch.com/workloadmatch.com/Manager
NameSizeModeActions
core/-0755rm
css/-0755rm
data/-0755rm
fonts/-0755rm
Inc/-0755rm
js/-0755rm
php/-0755rm
accesscontrol.php160390644editdlrm
AddClient.php39300644editdlrm
addcourse.php177360644editdlrm
addcoursesession.php205280644editdlrm
addcoursetime.php173050644editdlrm
addgroup - Copy.php212120644editdlrm
addgroup.php229990644editdlrm
addgroup1.php206670644editdlrm
addholiday.php180190644editdlrm
addmanager.php187650644editdlrm
addremediation.php178770644editdlrm
addretake.php219140644editdlrm
adduser.php300790644editdlrm
adduser1.php235270644editdlrm
Add_Course_Session.php65290644editdlrm
add_event.php19600644editdlrm
Add_Teacher_Unavailability.php17460644editdlrm
adminreports.php162190644editdlrm
AI_Generate_Schedule - Copy.php122170644editdlrm
AI_Generate_Schedule.php107310644editdlrm
ajax_course_group_Backup.php172700644editdlrm
ajax_course_group_Backup_1.php187420644editdlrm
ajax_fetch_schedule.php37600644editdlrm
ajax_get_group_slots.php8720644editdlrm
ajax_replace_saturday -Completed.php187390644editdlrm
ajax_replace_saturday - Copy (2).php187390644editdlrm
ajax_replace_saturday - Copy (3).php265540644editdlrm
ajax_replace_saturday - Copy (4).php266150644editdlrm
ajax_replace_saturday - Copy (5).php283740644editdlrm
ajax_replace_saturday - Copy.php134520644editdlrm
ajax_replace_saturday - Good.php172700644editdlrm
ajax_replace_saturday.php307790644editdlrm
ajax_swap_courses.php42790644editdlrm
assign_course_group-BackUp.php213310644editdlrm
assign_course_group - Copy (BackUp).php183150644editdlrm
assign_course_group - Copy.php213180644editdlrm
assign_course_group.php183150644editdlrm
assign_course_group1.php209620644editdlrm
Assign_Course_Report.php13750644editdlrm
assign_teacher_manual-1.php210950644editdlrm
assign_teacher_manual - Copy (2).php223280644editdlrm
assign_teacher_manual - Copy.php223880644editdlrm
assign_teacher_manual-Not work.php205850644editdlrm
assign_teacher_manual.php223280644editdlrm
assign_teacher_manual_force_conflicts.php223590644editdlrm
availableteacherreport.php137180644editdlrm
Available_Teacher_Report - Copy.php22360644editdlrm
Available_Teacher_Report.php76910644editdlrm
brokerreports.php163180644editdlrm
calendar - Copy (2).php168910644editdlrm
calendar - Copy.php231930644editdlrm
calendar.php306530644editdlrm
changestatus.php8650644editdlrm
Check_if_Teacher_Report.php15870644editdlrm
complete_schedule_report_by_teacher.php193120644editdlrm
courseflagtime.php34110644editdlrm
Create_Group_Schedule_Algorithm.php38280644editdlrm
Create_Schedule_Algorithm - Copy (2).php414120644editdlrm
Create_Schedule_Algorithm - Copy (3).php463520644editdlrm
Create_Schedule_Algorithm - Copy (4).php535690644editdlrm
Create_Schedule_Algorithm - Copy (5).php679560644editdlrm
Create_Schedule_Algorithm - Copy (6).php711340644editdlrm
Create_Schedule_Algorithm - Copy (7).php725290644editdlrm
Create_Schedule_Algorithm - Copy (8).php730840644editdlrm
Create_Schedule_Algorithm - Copy (9).php735770644editdlrm
Create_Schedule_Algorithm - Copy (10).php765050644editdlrm
Create_Schedule_Algorithm - Copy (11).php767640644editdlrm
Create_Schedule_Algorithm - Copy (12).php863240644editdlrm
Create_Schedule_Algorithm - Copy (13).php831330644editdlrm
Create_Schedule_Algorithm - Copy (14).php872740644editdlrm
Create_Schedule_Algorithm - Copy (get info only).php697470644editdlrm
Create_Schedule_Algorithm - Copy (with 2 course 2nd SPECIAL ).php823140644editdlrm
Create_Schedule_Algorithm - Copy.php405810644editdlrm
Create_Schedule_Algorithm.php882760644editdlrm
Create_Schedule_Algorithm_1.php414120644editdlrm
Create_Schedule_Algorithm_2.php765050644editdlrm
Create_Schedule_Algorithm_2_combined.php897640644editdlrm
Create_Schedule_Algorithm_2_combined_both_slots.php919320644editdlrm
Create_Schedule_Algorithm_2_fixed.php768290644editdlrm
Create_Schedule_Algorithm_3.php872740644editdlrm
Create_Schedule_Algorithm_4.php872740644editdlrm
dashboard-BackUp.php188060644editdlrm
dashboard.php225070644editdlrm
deleteschedulefromgroup.php168190644editdlrm
delete_course.php5800644editdlrm
delete_course_from_teacher.php49900644editdlrm
delete_course_from_teacher_backup.php30940644editdlrm
delete_event.php12120644editdlrm
delete_group.php18580644editdlrm
delete_holiday.php7150644editdlrm
delete_retake.php12760644editdlrm
delete_schedule_from_group-1.php18700644editdlrm
delete_schedule_from_group.php18500644editdlrm
delete_teacher_level.php7980644editdlrm
delete_teacher_unavailability.php13470644editdlrm
delete_timeslot.php5970644editdlrm
display_schedule-1.php188460644editdlrm
display_schedule.php188460644editdlrm
do_remove_saturday.php61700644editdlrm
edit_event.php16120644editdlrm
error_log740700644editdlrm
examschedulereport.php162670644editdlrm
Exam_Schedule_Report.php26770644editdlrm
export_absences.php12210644editdlrm
fetch_all_scheduled_courses.php63180644editdlrm
fetch_courses - BackUp.php97110644editdlrm
fetch_courses - Copy.php77190644editdlrm
fetch_courses.php91670644editdlrm
fetch_courses_for_program.php7880644editdlrm
fetch_courses_for_program_by_schedule - Copy.php22970644editdlrm
fetch_courses_for_program_by_schedule.php39350644editdlrm
fetch_courses_teacher_preference.php38520644editdlrm
fetch_course_for_added_group.php8970644editdlrm
fetch_course_hours.php6910644editdlrm
fetch_disabled_dates.php5180644editdlrm
fetch_events.php9750644editdlrm
fetch_exist_dates.php10990644editdlrm
fetch_groups_exist_in_schedule.php9560644editdlrm
fetch_groups_for_program.php8430644editdlrm
fetch_group_timeslot.php8470644editdlrm
fetch_reserve_courses.php74290644editdlrm
fetch_retake_courses.php9230644editdlrm
fetch_scheduled_courses.php21780644editdlrm
fetch_schedule_report_by_group.php54400644editdlrm
fetch_teachers_by_group.php44210644editdlrm
fetch_teachers_by_program.php18210644editdlrm
fetch_teachers_for_group.php31700644editdlrm
fetch_teacher_assignment.php247760644editdlrm
fetch_teacher_by_course.php38800644editdlrm
fetch_teacher_conflicts.php56820644editdlrm
fetch_teacher_conflicts_only.php76650644editdlrm
fetch_teacher_conflicts_only_force_conflicts.php71140644editdlrm
fetch_teacher_conflicts_showonly.php104470644editdlrm
fetch_teacher_load.php14820644editdlrm
fetch_teacher_prefrence_courses_accounting.php16060644editdlrm
find_replacement-1.php160750644editdlrm
find_replacement.php181610644editdlrm
followup.php161600644editdlrm
Generate Group Schedule.php169870644editdlrm
Generate Group Schedule 1.php181210644editdlrm
generateschedule.php157060644editdlrm
Generate_Schedule.php336200644editdlrm
generate_schedule_handler.php70950644editdlrm
Generate_Schedule_Script.php297310644editdlrm
getlang.php3260644editdlrm
getrefer.php43490644editdlrm
getstatus.php12600644editdlrm
get_groups_by_program.php6080644editdlrm
get_schedule_ai-1.php377550644editdlrm
get_schedule_ai - Copy.php364590644editdlrm
get_schedule_ai.php368550644editdlrm
get_schedule_report.php23930644editdlrm
group_schedule_form - Copy.php169940644editdlrm
group_schedule_form.php169940644editdlrm
main-header-inc.php11960644editdlrm
main-header.php166710644editdlrm
managecategory.php92330644editdlrm
managerreports.php250560644editdlrm
Preference_Accounting.php225030644editdlrm
profile.php206800644editdlrm
reference_list.php82070644editdlrm
remove_saturday_course.php195030644editdlrm
report_absence.php192870644editdlrm
report_absence_1.php61600644editdlrm
reserve_course.php189570644editdlrm
rewrite_ajax_replace_saturday.php128000644editdlrm
rewrite_Create_Schedule_Algorithm.php883180644editdlrm
rewrite_Create_Schedule_Algorithm_2.php889000644editdlrm
save_schedule.php29700644editdlrm
save_schedule_group_course.php253670644editdlrm
schedulereportbygroup.php177310644editdlrm
schedulereportbyteacher.php191110644editdlrm
scheduleteacherbygroupreport - Copy.php319860644editdlrm
scheduleteacherbygroupreport.php365560644editdlrm
scheduleteacherreport.php281500644editdlrm
schedule_report.php176640644editdlrm
Schedule_Report_by_Group.php36470644editdlrm
Schedule_Report_by_Teacher.php924330644editdlrm
selectuser.php11720644editdlrm
swapcourses.php194690644editdlrm
teacher_preference.php181820644editdlrm
teacher_preference_by_course.php192440644editdlrm
teacher_unavailability.php178350644editdlrm
test.php138950644editdlrm
test1.php218370644editdlrm
transfer_reference.php272880644editdlrm
unassigncoursereport.php160290644editdlrm
unassign_course.php190110644editdlrm
Unassign_Course_Report.php16970644editdlrm
unscheduledgroupreport.php156750644editdlrm
Unscheduled_Group_Report.php20070644editdlrm
updateclient.php147650644editdlrm
updatecourse.php216260644editdlrm
updatecoursesessionhours.php181970644editdlrm
updatecoursetime.php218310644editdlrm
updategroup - Copy.php245340644editdlrm
updategroup.php180010644editdlrm
updateholiday.php224930644editdlrm
updateteacherlevel.php245320644editdlrm
updateteacherunavailability.php141840644editdlrm
UpdateUser.php182140644editdlrm
Update_Course_Hours.php21350644editdlrm
Update_Follow_Up.php46180644editdlrm
update_reserve_course.php19340644editdlrm
update_teacher_level25080644editdlrm
update_teacher_level.php24300644editdlrm
useraccesslist.php128750644editdlrm
users.php90490644editdlrm
view_swap_log.php8940644editdlrm
Edit: /home/techb158/workloadmatch.com/workloadmatch.com/Manager/ajax_replace_saturday - Copy (5).php (28374B)
prepare("SELECT Time_Slot, Time_From, Time_To, class_days, Weekend_Class FROM Manager_Group_Name WHERE Group_ID = ?"); $stmt->bind_param("i", $groupID); $stmt->execute(); return $stmt->get_result()->fetch_assoc(); } // Fetch slot times function fetch_slot_times($mysqli, $slotLabels, $managerStart, $managerEnd) { $timeFrom = []; $timeTo = []; foreach ($slotLabels as $label) { $stmt = $mysqli->prepare("SELECT Time_From, Time_To FROM Time_Slot_Programs WHERE Time_Slot = ?"); $stmt->bind_param("s", $label); $stmt->execute(); $res = $stmt->get_result(); if ($row = $res->fetch_assoc()) { $timeFrom[] = $row['Time_From']; $timeTo[] = $row['Time_To']; } else { $timeFrom[] = $managerStart->format('H:i:s'); $timeTo[] = $managerEnd->format('H:i:s'); } } return [$timeFrom, $timeTo]; } // Fetch holidays function get_holidays($mysqli, $startDate) { $holidays = []; $res = $mysqli->query("SELECT Event_Start, Event_End FROM Events WHERE Calendar_Year = YEAR('$startDate')"); while ($row = $res->fetch_assoc()) { $start = new DateTime($row['Event_Start']); $end = new DateTime($row['Event_End']); while ($start <= $end) { $holidays[] = $start->format('Y-m-d'); $start->modify('+1 day'); } } return $holidays; } // Fetch retake dates function get_retake_dates($mysqli, $programID, $groupID) { $retakes = []; $stmt = $mysqli->prepare("SELECT Retake_Date FROM Retake_Records WHERE Program_ID = ? AND Group_ID = ?"); $stmt->bind_param("ii", $programID, $groupID); $stmt->execute(); $res = $stmt->get_result(); while ($row = $res->fetch_assoc()) { $retakes[] = $row['Retake_Date']; } return $retakes; } // Generate all valid class dates, excluding holidays, retakes, and July function generate_valid_dates($Start_Date, $End_Date, $classDays, $holidayDates, $retakeDates) { $validDates = []; $cur = new DateTime($Start_Date); $end = $End_Date ? new DateTime($End_Date) : null; while (!$end || $cur <= $end) { $day = $cur->format('l'); $dateStr = $cur->format('Y-m-d'); $month = (int)$cur->format('m'); // โœ… Check holidays and retakes FIRST if (in_array($dateStr, $holidayDates)) { $validDates[] = ['Date' => $dateStr, 'Type' => 'Holiday']; } elseif (in_array($dateStr, $retakeDates)) { $validDates[] = ['Date' => $dateStr, 'Type' => 'Retake']; } // โœ… Then check for valid class day (not July, must be in classDays) elseif ($month !== 7 && in_array($day, $classDays)) { $validDates[] = ['Date' => $dateStr, 'Type' => 'Class']; } $cur->modify('+1 day'); if ($end === null && count($validDates) > 500) break; } return $validDates; } // Calculate the average duration of one session function calculate_session_length($timeFrom, $timeTo) { $sessionLength = 0; foreach ($timeFrom as $i => $from) { $fromTime = new DateTime($from); $toTime = new DateTime($timeTo[$i]); $sessionLength += ($toTime->getTimestamp() - $fromTime->getTimestamp()) / 3600; } $slotCount = count($timeFrom); return $slotCount > 0 ? $sessionLength / $slotCount : 3; } // Calculate the number of sessions required for each course function calculate_course_sessions($mysqli, $Program_ID, $sessionLength) { $courseSessions = []; $res = $mysqli->query("SELECT Course_ID, Course_Time FROM Courses WHERE Program_ID = $Program_ID"); while ($row = $res->fetch_assoc()) { $courseID = $row['Course_ID']; $courseHours = $row['Course_Time']; $courseSessions[$courseID] = ceil($courseHours / $sessionLength); } return $courseSessions; } // --- MAIN LOGIC --- // /* if ($_SERVER['REQUEST_METHOD'] === 'POST') { $saturdayDate = $_POST['date'] ?? ''; $programID = intval($_POST['Program_ID'] ?? 0); $groupID = intval($_POST['Group_ID'] ?? 0); $startDate = $_POST['Start_Date'] ?? ''; $selectedCourses = json_decode(urldecode($_POST['Selected_Courses'] ?? '[]'), true); $priorityCourses = json_decode(urldecode($_POST['Priority_Course'] ?? '{}'), true); if (!$programID || !$groupID || !$saturdayDate || !$startDate || empty($selectedCourses)) { echo json_encode(['status' => 'error', 'message' => 'Missing required fields.']); exit; } $group = get_group_info($mysqli, $groupID); if (!$group) { echo json_encode(['status' => 'error', 'message' => 'Group not found.']); exit; } $classDays = array_map('trim', explode(',', $group['class_days'])); $slotLabels = array_map('trim', explode(',', $group['Time_Slot'])); $managerStart = new DateTime($group['Time_From']); $managerEnd = new DateTime($group['Time_To']); list($timeFrom, $timeTo) = fetch_slot_times($mysqli, $slotLabels, $managerStart, $managerEnd); $holidayDates = get_holidays($mysqli, $startDate); $retakeDates = get_retake_dates($mysqli, $programID, $groupID); // ๐Ÿงน Find the next valid weekday (limit to 20 days) $cur = new DateTime($saturdayDate); $cur->modify('+1 day'); $replacementDate = null; $attempts = 0; while ($attempts < 20) { $day = $cur->format('l'); $dateStr = $cur->format('Y-m-d'); if ($day !== 'Saturday' && in_array($day, $classDays) && !in_array($dateStr, $holidayDates) && !in_array($dateStr, $retakeDates)) { $replacementDate = $dateStr; break; } $cur->modify('+1 day'); $attempts++; } if (!$replacementDate) { echo json_encode(['status' => 'error', 'message' => 'No available weekday found within 20 days.']); exit; } // ๐ŸŽฏ Sort courses by priority usort($selectedCourses, function($a, $b) use ($priorityCourses) { return ($priorityCourses[$a] ?? PHP_INT_MAX) <=> ($priorityCourses[$b] ?? PHP_INT_MAX); }); $courseID = $selectedCourses[0]; // Fetch course name $res = $mysqli->query("SELECT Course_Name FROM Courses WHERE Course_ID = $courseID"); $courseData = $res->fetch_assoc(); $courseName = $courseData ? $courseData['Course_Name'] : "Course ID $courseID"; // ๐ŸŽจ Prepare new HTML row $dayName = (new DateTime($replacementDate))->format('l'); $slotName = format_time_slot_label($slotLabels[0] ?? 'Morning', $dayName); $timeRange = format_time_slot_range($slotLabels[0] ?? 'Morning', $timeFrom[0] ?? '08:30', $timeTo[0] ?? '12:30', $dayName); $newRowHtml = " ($dayName) $replacementDate $slotName $timeRange $courseName - "; echo json_encode([ 'status' => 'success', 'original' => $saturdayDate, 'replacement' => $replacementDate, 'newRowHtml' => $newRowHtml ]); exit; } */ // ------------------- Functions ------------------- function getNextCourseForSlot($remainingSessions, $courseList, $usedToday) { $available = array_filter($courseList, function($courseID) use ($remainingSessions) { return ($remainingSessions[$courseID] ?? 0) > 0; }); $unusedToday = array_filter($available, fn($courseID) => !in_array($courseID, $usedToday)); if (!empty($unusedToday)) { return reset($unusedToday); } // Allow reuse only if it's the last course left if (count($available) === 1) { return reset($available); } return null; } // Handle AJAX request // Handle AJAX request // MAIN START if ($_SERVER['REQUEST_METHOD'] === 'POST') { session_start(); $Program_ID = intval($_POST['Program_ID']); $Group_ID = intval($_POST['Group_ID']); $Start_Date = $_POST['Start_Date']; $Removed_Date = $_POST['date']; // ๐Ÿงน Reset deleted Saturdays when changing group $lastGroup = $_SESSION['last_group_id'] ?? null; if ($Group_ID !== $lastGroup) { unset($_SESSION['deletedSaturdays']); } $_SESSION['last_group_id'] = $Group_ID; $selectedCourses = json_decode($_POST['Selected_Courses'], true) ?? []; $priorityCourses = json_decode($_POST['Priority_Course'], true) ?? []; $group = get_group_info($mysqli, $Group_ID); if (!$group) { echo json_encode(['status' => 'error', 'message' => 'Group not found']); exit; } $classDays = explode(',', $group['class_days']); //$slotLabels = explode(',', $group['Time_Slot']); $managerStart = new DateTime(trim($group['Time_From'])); $managerEnd = new DateTime(trim($group['Time_To'])); //list($timeFrom, $timeTo) = fetch_slot_times($mysqli, $slotLabels, $managerStart, $managerEnd); $stmt = $mysqli->prepare("SELECT Group_Slot_ID, Time_Slot, Time_From, Time_To FROM Group_Slot_Mapping WHERE Group_ID = ?"); $stmt->bind_param("i", $Group_ID); $stmt->execute(); $res = $stmt->get_result(); //$group_slot_id = []; // <โ€“ Add this before the while loop $slotLabels = $timeFrom = $timeTo = []; //while ($row = $res->fetch_assoc()) { // $slotLabels[] = $row['Time_Slot']; // $timeFrom[] = $row['Time_From']; // $timeTo[] = $row['Time_To']; // //$group_slot_id[] = $row['Group_Slot_ID']; //} $slotData = []; // holds each slot's full data while ($row = $res->fetch_assoc()) { $slotLabels[] = $row['Time_Slot']; $timeFrom[] = $row['Time_From']; $timeTo[] = $row['Time_To']; $slotData[] = [ 'Group_Slot_ID' => $row['Group_Slot_ID'], 'Time_Slot' => $row['Time_Slot'], 'Time_From' => $row['Time_From'], 'Time_To' => $row['Time_To'] ]; } $sessionLength = calculate_session_length($timeFrom, $timeTo); $holidayDates = get_holidays($mysqli, $Start_Date); $retakeDates = get_retake_dates($mysqli, $Program_ID, $Group_ID); // Generate valid dates $validDates = generate_valid_dates($Start_Date, null, $classDays, $holidayDates, $retakeDates); /////////////// Remove the deleted Saturday /////////////$validDates = array_filter($validDates, function($d) use ($Removed_Date) { ///////////// return $d['Date'] !== $Removed_Date; /////////////}); /////////////$validDates = array_values($validDates); // Step 5: Remove and store the deleted Saturday(s) $deletedSaturdays = $_SESSION['deletedSaturdays'] ?? []; // keep history in session $deletedSaturdays[] = $Removed_Date; // add this new one $_SESSION['deletedSaturdays'] = array_unique($deletedSaturdays); // avoid duplicates // Remove all deleted Saturdays from validDates $validDates = array_filter($validDates, function($d) use ($deletedSaturdays) { return !in_array($d['Date'], $deletedSaturdays); }); $validDates = array_values($validDates); // reindex ///////////////////////////////////////////////////////// // Reorder courses by priority if (!empty($priorityCourses)) { usort($selectedCourses, function($a, $b) use ($priorityCourses) { return ($priorityCourses[$a] ?? PHP_INT_MAX) <=> ($priorityCourses[$b] ?? PHP_INT_MAX); }); } $courseNames = []; $res = $mysqli->query("SELECT Course_ID, Course_Name FROM Courses WHERE Program_ID = $Program_ID"); while ($row = $res->fetch_assoc()) { $courseNames[$row['Course_ID']] = $row['Course_Name']; } $courseSessions = calculate_course_sessions($mysqli, $Program_ID, $sessionLength); $remainingSessions = []; foreach ($selectedCourses as $courseID) { $remainingSessions[$courseID] = $courseSessions[$courseID] ?? 0; } //// Build schedule //$html = "
"; //$html .= "
"; $html .= ""; ////$html = "
"; $html .= ""; //$html = '
DateSlotTimeCourseAction
'; //$html .= ''; $currentCourse = reset($selectedCourses); $slotCount = count($slotLabels); $slotIndex = 0; foreach ($validDates as $entry) { $date = $entry['Date']; $dayName = (new DateTime($date))->format('l'); $type = $entry['Type']; if ($type === 'Holiday') { $html .= ""; continue; } if ($type === 'Retake') { $html .= ""; continue; } if (!$currentCourse) break; $slotLabel = format_time_slot_label($slotLabels[$slotIndex % $slotCount], $dayName); $timeRange = format_time_slot_range($slotLabels[$slotIndex % $slotCount], $timeFrom[$slotIndex % $slotCount], $timeTo[$slotIndex % $slotCount], $dayName); $examTag = ($remainingSessions[$currentCourse] == 1) ? ' (Exam Day)' : ''; ////////////////$action = ($dayName === 'Saturday' && !$examTag) ? "" : "-"; $deletedSaturdays = $_SESSION['deletedSaturdays'] ?? []; $normalizedDate = (new DateTime($date))->format('Y-m-d'); $deletedSaturdays = $_SESSION['deletedSaturdays'] ?? []; if ($dayName === 'Saturday') { if (in_array($normalizedDate, $deletedSaturdays)) { $action = "๐Ÿ—‘๏ธ Removed"; } else { $action = ""; } } else { $action = "-"; } $slotDataCount = count($slotData); if ($slotDataCount === 0) { die("โŒ Error: No slot data found for Group_ID = $Group_ID"); } //$html .= ""; $currentSlot = $slotData[$slotIndex % count($slotData)]; $groupSlotID = $currentSlot['Group_Slot_ID']; $slotLabel = $currentSlot['Time_Slot']; $from = $currentSlot['Time_From']; $to = $currentSlot['Time_To']; $html .= ""; $html .= ""; $html .= ""; $remainingSessions[$currentCourse]--; if ($remainingSessions[$currentCourse] <= 0) { $currentCourse = next($selectedCourses); } $slotIndex++; } //$html .= '
DateSlotTimeCourseAction
($dayName) $date - - HOLIDAY -
($dayName) $date - - RETAKE -
($dayName) $date$slotLabel$timeRange{$courseNames[$currentCourse]}$examTag$action
'; $html .= ""; //$html = "
"; //$html .= ""; $html .= ""; //$html .= "
DateSlotTimeCourseAction
DateSlotTimeCourseAction
"; //$html .= "
// //
"; $html .= "
"; echo json_encode([ 'status' => 'success', 'html' => $html ]); exit; } function generateSchedule($mysqli, $Program_ID, $Group_ID, $Start_Date, $Removed_Date, $selectedCourses, $priorityCourses) { // Get group info $group = get_group_info($mysqli, $Group_ID); if (!$group) { return '
Error: Group not found.
'; } $classDays = explode(',', $group['class_days']); $slotLabels = explode(',', $group['Time_Slot']); $managerStart = new DateTime(trim($group['Time_From'])); $managerEnd = new DateTime(trim($group['Time_To'])); list($timeFrom, $timeTo) = fetch_slot_times($mysqli, $slotLabels, $managerStart, $managerEnd); $sessionLength = calculate_session_length($timeFrom, $timeTo); $courseSessions = calculate_course_sessions($mysqli, $Program_ID, $sessionLength); $holidayDates = get_holidays($mysqli, $Start_Date); $retakeDates = get_retake_dates($mysqli, $Program_ID, $Group_ID); $validDates = generate_valid_dates($Start_Date, null, $classDays, $holidayDates, $retakeDates); $validDates = array_filter($validDates, function($date) use ($Removed_Date) { return $date !== $Removed_Date; }); $validDates = array_values($validDates); if (!empty($priorityCourses)) { usort($selectedCourses, function ($a, $b) use ($priorityCourses) { return ($priorityCourses[$a] ?? PHP_INT_MAX) <=> ($priorityCourses[$b] ?? PHP_INT_MAX); }); } $remainingSessions = []; foreach ($selectedCourses as $courseID) { $remainingSessions[$courseID] = $courseSessions[$courseID] ?? 0; } $courseNames = []; $res = $mysqli->query("SELECT Course_ID, Course_Name FROM Courses"); while ($row = $res->fetch_assoc()) { $courseNames[$row['Course_ID']] = $row['Course_Name']; } $currentCourses = [null, null]; $htmlRows = []; $examTag = ' (Exam Day)'; //$courseQueue = $selectedCourses; // copy for rotation $ajaxScheduleData = []; foreach ($validDates as $entry) { $date = $entry['Date']; $dayName = (new DateTime($date))->format('l'); $type = $entry['Type']; if ($type === 'Holiday' || $type === 'Retake') { $htmlRows[] = [ 'Date' => $date, 'Day' => $dayName, 'Slot' => '', 'Time' => '', 'Course_Name' => strtoupper($type), 'IsExam' => false, 'Action' => '-' ]; continue; } $usedToday = []; foreach (array_keys($slotLabels) as $slotIndex) { $from = $timeFrom[$slotIndex] ?? null; $to = $timeTo[$slotIndex] ?? null; $slotLabel = $slotLabels[$slotIndex] ?? 'Unknown'; if (!$from || !$to) continue; $courseID = getNextCourseForSlot($remainingSessions, $selectedCourses, $usedToday); if (!$courseID) continue; $isExam = ($remainingSessions[$courseID] === 1); $usedToday[] = $courseID; $remainingSessions[$courseID]--; $action = ($dayName === 'Saturday' && !in_array($date, $deletedSaturdays)) ? "" : ($dayName === 'Saturday' ? '๐Ÿ—‘๏ธ Removed' : '-'); $htmlRows[] = [ 'Date' => $date, 'Day' => $dayName, 'Slot' => $slotLabel, 'Time' => format_time_slot_range($slotLabel, $from, $to, $dayName), 'Course_Name' => $courseNames[$courseID] ?? "Course $courseID", 'IsExam' => $isExam, 'Action' => $action ]; $ajaxScheduleData[] = [ 'program_id' => $Program_ID, 'course_id' => $courseID, 'course_name' => $courseNames[$courseID] ?? '', 'group_id' => $Group_ID, 'group_slot_id' => $slotIndex, 'reserve_course' => 0, 'time_slot' => $slotLabel, 'start_date' => $date, // or $normalizedDate if you format earlier 'end_date' => $date, 'start_time' => $from, 'end_time' => $to ]; if (array_sum($remainingSessions) <= 0) break 2; // Stop if everything is scheduled } } $html = "
"; $html .= "
"; $html .= ""; //$html = "
"; $html .= ""; foreach ($htmlRows as $row) { // Ensure all required keys exist $row['Slot'] = $row['Slot'] ?? '-'; $row['Time'] = $row['Time'] ?? '-'; $row['Course_Name'] = $row['Course_Name'] ?? '-'; $row['Action'] = $row['Action'] ?? '-'; $row['IsExam'] = $row['IsExam'] ?? false; $examLabel = $row['IsExam'] ? ' (Exam Day)' : ''; $formattedDate = "({$row['Day']}) {$row['Date']}"; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; } //foreach ($htmlRows as $row) { // $examLabel = $row['IsExam'] ? ' (Exam Day)' : ''; // $formattedDate = "({$row['Day']}) {$row['Date']}"; // // $html .= ""; // $html .= ""; // $html .= ""; // $html .= ""; // $html .= ""; // $html .= ""; // $html .= ""; //} //$html .= "
DateSlotTimeCourseAction
{$formattedDate}{$row['Slot']}{$row['Time']}{$row['Course_Name']}{$examLabel}{$row['Action']}
{$formattedDate}{$row['Slot']}{$row['Time']}{$row['Course_Name']}{$examLabel}{$row['Action']}
"; // Footer $html .= "DateSlotTimeCourseAction"; $html .= "
"; //$html .= "
// //
"; //$html .= ""; return $html; } // โŒ Fallback if not POST http_response_code(405); echo json_encode(['status' => 'error', 'message' => 'Invalid request method.']); exit; /* function generateSchedule($mysqli, $Program_ID, $Group_ID, $Start_Date, $Removed_Date, $selectedCourses, $priorityCourses) { // Get group info $group = get_group_info($mysqli, $Group_ID); if (!$group) { return '
Error: Group not found.
'; } $classDays = explode(',', $group['class_days']); $slotLabels = explode(',', $group['Time_Slot']); $managerStart = new DateTime(trim($group['Time_From'])); $managerEnd = new DateTime(trim($group['Time_To'])); list($timeFrom, $timeTo) = fetch_slot_times($mysqli, $slotLabels, $managerStart, $managerEnd); $sessionLength = calculate_session_length($timeFrom, $timeTo); // Courses & sessions $courseSessions = calculate_course_sessions($mysqli, $Program_ID, $sessionLength); // Load holidays & retakes $holidayDates = get_holidays($mysqli, $Start_Date); $retakeDates = get_retake_dates($mysqli, $Program_ID, $Group_ID); // Generate valid dates $validDates = generate_valid_dates($Start_Date, null, $classDays, $holidayDates, $retakeDates); // Remove the Saturday we want to delete $validDates = array_filter($validDates, function($date) use ($Removed_Date) { return $date !== $Removed_Date; }); $validDates = array_values($validDates); // Re-index after filtering // Sort courses by priority if (!empty($priorityCourses)) { usort($selectedCourses, function ($a, $b) use ($priorityCourses) { $priorityA = $priorityCourses[$a] ?? PHP_INT_MAX; $priorityB = $priorityCourses[$b] ?? PHP_INT_MAX; return $priorityA <=> $priorityB; }); } // Initialize scheduling $schedule = []; $remainingSessions = []; foreach ($selectedCourses as $courseID) { $remainingSessions[$courseID] = $courseSessions[$courseID] ?? 0; } // Course Names $courseNames = []; $res = $mysqli->query("SELECT Course_ID, Course_Name FROM Courses"); while ($row = $res->fetch_assoc()) { $courseNames[$row['Course_ID']] = $row['Course_Name']; } // Main loop: assign courses $courseQueue = $selectedCourses; $currentCourses = [0 => null, 1 => null]; // Morning and Evening foreach ([0, 1] as $slotIndex) { foreach ($courseQueue as $courseID) { if ($remainingSessions[$courseID] > 0) { $currentCourses[$slotIndex] = $courseID; break; } } } $examTag = ' (Exam Day)'; // Build schedule $examDates = []; foreach ($validDates as $date) { $weekday = (new DateTime($date))->format('l'); foreach ([0, 1] as $slotIndex) { $from = $timeFrom[$slotIndex] ?? null; $to = $timeTo[$slotIndex] ?? null; if (!$from || !$to || !$currentCourses[$slotIndex]) { continue; } $courseID = $currentCourses[$slotIndex]; $isExam = false; if (isset($remainingSessions[$courseID]) && $remainingSessions[$courseID] == 1) { $isExam = true; // last session becomes exam } $schedule[] = [ 'Date' => $date, 'Day' => $weekday, 'Slot' => $slotLabels[$slotIndex] ?? 'Unknown Slot', 'Time' => format_time_slot_range($slotLabels[$slotIndex], $from, $to, $weekday), 'Course_Name' => $courseNames[$courseID] ?? 'Unknown', 'IsExam' => $isExam ]; // Reduce sessions $remainingSessions[$courseID]--; if ($remainingSessions[$courseID] <= 0) { $currentCourses[$slotIndex] = null; while (!empty($courseQueue)) { $nextCourseID = array_shift($courseQueue); if ($remainingSessions[$nextCourseID] > 0) { $currentCourses[$slotIndex] = $nextCourseID; break; } } } } if (!$currentCourses[0] && !$currentCourses[1]) { break; } } // Render HTML $html = "
"; $html .= ""; $html .= ""; foreach ($schedule as $row) { $formattedDate = "(" . $row['Day'] . ") " . $row['Date']; $examLabel = $row['IsExam'] ? $examTag : ''; $action = (stripos($row['Day'], 'Saturday') !== false) ? "๐Ÿงน Replace" : "-"; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; } $html .= "
DateSlotTimeCourseAction
{$formattedDate}{$row['Slot']}{$row['Time']}{$row['Course_Name']}{$examLabel}{$action}
"; return $html; } */ ?>