<?php
// Verification script to check admission page behavior
require_once 'config/database.php';

echo "<h2>Admission Page Verification</h2>";

// Check if admission is currently open
$admission_open = false;
$admission_message = '';
$admission_dates = null;
$dates_set = false;

try {
    // Try to get admission publish dates
    $stmt = $pdo->query("SELECT * FROM admission_publish_dates WHERE is_active = 1 ORDER BY id DESC LIMIT 1");
    $admission_dates = $stmt->fetch();
    
    if ($admission_dates) {
        $dates_set = true;
        $current_date = date('Y-m-d');
        $start_date = $admission_dates['start_date'];
        $end_date = $admission_dates['end_date'];
        
        echo "Current Date: " . $current_date . "<br>";
        echo "Start Date: " . $start_date . "<br>";
        echo "End Date: " . $end_date . "<br>";
        
        if ($current_date < $start_date) {
            $admission_open = false;
            $admission_message = 'ভর্তি আবেদন ' . date('d/m/Y', strtotime($start_date)) . ' তারিখ থেকে শুরু হবে।';
        } elseif ($current_date > $end_date) {
            $admission_open = false;
            $admission_message = 'ভর্তি আবেদনের সময় শেষ হয়ে গেছে। শেষ তারিখ ছিল ' . date('d/m/Y', strtotime($end_date)) . '।';
        } else {
            $admission_open = true;
            $admission_message = 'ভর্তি আবেদন চলছে।';
        }
    } else {
        // No dates set - show specific message
        $admission_open = false;
        $admission_message = 'এখন পর্যন্ত কোন ভর্তি আবেদনের তারিখ নির্ধারণ করা হয়নি। অনুগ্রহ করে পরে আবার চেষ্টা করুন।';
    }
} catch (Exception $e) {
    // If table doesn't exist or other error, continue with admission closed
    $admission_open = false;
    $admission_message = 'এখন পর্যন্ত কোন ভর্তি আবেদনের তারিখ নির্ধারণ করা হয়নি। অনুগ্রহ করে পরে আবার চেষ্টা করুন।';
}

echo "<h3>Status Check:</h3>";
echo "Admission Open: " . ($admission_open ? 'Yes' : 'No') . "<br>";
echo "Message: " . $admission_message . "<br>";
echo "Dates Set: " . ($dates_set ? 'Yes' : 'No') . "<br>";

if ($admission_dates) {
    echo "<h3>Details:</h3>";
    echo "Academic Year: " . htmlspecialchars($admission_dates['academic_year']) . "<br>";
    echo "Application Period: " . date('d/m/Y', strtotime($admission_dates['start_date'])) . " to " . date('d/m/Y', strtotime($admission_dates['end_date'])) . "<br>";
}

echo "<h3>Expected Behavior:</h3>";
if ($admission_open) {
    echo "✅ Admission form should be visible<br>";
} else {
    echo "❌ Admission form should be hidden<br>";
    echo "✅ Message should be displayed: " . $admission_message . "<br>";
}
?>