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

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

echo "\nSubjects mapped to classes:\n";
$stmt = $pdo->query("SELECT c.name as class_name, s.name as subject_name, s.code 
                     FROM class_subjects cs 
                     JOIN subjects s ON cs.subject_id = s.id 
                     JOIN classes c ON cs.class_id = c.id 
                     WHERE s.status='active' 
                     ORDER BY c.name, s.name");
$mappings = $stmt->fetchAll();
$current_class = '';
foreach ($mappings as $mapping) {
    if ($current_class != $mapping['class_name']) {
        $current_class = $mapping['class_name'];
        echo "\nClass: {$current_class}\n";
    }
    echo "  - {$mapping['subject_name']} ({$mapping['code']})\n";
}
?>