/home/techb158/workloadmatch.com/workloadmatch.com/api/reports
Edit: /home/techb158/workloadmatch.com/workloadmatch.com/api/reports/schedule-by-course.php (3063B)
"error",
"message" => "Unauthorized: Please log in."
]);
exit();
}
$teacherId = $_SESSION['user_id'];
// Build the query to fetch schedule records for the logged‑in teacher.
// This query joins the Course_Group_Schedule table (alias s) with the Courses table (alias c)
// and filters records where s.Teacher_ID equals the teacher's ID.
$query = "SELECT
s.Schedule_ID,
s.Program_ID,
p.Program_Name,
s.Course_ID,
c.Course_Name,
cs.Group_ID,
g.Group_Name,
cs.Time_Slot,
cs.Start_Date,
cs.End_Date,
cs.Start_Time,
cs.End_Time,
cs.Assigned,
c.Course_Name
FROM Teacher_Course_Assignments s
JOIN Programs p ON p.Program_ID = s.Program_ID
JOIN Courses c ON s.Course_ID = c.Course_ID
JOIN Manager_Group_Name g ON g.Group_ID = s.Group_ID
JOIN Course_Group_Schedule cs ON cs.Schedule_ID = s.Schedule_ID
WHERE s.Teacher_ID = ?
ORDER BY cs.Course_ID, cs.Start_Date";
if ($stmt = $mysqli->prepare($query)) {
$stmt->bind_param("i", $teacherId);
$stmt->execute();
$result = $stmt->get_result();
$data = [];
while ($row = $result->fetch_assoc()) {
// Group the schedule data by Course_ID.
$data[$row['Course_ID']][] = $row;
}
echo json_encode([
"status" => "success",
"data" => $data
]);
$stmt->close();
} else {
http_response_code(500);
echo json_encode([
"status" => "error",
"message" => "Database error: " . $mysqli->error
]);
}
exit();
/*
// Query to fetch schedule by course; adjust field names if your schema uses different ones.
$query = "SELECT s.Schedule_ID, s.Program_ID, s.Course_ID, s.Group_ID, s.Time_Slot, s.Start_Date, s.End_Date, s.Start_Time, s.End_Time, s.Assigned, c.Course_Name
FROM Course_Group_Schedule s
JOIN Courses c ON s.Course_ID = c.Course_ID
ORDER BY s.Course_ID, s.Start_Date";
$result = $mysqli->query($query);
if (!$result) {
http_response_code(500);
echo json_encode([
"status" => "error",
"message" => "Database error: " . $mysqli->error
]);
exit();
}
$data = [];
while ($row = $result->fetch_assoc()) {
// Group schedule data by course.
$data[$row['Course_ID']][] = $row;
}
echo json_encode([
"status" => "success",
"data" => $data
]);
exit();
*/
?>