<?php
// Test script to verify tabulation sheet functionality with detailed marks
require_once 'config/database.php';

// Simulate the tabulation sheet query
$class_id = 1;
$session = 2025;
$exam_type = 'midterm';

// Get all results for this class, session, and exam (same query as tabulation_sheet.php)
$stmt = $pdo->prepare("
    SELECT r.*, s.student_id as roll_number
    FROM results r
    JOIN students s ON r.student_id = s.id
    WHERE s.class_id = ? AND r.session = ? AND r.exam_type = ?
");
$stmt->execute([$class_id, $session, $exam_type]);
$all_results = $stmt->fetchAll();

echo "Found " . count($all_results) . " results\n";

// Check if detailed marks are present
if (!empty($all_results)) {
    $sample = $all_results[0];
    echo "Sample result data:\n";
    echo "- Student ID: " . $sample['student_id'] . "\n";
    echo "- Subject ID: " . $sample['subject_id'] . "\n";
    echo "- Marks Obtained: " . $sample['marks_obtained'] . "\n";
    echo "- CQ Marks: " . ($sample['cq_marks'] ?: 'NULL') . "\n";
    echo "- MCQ Marks: " . ($sample['mcq_marks'] ?: 'NULL') . "\n";
    echo "- Practical Marks: " . ($sample['practical_marks'] ?: 'NULL') . "\n";
    echo "- Assignment Marks: " . ($sample['assignment_marks'] ?: 'NULL') . "\n";
    echo "- Attendance Marks: " . ($sample['attendance_marks'] ?: 'NULL') . "\n";
    echo "- Grade: " . $sample['grade'] . "\n";
}

echo "\nTabulation sheet should display these detailed marks correctly.\n";
?>