prepare($sql_course)) {
// Bind variables to the prepared statement as parameters
$stmt_course->bind_param("s", $param_courseID);
// Set parameters
$param_courseID = $courseID;
// Attempt to execute the prepared statement
if ($stmt_course->execute()) {
// Get result
$result = $stmt_course->get_result();
// Check if the course exists
if ($result->num_rows == 1) {
// Fetch result as an associative array
$courseDetails = $result->fetch_assoc();
$coursename = $courseDetails['coursename'];
$degree = $courseDetails['degree'];
$startdate = $courseDetails['start'];
$time = $courseDetails['time'];
$room = $courseDetails['room'];
$instructorID = $courseDetails['instructorID'];
} else {
// Course not found, handle the error as needed
header('Location: /acb/login.html?error=Course not found');
exit();
}
} else {
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
$stmt_course->close();
}
// Create DateTime objects
try {
$startdateObj = new DateTime($startdate);
$timeObj = new DateTime($time);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
exit;
}
// Translate day of the week and time of day
$dayOfWeek = translateDayOfWeek($startdateObj->format('l'));
$timeOfDay = translateTimeOfDay((int)$timeObj->format('H'));
// Format date and time
$startdateFormatted = $startdateObj->format('d/m/Y');
$timeFormatted = $timeObj->format('H:i');
// Combine the time description
$fullTimeDescription = $timeFormatted . ' (' . $dayOfWeek . ' ' . $timeOfDay . ')';
//echo $fullTimeDescription;
// Fetch instructor's full name based on instructorID
$instructor = 'Instructor not found';
$sql_instructor = "SELECT fullname FROM instructors WHERE instructorID = ?";
if ($stmt_instructor = $link->prepare($sql_instructor)) {
// Bind variables to the prepared statement as parameters
$stmt_instructor->bind_param("s", $param_instructorID);
// Set parameters
$param_instructorID = $instructorID;
// Attempt to execute the prepared statement
if ($stmt_instructor->execute()) {
// Get result
$result = $stmt_instructor->get_result();
// Check if the instructor exists
if ($result->num_rows == 1) {
// Fetch result as an associative array
$instructorData = $result->fetch_assoc();
$instructor = $instructorData['fullname'];
} else {
// Instructor not found, handle the error as needed
$instructor = 'Instructor not found';
}
} else {
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
$stmt_instructor->close();
}
// Fetch the bonus score from the student table
$sql = "SELECT bonus, `group` FROM students WHERE studentID = ? AND courseID = ?";
$stmt = $link->prepare($sql);
$stmt->bind_param("ss", $studentID, $courseID);
$stmt->execute();
$result = $stmt->get_result();
// Fetch the results or set default values
if ($row = $result->fetch_assoc()) {
$bonusScore = $row['bonus'] !== null ? $row['bonus']/50 : 0;
$groupID = !empty($row['group']) ? $row['group'] : "Not Assigned"; // Default to "Not Assigned"
} else {
$bonusScore = 0;
$groupID = "Not Assigned"; // Default if no record found
}
// Get midterm scores
$scores = getMidtermScore($studentID, $courseID, $link);
// Check for errors
if (isset($scores["error"])) {
echo "