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

try {
    // Show sessions
    echo "Available sessions in academic_sessions table:\n";
    $stmt = $pdo->query("SELECT * FROM academic_sessions ORDER BY is_current DESC, id DESC");
    $sessions = $stmt->fetchAll();
    if (empty($sessions)) {
        echo "No sessions found in academic_sessions table\n";
    } else {
        foreach ($sessions as $session) {
            echo "- ID: " . $session['id'] . ", Name: " . $session['session_name'] . ", Current: " . $session['is_current'] . ", Status: " . $session['status'] . "\n";
        }
    }
    
    // Check some sample student data
    echo "\nSample student records:\n";
    $stmt = $pdo->query("SELECT id, student_id, first_name, last_name, session, session_id FROM students LIMIT 5");
    $students = $stmt->fetchAll();
    foreach ($students as $student) {
        echo "- ID: " . $student['id'] . ", Student ID: " . $student['student_id'] . ", Name: " . $student['first_name'] . " " . $student['last_name'] . ", Session: " . $student['session'] . ", Session ID: " . $student['session_id'] . "\n";
    }
    
    // Check what sessions exist in the students table
    echo "\nSessions currently used in students table:\n";
    $stmt = $pdo->query("SELECT DISTINCT session FROM students WHERE session IS NOT NULL AND session != '' ORDER BY session");
    $student_sessions = $stmt->fetchAll(PDO::FETCH_COLUMN);
    foreach ($student_sessions as $sess) {
        echo "- " . $sess . "\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>