/
home
/
techb158
/
workloadmatch.com
/
workloadmatch.com
/
Manager
/
/home/techb158/workloadmatch.com/workloadmatch.com/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/Manager/test1.php
(21837B)
<?php include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); //if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['Program_ID'], $_POST['Group_ID'])) { // Get Program ID and Group ID from the submitted form $Program_ID = 1; $Group_ID = 0; $Reserve_Course = 0; // For demonstration, using fixed Program_ID and Group_ID (in your actual system, these come from the submitted form) //$Program_ID = 1; //$Group_ID = 13; // ----------------------------- // STEP 1: Get all unassigned schedules for this Program // ----------------------------- if($Group_ID != 0) { $scheduleQuery = "SELECT * FROM Course_Group_Schedule WHERE Assigned = 0 AND Program_ID = ? AND Group_ID = ? AND Reserve_Course = ? ORDER BY Time_Slot"; $stmt = $mysqli->prepare($scheduleQuery); $stmt->bind_param("iii", $Program_ID, $Group_ID, $Reserve_Course); }else{ $scheduleQuery = "SELECT * FROM Course_Group_Schedule WHERE Assigned = 0 AND Program_ID = ? AND Reserve_Course = ? ORDER BY Time_Slot"; $stmt = $mysqli->prepare($scheduleQuery); $stmt->bind_param("ii", $Program_ID, $Reserve_Course); } if (!$stmt) { die("Error preparing schedule query: " . $mysqli->error); } if (!$stmt->execute()) { die("Error executing schedule query: " . $stmt->error); } $schedulesResult = $stmt->get_result(); $schedules = []; while ($row = $schedulesResult->fetch_assoc()) { $schedules[] = $row; } $stmt->close(); // ----------------------------- // STEP 2: Get teachers for this Program, combining Teacher_Profile and Top_Teacher_List. // Ordering: Premium (top) teachers first, then teachers with Seniority_ID = 1 (qualified), // then teachers with Seniority_ID = 2 (unqualified). // ----------------------------- //$teacherQuery = " // SELECT // tp.Teacher_ID, // tp.First_Name, // tp.Last_Name, // tp.Seniority_ID, // tp.Time_Slot AS Availability, // tp.Load_Hours, // ttl.Top_Teacher_ID, // ttl.Teacher_Level // FROM Teacher_Profile tp // LEFT JOIN Top_Teacher_List ttl // ON tp.Teacher_ID = ttl.Teacher_ID // AND ttl.Program_ID = ? // WHERE 1 // ORDER BY // CASE // WHEN ttl.Top_Teacher_ID IS NOT NULL THEN 1 // WHEN tp.Seniority_ID = 1 THEN 2 // WHEN tp.Seniority_ID = 2 THEN 3 // ELSE 4 // END, // tp.First_Name ASC, // tp.Last_Name ASC //"; //$stmt = $mysqli->prepare($teacherQuery); //if (!$stmt) { // die("Error preparing teacher query: " . $mysqli->error); //} //$stmt->bind_param("i", $Program_ID); //if (!$stmt->execute()) { // die("Error executing teacher query: " . $stmt->error); //} //$result = $stmt->get_result(); //$teachers = []; //while ($row = $result->fetch_assoc()) { // $teachers[] = $row; //} //$stmt->close(); //// Debug: Optional print teacher list //foreach ($teachers as $teacher) { // $isPremium = !empty($teacher['Top_Teacher_ID']) ? "Premium (Level: " . $teacher['Teacher_Level'] . ")" : ""; // echo $teacher['First_Name'] . " " . $teacher['Last_Name'] . " - Seniority: " . $teacher['Seniority_ID'] . " " . $isPremium . " - Load Hours: " . $teacher['Load_Hours'] . "<br>"; //} // STEP 2: Get teachers for this Program by combining Teacher_Profile and Top_Teacher_List. // (No filtering on Teacher_Profile by Program_ID because it's not in that table.) $teacherQuery = " SELECT tp.Teacher_ID, tp.First_Name, tp.Last_Name, tp.Seniority_ID, tp.Time_Slot AS Availability, tp.Load_Hours, ttl.Top_Teacher_ID, ttl.Teacher_Level FROM Teacher_Profile tp LEFT JOIN Top_Teacher_List ttl ON tp.Teacher_ID = ttl.Teacher_ID AND ttl.Program_ID = ? WHERE 1 ORDER BY tp.First_Name ASC, tp.Last_Name ASC "; $stmt = $mysqli->prepare($teacherQuery); if (!$stmt) { die("Error preparing teacher query: " . $mysqli->error); } $stmt->bind_param("i", $Program_ID); $stmt->execute(); $result = $stmt->get_result(); $allTeachers = []; while ($row = $result->fetch_assoc()) { $allTeachers[] = $row; } $stmt->close(); // Initialize the round-robin pointer $teacherCount = count($teachers); $teacherIndex = 0; // ----------------------------- // STEP 3: Loop through each unassigned schedule and try to assign a teacher // ----------------------------- // Separate teachers into groups $premiumTeachers = []; $qualifiedTeachers = []; $unqualifiedTeachers = []; foreach ($allTeachers as $teacher) { if (!empty($teacher['Top_Teacher_ID'])) { $premiumTeachers[] = $teacher; } elseif ($teacher['Seniority_ID'] == 1) { $qualifiedTeachers[] = $teacher; } elseif ($teacher['Seniority_ID'] == 2) { $unqualifiedTeachers[] = $teacher; } } // Initialize round-robin pointers for each group $ptrPremium = 0; $ptrQualified = 0; $ptrUnqualified = 0; $cntPremium = count($premiumTeachers); $cntQualified = count($qualifiedTeachers); $cntUnqualified = count($unqualifiedTeachers); // (Optional) Debug output: print ordered teacher groups echo "<h3>Premium Teachers:</h3>"; foreach ($premiumTeachers as $t) { echo $t['First_Name']." ".$t['Last_Name']." (Level: ".$t['Teacher_Level'].")<br>"; } echo "<h3>Qualified Teachers:</h3>"; foreach ($qualifiedTeachers as $t) { echo $t['First_Name']." ".$t['Last_Name']." (Seniority: ".$t['Seniority_ID'].")<br>"; } echo "<h3>Unqualified Teachers:</h3>"; foreach ($unqualifiedTeachers as $t) { echo $t['First_Name']." ".$t['Last_Name']." (Seniority: ".$t['Seniority_ID'].")<br>"; } echo "<hr>"; // Helper inline: For each teacher, perform assignment checks. // (Availability, conflict, load hours, preferences) foreach ($schedules as $schedule) { $assigned = false; // Function to check if teacher can be assigned // (We inline the checks here.) $canAssign = function($teacher, $schedule) use ($mysqli, $Program_ID) { // Check availability: Teacher's Availability field is a comma-separated list. $availableSlots = array_map('trim', explode(',', $teacher['Availability'])); if (!in_array($schedule['Time_Slot'], $availableSlots)) { return false; } // Check conflicts: any overlapping assignment in the same time slot. $conflictQuery = "SELECT COUNT(*) AS cnt FROM Teacher_Course_Assignments WHERE Teacher_ID = ? AND Time_Slot = ? AND (? <= End_Date AND ? >= Start_Date)"; $conflictStmt = $mysqli->prepare($conflictQuery); if (!$conflictStmt) { echo "Error preparing conflict query: " . $mysqli->error . "<br>"; return false; } $conflictStmt->bind_param("isss", $teacher['Teacher_ID'], $schedule['Time_Slot'], $schedule['Start_Date'], $schedule['End_Date']); if (!$conflictStmt->execute()) { echo "Error executing conflict query: " . $conflictStmt->error . "<br>"; $conflictStmt->close(); return false; } $conflictResult = $conflictStmt->get_result(); $conflictRow = $conflictResult->fetch_assoc(); $conflictCount = $conflictRow['cnt']; $conflictStmt->close(); if ($conflictCount > 0) { return false; } // Check load hours capacity: // 1. Get teacher's current assigned hours. $currentLoadQuery = "SELECT IFNULL(SUM(c.Course_Time), 0) AS total_hours FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID WHERE tca.Teacher_ID = ?"; $currentLoadStmt = $mysqli->prepare($currentLoadQuery); if (!$currentLoadStmt) { echo "Error preparing current load query: " . $mysqli->error . "<br>"; return false; } $currentLoadStmt->bind_param("i", $teacher['Teacher_ID']); $currentLoadStmt->execute(); $currentLoadResult = $currentLoadStmt->get_result(); $currentLoadRow = $currentLoadResult->fetch_assoc(); $currentLoad = $currentLoadRow['total_hours']; $currentLoadStmt->close(); // 2. Get new course's hours. $courseQuery = "SELECT Course_Time FROM Courses WHERE Course_ID = ?"; $courseStmt = $mysqli->prepare($courseQuery); if (!$courseStmt) { echo "Error preparing course query: " . $mysqli->error . "<br>"; return false; } $courseStmt->bind_param("i", $schedule['Course_ID']); $courseStmt->execute(); $courseResult = $courseStmt->get_result(); $courseData = $courseResult->fetch_assoc(); $newCourseTime = $courseData['Course_Time']; $courseStmt->close(); if (($currentLoad + $newCourseTime) > $teacher['Load_Hours']) { return false; } // Check teacher's course preferences. $prefQuery = "SELECT * FROM Teacher_Course_Preferences WHERE Teacher_ID = ? AND Course_ID = ? AND Priority IN (1,2) ORDER BY Priority ASC"; $prefStmt = $mysqli->prepare($prefQuery); if (!$prefStmt) { echo "Error preparing preference query: " . $mysqli->error . "<br>"; return false; } $prefStmt->bind_param("ii", $teacher['Teacher_ID'], $schedule['Course_ID']); $prefStmt->execute(); $prefResult = $prefStmt->get_result(); $preferences = []; while ($prefRow = $prefResult->fetch_assoc()) { $preferences[] = $prefRow; } $prefStmt->close(); if (empty($preferences)) { return false; } return true; }; // end of anonymous function // Try to assign from premium teachers first if ($cntPremium > 0) { for ($i = 0; $i < $cntPremium; $i++) { $currentIndex = ($ptrPremium + $i) % $cntPremium; $teacher = $premiumTeachers[$currentIndex]; if ($canAssign($teacher, $schedule)) { // Assign this teacher // Insert assignment $insertQuery = "INSERT INTO Teacher_Course_Assignments (Teacher_ID, Course_ID, Group_ID, Program_ID, Schedule_ID, Time_Slot, Start_Date, End_Date, Assigned_At) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; $insertStmt = $mysqli->prepare($insertQuery); if (!$insertStmt) { echo "Error preparing insert query: " . $mysqli->error . "<br>"; continue; } $assignedAt = date('Y-m-d H:i:s'); $insertStmt->bind_param("iiiiissss", $teacher['Teacher_ID'], $schedule['Course_ID'], $schedule['Group_ID'], $schedule['Program_ID'], $schedule['Schedule_ID'], $schedule['Time_Slot'], $schedule['Start_Date'], $schedule['End_Date'], $assignedAt ); if (!$insertStmt->execute()) { echo "Error executing insert query: " . $insertStmt->error . "<br>"; $insertStmt->close(); continue; } $insertStmt->close(); // Mark schedule as assigned. $updateQuery = "UPDATE Course_Group_Schedule SET Assigned = 1 WHERE Schedule_ID = ?"; $updateStmt = $mysqli->prepare($updateQuery); if (!$updateStmt) { echo "Error preparing update query: " . $mysqli->error . "<br>"; continue; } $updateStmt->bind_param("i", $schedule['Schedule_ID']); if (!$updateStmt->execute()) { echo "Error executing update query: " . $updateStmt->error . "<br>"; $updateStmt->close(); continue; } $updateStmt->close(); // Update pointer for premium group. $ptrPremium = ($currentIndex + 1) % $cntPremium; $assigned = true; break; } } } // If not assigned by premium, try qualified teachers. if (!$assigned && $cntQualified > 0) { for ($i = 0; $i < $cntQualified; $i++) { $currentIndex = ($ptrQualified + $i) % $cntQualified; $teacher = $qualifiedTeachers[$currentIndex]; if ($canAssign($teacher, $schedule)) { $insertQuery = "INSERT INTO Teacher_Course_Assignments (Teacher_ID, Course_ID, Group_ID, Program_ID, Schedule_ID, Time_Slot, Start_Date, End_Date, Assigned_At) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; $insertStmt = $mysqli->prepare($insertQuery); if (!$insertStmt) { echo "Error preparing insert query: " . $mysqli->error . "<br>"; continue; } $assignedAt = date('Y-m-d H:i:s'); $insertStmt->bind_param("iiiiissss", $teacher['Teacher_ID'], $schedule['Course_ID'], $schedule['Group_ID'], $schedule['Program_ID'], $schedule['Schedule_ID'], $schedule['Time_Slot'], $schedule['Start_Date'], $schedule['End_Date'], $assignedAt ); if (!$insertStmt->execute()) { echo "Error executing insert query: " . $insertStmt->error . "<br>"; $insertStmt->close(); continue; } $insertStmt->close(); $updateQuery = "UPDATE Course_Group_Schedule SET Assigned = 1 WHERE Schedule_ID = ?"; $updateStmt = $mysqli->prepare($updateQuery); if (!$updateStmt) { echo "Error preparing update query: " . $mysqli->error . "<br>"; continue; } $updateStmt->bind_param("i", $schedule['Schedule_ID']); if (!$updateStmt->execute()) { echo "Error executing update query: " . $updateStmt->error . "<br>"; $updateStmt->close(); continue; } $updateStmt->close(); $ptrQualified = ($currentIndex + 1) % $cntQualified; $assigned = true; break; } } } // If still not assigned, try unqualified teachers. if (!$assigned && $cntUnqualified > 0) { for ($i = 0; $i < $cntUnqualified; $i++) { $currentIndex = ($ptrUnqualified + $i) % $cntUnqualified; $teacher = $unqualifiedTeachers[$currentIndex]; if ($canAssign($teacher, $schedule)) { $insertQuery = "INSERT INTO Teacher_Course_Assignments (Teacher_ID, Course_ID, Group_ID, Program_ID, Schedule_ID, Time_Slot, Start_Date, End_Date, Assigned_At) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; $insertStmt = $mysqli->prepare($insertQuery); if (!$insertStmt) { echo "Error preparing insert query: " . $mysqli->error . "<br>"; continue; } $assignedAt = date('Y-m-d H:i:s'); $insertStmt->bind_param("iiiiissss", $teacher['Teacher_ID'], $schedule['Course_ID'], $schedule['Group_ID'], $schedule['Program_ID'], $schedule['Schedule_ID'], $schedule['Time_Slot'], $schedule['Start_Date'], $schedule['End_Date'], $assignedAt ); if (!$insertStmt->execute()) { echo "Error executing insert query: " . $insertStmt->error . "<br>"; $insertStmt->close(); continue; } $insertStmt->close(); $updateQuery = "UPDATE Course_Group_Schedule SET Assigned = 1 WHERE Schedule_ID = ?"; $updateStmt = $mysqli->prepare($updateQuery); if (!$updateStmt) { echo "Error preparing update query: " . $mysqli->error . "<br>"; continue; } $updateStmt->bind_param("i", $schedule['Schedule_ID']); if (!$updateStmt->execute()) { echo "Error executing update query: " . $updateStmt->error . "<br>"; $updateStmt->close(); continue; } $updateStmt->close(); $ptrUnqualified = ($currentIndex + 1) % $cntUnqualified; $assigned = true; break; } } } } // Build the query to retrieve teacher assignments along with related details $query = " SELECT tca.Assignment_ID, tca.Teacher_ID, tca.Course_ID, tca.Group_ID, tca.Program_ID, tca.Schedule_ID, tca.Time_Slot, tca.Start_Date, tca.End_Date, tca.Assigned_At, tp.First_Name, tp.Last_Name, p.Program_Name, c.Course_Name, g.Group_Name FROM Teacher_Course_Assignments tca JOIN Teacher_Profile tp ON tca.Teacher_ID = tp.Teacher_ID JOIN Programs p ON tca.Program_ID = p.Program_ID JOIN Courses c ON tca.Course_ID = c.Course_ID JOIN Manager_Group_Name g ON tca.Group_ID = g.Group_ID ORDER BY tca.Assigned_At DESC "; // Execute the query $result = $mysqli->query($query); if (!$result) { die("Error executing query: " . $mysqli->error); } ?> <!-- Display the results in a table --> <table id="example1" class="table table-bordered table-striped"> <thead> <tr> <th>Assignment ID</th> <th>Teacher</th> <th>Course</th> <th>Group</th> <th>Program</th> <th>Time Slot</th> <th>Start Date</th> <th>End Date</th> <th>Assigned At</th> </tr> </thead> <tbody> <?php while ($row = $result->fetch_assoc()) { ?> <tr id="row_<?php echo $row['Assignment_ID']; ?>"> <td><?php echo $row['Assignment_ID']; ?></td> <td><?php echo $row['First_Name'] . ' ' . $row['Last_Name']; ?></td> <td><?php echo $row['Course_Name']; ?></td> <td><?php echo $row['Group_Name']; ?></td> <td><?php echo $row['Program_Name']; ?></td> <td><?php echo $row['Time_Slot']; ?></td> <td><?php echo $row['Start_Date']; ?></td> <td><?php echo $row['End_Date']; ?></td> <td><?php echo $row['Assigned_At']; ?></td> </tr> <?php } ?> </tbody> <tfoot> <tr> <th>Assignment ID</th> <th>Teacher</th> <th>Course</th> <th>Group</th> <th>Program</th> <th>Time Slot</th> <th>Start Date</th> <th>End Date</th> <th>Assigned At</th> </tr> </tfoot> </table> <?php // Query to get all teachers along with their Load_Hours from Teacher_Profile $query = "SELECT Teacher_ID, First_Name, Last_Name, Load_Hours FROM Teacher_Profile"; $result = $mysqli->query($query); if (!$result) { die("Error fetching teachers: " . $mysqli->error); } echo "<h2>Teacher Assigned Hours</h2>"; echo "<table border='1' cellpadding='5' cellspacing='0'>"; echo "<tr> <th>Teacher</th> <th>Load Hours</th> <th>Total Assigned Hours</th> </tr>"; while ($teacher = $result->fetch_assoc()) { $teacher_id = $teacher['Teacher_ID']; $teacherName = $teacher['First_Name'] . " " . $teacher['Last_Name']; $load_hours = $teacher['Load_Hours']; // Query to sum Course_Time for all assignments of this teacher. // Assumes Course_Time is stored in a numeric format (e.g., integer or decimal) representing hours. $stmt = $mysqli->prepare(" SELECT IFNULL(SUM(c.Course_Time), 0) AS total_hours FROM Teacher_Course_Assignments tca JOIN Courses c ON tca.Course_ID = c.Course_ID WHERE tca.Teacher_ID = ? "); if (!$stmt) { die("Error preparing sum query: " . $mysqli->error); } $stmt->bind_param("i", $teacher_id); if (!$stmt->execute()) { die("Error executing sum query: " . $stmt->error); } $result2 = $stmt->get_result(); $sum_row = $result2->fetch_assoc(); $total_hours = $sum_row['total_hours']; $stmt->close(); echo "<tr>"; echo "<td>" . htmlspecialchars($teacherName) . "</td>"; echo "<td>" . htmlspecialchars($load_hours) . "</td>"; echo "<td>" . htmlspecialchars($total_hours) . "</td>"; echo "</tr>"; } echo "</table>"; //} else { //echo "Program ID and Group ID are required."; //} ?>
Save
cmd:
run