<?php
require_once 'config/database.php';

// Test function to get student subjects
function getStudentSubjects($pdo, $exam_id, $student_id) {
    $stmt = $pdo->prepare("
        SELECT es.*, s.name as subject_name, s.code as subject_code
        FROM exam_subjects es
        JOIN subjects s ON es.subject_id = s.id
        JOIN student_subjects ss ON es.subject_id = ss.subject_id
        WHERE es.exam_id = ? AND ss.student_id = ?
        ORDER BY es.exam_date, es.start_time
    ");
    $stmt->execute([$exam_id, $student_id]);
    return $stmt->fetchAll();
}

try {
    // Test with exam ID 68 and a student ID
    $exam_id = 68;
    $student_id = 1; // Assuming student ID 1 exists
    
    echo "Testing student subjects for exam ID $exam_id and student ID $student_id:\n";
    
    $subjects = getStudentSubjects($pdo, $exam_id, $student_id);
    
    echo "Found " . count($subjects) . " subjects:\n";
    
    foreach ($subjects as $subject) {
        echo "- " . $subject['subject_name'] . " (" . $subject['subject_code'] . ")\n";
        echo "  Date: " . $subject['exam_date'] . ", Time: " . $subject['start_time'] . " - " . $subject['end_time'] . "\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>