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

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

if ($student) {
    echo "Student found: " . $student['first_name'] . ' ' . $student['last_name'] . " (ID: " . $student['id'] . ")\n";
    echo "Class ID: " . $student['class_id'] . "\n";
    echo "Session: " . $student['session'] . "\n";
    echo "Group: " . $student['group_name'] . "\n";
    
    // Get results for this student
    $stmt = $pdo->prepare("SELECT r.*, sub.name as subject_name, sub.code as subject_code 
                          FROM results r 
                          JOIN subjects sub ON r.subject_id = sub.id 
                          WHERE r.student_id = ? AND r.session = ? AND r.exam_type = ? 
                          ORDER BY sub.name");
    $stmt->execute([$student['id'], $student['session'], 'final']);
    $results = $stmt->fetchAll();
    
    echo "\nStudent's results:\n";
    foreach ($results as $result) {
        echo "- " . $result['subject_name'] . " (Code: " . $result['subject_code'] . "): Marks " . $result['marks_obtained'] . ", Grade " . $result['grade'] . "\n";
    }
    
    // Check Bangla subjects specifically
    echo "\nBangla subjects:\n";
    $stmt = $pdo->prepare("SELECT r.*, sub.name as subject_name 
                          FROM results r 
                          JOIN subjects sub ON r.subject_id = sub.id 
                          WHERE r.student_id = ? AND r.session = ? AND r.exam_type = ? 
                          AND (sub.name LIKE '%বাংলা%' OR sub.name LIKE '%Bangla%')
                          ORDER BY sub.name");
    $stmt->execute([$student['id'], $student['session'], 'final']);
    $bangla_results = $stmt->fetchAll();
    
    foreach ($bangla_results as $result) {
        echo "- " . $result['subject_name'] . ": Marks " . $result['marks_obtained'] . ", Grade " . $result['grade'] . "\n";
        // Check if this has detailed CQ marks
        echo "  CQ Marks: " . ($result['cq_marks'] ?? 'N/A') . ", MCQ Marks: " . ($result['mcq_marks'] ?? 'N/A') . "\n";
    }
    
} else {
    echo "Student 20250020 not found\n";
}
?>