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

// Test the admit card photo functionality with student 6193
$student_id = 6193;
$exam_id = 68;

// Get student details
$stmt = $pdo->prepare("
    SELECT s.*, c.name as class_name, c.section
    FROM students s
    JOIN classes c ON s.class_id = c.id
    WHERE s.id = ?
");
$stmt->execute([$student_id]);
$student = $stmt->fetch();

echo "Student Info:\n";
echo "Name: " . $student['first_name'] . ' ' . $student['last_name'] . "\n";
echo "Photo: " . ($student['photo'] ? $student['photo'] : 'No photo') . "\n";

if ($student['photo']) {
    $photo_path = '../' . $student['photo'];
    echo "Photo path: " . $photo_path . "\n";
    echo "File exists: " . (file_exists($photo_path) ? 'Yes' : 'No') . "\n";
    
    if (file_exists($photo_path)) {
        echo "Photo can be displayed on admit card!\n";
    } else {
        echo "Photo file not found. Need to fix path.\n";
    }
}

// Get exam subjects that the student is enrolled in
$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]);
$exam_subjects = $stmt->fetchAll();

echo "\nExam subjects for this student:\n";
foreach ($exam_subjects as $subject) {
    echo "- " . $subject['subject_name'] . " (" . $subject['subject_code'] . ")\n";
}
?>