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

// Debug the marks entry issue
echo "Debugging marks entry issue\n";

// Check classes
$stmt = $pdo->query('SELECT id, name FROM classes');
$classes = $stmt->fetchAll();
echo "Available classes:\n";
foreach($classes as $class) {
    echo "  {$class['id']}: {$class['name']}\n";
}

// Check sessions
$stmt = $pdo->query('SELECT session_name FROM academic_sessions WHERE status = "active" ORDER BY session_name DESC');
$sessions = $stmt->fetchAll();
echo "\nAvailable sessions:\n";
foreach($sessions as $session) {
    echo "  {$session['session_name']}\n";
}

// Check if class_id=10 exists
$stmt = $pdo->prepare('SELECT COUNT(*) as count FROM students WHERE class_id = ? AND session = ?');
$stmt->execute([10, '2025']);
$result = $stmt->fetch();
echo "\nStudents in class_id=10, session=2025: {$result['count']}\n";

// Check if class_id=11 exists (from sample data)
$stmt = $pdo->prepare('SELECT COUNT(*) as count FROM students WHERE class_id = ? AND session = ?');
$stmt->execute([11, '2024']);
$result = $stmt->fetch();
echo "Students in class_id=11, session=2024: {$result['count']}\n";

// Check subjects
$stmt = $pdo->query('SELECT id, name, code FROM subjects WHERE status = "active" ORDER BY name');
$subjects = $stmt->fetchAll();
echo "\nAvailable subjects:\n";
foreach($subjects as $subject) {
    echo "  {$subject['id']}: {$subject['name']} ({$subject['code']})\n";
}

// Check student_subjects for subject_id=35
$stmt = $pdo->prepare('SELECT COUNT(*) as count FROM student_subjects WHERE subject_id = ?');
$stmt->execute([35]);
$result = $stmt->fetch();
echo "\nStudent-subject mappings for subject_id=35: {$result['count']}\n";

// Check if there are students enrolled in subject_id=35 in class_id=10
$stmt = $pdo->prepare('
    SELECT COUNT(*) as count 
    FROM students s 
    INNER JOIN student_subjects ss ON ss.student_id = s.id 
    WHERE s.class_id = ? AND s.session = ? AND ss.subject_id = ?
');
$stmt->execute([10, '2025', 35]);
$result = $stmt->fetch();
echo "Students in class_id=10, session=2025 enrolled in subject_id=35: {$result['count']}\n";

echo "\nDebug complete.\n";
?>