/home/techb158/workloadmatch.com/Manager
Edit: /home/techb158/workloadmatch.com/Manager/fetch_teacher_conflicts_only_legacy.php (6702B)
prepare("SELECT Time_Slot FROM teacher_profile WHERE Teacher_ID = ?");
$teacherSlotStmt->bind_param("i", $teacherID);
$teacherSlotStmt->execute();
$teacherSlotResult = $teacherSlotStmt->get_result();
$teacherSlotRow = $teacherSlotResult->fetch_assoc();
$teacherSlots = $teacherSlotRow ? trim($teacherSlotRow['Time_Slot']) : '';
$teacherSlotStmt->close();
// Query to get courses for this program
$query = "SELECT Course_ID, Course_Name FROM Courses WHERE Program_ID = ? ORDER BY Course_ID";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("i", $programID);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$courseID = $row["Course_ID"];
// Check if an unassigned schedule exists for this course and group
$checkStmt = $mysqli->prepare("SELECT COUNT(*) FROM course_group_schedule_main
WHERE Program_ID = ? AND Course_ID = ? AND Group_ID = ? AND Assigned = 0");
if (!$checkStmt) {
continue;
}
$checkStmt->bind_param('iii', $programID, $courseID, $groupID);
$checkStmt->execute();
$checkStmt->bind_result($count);
$checkStmt->fetch();
$checkStmt->close();
if ($count > 0) {
// Check if teacher prefers this course
if ($teacherID > 0) {
$prefStmt = $mysqli->prepare("SELECT COUNT(*) FROM teacher_course_preferences
WHERE Teacher_ID = ? AND Course_ID = ?");
$prefStmt->bind_param("ii", $teacherID, $courseID);
$prefStmt->execute();
$prefStmt->bind_result($prefCount);
$prefStmt->fetch();
$prefStmt->close();
if ($prefCount == 0) {
continue;
}
}
// Fetch schedule details
$fetchStmt = $mysqli->prepare("SELECT Reserve_Course, Time_Slot, Start_Date, End_Date, Start_Time, End_Time
FROM course_group_schedule_main
WHERE Program_ID = ? AND Course_ID = ? AND Group_ID = ? AND Assigned = 0");
if (!$fetchStmt) {
continue;
}
$fetchStmt->bind_param('iii', $programID, $courseID, $groupID);
$fetchStmt->execute();
$fetchStmt->bind_result($Reserve_Course, $Time_Slot, $Start_Date, $End_Date, $Start_Time, $End_Time);
if (!$fetchStmt->fetch()) {
$fetchStmt->close();
continue;
}
$fetchStmt->close();
$checkedReserve = ($Reserve_Course == 1) ? 'checked' : '';
// Check conflict with teacher's current schedule (proper overlap)
if ($teacherID > 0) {
$conflictStmt = $mysqli->prepare("
SELECT COUNT(*)
FROM teacher_course_assignments
WHERE Teacher_ID = ?
AND Time_Slot = ?
AND Start_Date <= ?
AND End_Date >= ?
");
if ($conflictStmt) {
$conflictStmt->bind_param("isss", $teacherID, $Time_Slot, $End_Date, $Start_Date);
$conflictStmt->execute();
$conflictStmt->bind_result($conflictCount);
$conflictStmt->fetch();
$conflictStmt->close();
if ($conflictCount > 0) {
continue;
}
// Check if the teacher is unavailable during the given period
$availabilityStmt = $mysqli->prepare(
"SELECT COUNT(*) FROM teacher_unavailability
WHERE Teacher_ID = ?
AND Unavailable_From <= ?
AND Unavailable_To >= ?"
);
if ($availabilityStmt) {
$availabilityStmt->bind_param("iss", $teacherID, $End_Date, $Start_Date);
$availabilityStmt->execute();
$availabilityStmt->bind_result($unavailableCount);
$availabilityStmt->fetch();
$availabilityStmt->close();
if ($unavailableCount > 0) {
continue;
}
}
}
}
$Start_Time = date("h:i A", strtotime($Start_Time));
$End_Time = date("h:i A", strtotime($End_Time));
echo "
|
|
" . htmlspecialchars($row["Course_Name"]) . " |
|
|
|
|
|
";
}
}
$stmt->close();
$mysqli->close();
}
?>