<?php
session_start();
$_SESSION['user_id'] = 1;
$_SESSION['user_role'] = 'admin';
$_SESSION['user_name'] = 'Admin User';

require_once 'config/database.php';

// Test getting classes
$stmt = $pdo->query("SELECT id, name, section FROM classes WHERE status = 'active' ORDER BY name, section LIMIT 3");
$classes = $stmt->fetchAll();

echo "Classes:\n";
foreach ($classes as $class) {
    echo "- " . $class['name'] . " - " . $class['section'] . " (ID: " . $class['id'] . ")\n";
}

// Test getting teachers
$stmt = $pdo->query("
    SELECT t.id, t.employee_id, t.first_name, t.last_name 
    FROM teachers t 
    WHERE t.status = 'active' 
    ORDER BY t.first_name, t.last_name 
    LIMIT 3
");
$teachers = $stmt->fetchAll();

echo "\nTeachers:\n";
foreach ($teachers as $teacher) {
    echo "- " . $teacher['first_name'] . " " . $teacher['last_name'] . " (ID: " . $teacher['id'] . ")\n";
}

// Test getting subjects for first class
if (!empty($classes)) {
    $class_id = $classes[0]['id'];
    echo "\nSubjects for class " . $classes[0]['name'] . " - " . $classes[0]['section'] . ":\n";
    
    $stmt = $pdo->prepare("
        SELECT s.id, s.name, s.code, cs.teacher_id,
               t.first_name as teacher_first_name, t.last_name as teacher_last_name
        FROM class_subjects cs
        JOIN subjects s ON cs.subject_id = s.id
        LEFT JOIN teachers t ON cs.teacher_id = t.id
        WHERE cs.class_id = ? AND s.status = 'active'
        ORDER BY s.name
    ");
    $stmt->execute([$class_id]);
    $subjects = $stmt->fetchAll();
    
    if (empty($subjects)) {
        echo "No subjects assigned to this class yet.\n";
    } else {
        foreach ($subjects as $subject) {
            echo "- " . $subject['name'] . " (" . $subject['code'] . ")";
            if ($subject['teacher_id']) {
                echo " - Assigned to: " . $subject['teacher_first_name'] . " " . $subject['teacher_last_name'];
            } else {
                echo " - No teacher assigned";
            }
            echo "\n";
        }
    }
}
?>