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

// Get all classes
$stmt = $pdo->query("SELECT id, name, section FROM classes ORDER BY name");
$classes = $stmt->fetchAll();

echo "<h2>Subjects for Each Class</h2>\n";
echo "<ul>\n";

foreach ($classes as $class) {
    echo "<li><strong>{$class['name']} {$class['section']}</strong> (ID: {$class['id']})\n";
    echo "<ul>\n";
    
    // Get subjects for this class
    $stmt = $pdo->prepare("
        SELECT s.id as subject_id, s.name, s.code
        FROM subjects s
        JOIN class_subjects cs ON s.id = cs.subject_id
        WHERE cs.class_id = ? AND s.status = 'active'
        ORDER BY s.name
    ");
    $stmt->execute([$class['id']]);
    $subjects = $stmt->fetchAll();
    
    if (!empty($subjects)) {
        foreach ($subjects as $subject) {
            echo "<li>{$subject['name']} ({$subject['code']})</li>\n";
        }
    } else {
        echo "<li><em>No subjects assigned</em></li>\n";
    }
    
    echo "</ul>\n";
    echo "</li>\n";
}

echo "</ul>\n";
?>