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

try {
    // Check if session "2025" exists in academic_sessions
    echo "Checking for session '2025' in academic_sessions table:\n";
    $stmt = $pdo->prepare("SELECT * FROM academic_sessions WHERE session_name = ?");
    $stmt->execute(['2025']);
    $session = $stmt->fetch();
    if ($session) {
        echo "Found session: ID: " . $session['id'] . ", Name: " . $session['session_name'] . ", Current: " . $session['is_current'] . ", Status: " . $session['status'] . "\n";
    } else {
        echo "Session '2025' not found in academic_sessions table\n";
    }
    
    // Count students with session '2025'
    echo "\nCounting students with session '2025':\n";
    $stmt = $pdo->prepare("SELECT COUNT(*) as count FROM students WHERE session = ?");
    $stmt->execute(['2025']);
    $count = $stmt->fetch();
    echo "Students with session '2025': " . $count['count'] . "\n";
    
    // Check if there are any active sessions in academic_sessions
    echo "\nActive sessions in academic_sessions table:\n";
    $stmt = $pdo->query("SELECT * FROM academic_sessions WHERE status = 'active' ORDER BY is_current DESC, id DESC");
    $sessions = $stmt->fetchAll();
    foreach ($sessions as $session) {
        echo "- ID: " . $session['id'] . ", Name: " . $session['session_name'] . ", Current: " . $session['is_current'] . ", Status: " . $session['status'] . "\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>