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

// Check student information
$stmt = $pdo->prepare('SELECT * FROM students WHERE student_id = ?');
$stmt->execute(['20250008']);
$student = $stmt->fetch();

echo "Student Information:\n";
print_r($student);

// Check student results
if ($student) {
    echo "\nStudent Results:\n";
    $stmt = $pdo->prepare('SELECT * FROM results WHERE student_id = ? AND session = ? AND exam_type = ?');
    $stmt->execute([$student['id'], '2025', 'final']);
    $results = $stmt->fetchAll();
    
    foreach ($results as $result) {
        // Get subject name
        $stmt2 = $pdo->prepare('SELECT * FROM subjects WHERE id = ?');
        $stmt2->execute([$result['subject_id']]);
        $subject = $stmt2->fetch();
        
        echo "Subject: {$subject['name']}, Marks: {$result['marks_obtained']}, Grade: {$result['grade']}\n";
        
        // Check mark distribution for this subject
        $stmt3 = $pdo->prepare('SELECT * FROM mark_distributions WHERE subject_id = ? AND class_id = ? AND session = ? AND exam_type = ?');
        $stmt3->execute([$result['subject_id'], $student['class_id'], $student['session'], $result['exam_type']]);
        $mark_dist = $stmt3->fetch();
        
        if ($mark_dist) {
            echo "  Full Marks: " . (isset($mark_dist['full_marks']) ? $mark_dist['full_marks'] : 'N/A') . ", Pass Marks: " . (isset($mark_dist['pass_marks']) ? $mark_dist['pass_marks'] : 'N/A') . "\n";
        } else {
            echo "  No mark distribution found for this subject\n";
        }
    }
    
    // Check student subjects
    echo "\nStudent Subjects:\n";
    $stmt = $pdo->prepare('SELECT ss.*, s.name as subject_name FROM student_subjects ss JOIN subjects s ON ss.subject_id = s.id WHERE ss.student_id = ?');
    $stmt->execute([$student['id']]);
    $subjects = $stmt->fetchAll();
    
    foreach ($subjects as $subject) {
        echo "Subject: {$subject['subject_name']}, Is Fourth: {$subject['is_fourth_subject']}\n";
    }
}
?>