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

echo "Testing class_teachers functionality...\n\n";

// Check if class_teachers table exists
try {
    $stmt = $pdo->query("DESCRIBE class_teachers");
    echo "✓ class_teachers table exists\n";
    
    // Show table structure
    echo "Table structure:\n";
    while ($row = $stmt->fetch()) {
        echo "  " . $row['Field'] . " " . $row['Type'] . "\n";
    }
    
    echo "\n";
    
    // Check existing data
    $stmt = $pdo->query("SELECT COUNT(*) as count FROM class_teachers");
    $count = $stmt->fetch()['count'];
    echo "✓ Found $count records in class_teachers table\n";
    
    // Show sample data
    if ($count > 0) {
        $stmt = $pdo->query("SELECT ct.*, c.name as class_name, t.first_name, t.last_name FROM class_teachers ct JOIN classes c ON ct.class_id = c.id JOIN teachers t ON ct.teacher_id = t.id LIMIT 5");
        echo "Sample records:\n";
        while ($row = $stmt->fetch()) {
            echo "  Class: " . $row['class_name'] . ", Teacher: " . $row['first_name'] . " " . $row['last_name'] . ", Type: " . $row['assignment_type'] . "\n";
        }
    }
    
} catch (Exception $e) {
    echo "✗ Error: " . $e->getMessage() . "\n";
}

echo "\nTesting completed.\n";
?>