<?php
echo "<h1>🔍 NIS-AMS Setup Check</h1>";

// Check PHP version
echo "<h2>PHP Information</h2>";
echo "<pre>";
echo "PHP Version: " . phpversion() . "\n";
echo "Loaded Extensions: " . implode(', ', get_loaded_extensions()) . "\n";
echo "</pre>";

// Check directories
echo "<h2>Directory Structure</h2>";
$dirs = ['config', 'core', 'controllers', 'models', 'views', 'assets'];
echo "<ul>";
foreach ($dirs as $dir) {
    if (is_dir($dir)) {
        echo "<li style='color:green'>✓ $dir directory exists</li>";
    } else {
        echo "<li style='color:red'>✗ $dir directory missing</li>";
    }
}
echo "</ul>";

// Check important files
echo "<h2>Important Files</h2>";
$files = ['.htaccess', 'index.php', 'dashboard.php'];
echo "<ul>";
foreach ($files as $file) {
    if (file_exists($file)) {
        echo "<li style='color:green'>✓ $file exists</li>";
    } else {
        echo "<li style='color:red'>✗ $file missing</li>";
    }
}
echo "</ul>";

// Check .htaccess content
echo "<h2>.htaccess Content</h2>";
if (file_exists('.htaccess')) {
    echo "<pre>" . htmlspecialchars(file_get_contents('.htaccess')) . "</pre>";
} else {
    echo "<p style='color:red'>.htaccess file not found</p>";
}

// Test rewrite
echo "<h2>Rewrite Test</h2>";
echo "<p>If you see this page, rewrite is working: <a href='test_rewrite'>Test Link</a></p>";
echo "<p>Create a file called 'test_rewrite' to test 404 handling</p>";

// Server info
echo "<h2>Server Information</h2>";
echo "<pre>";
echo "DOCUMENT_ROOT: " . $_SERVER['DOCUMENT_ROOT'] . "\n";
echo "SCRIPT_FILENAME: " . $_SERVER['SCRIPT_FILENAME'] . "\n";
echo "REQUEST_URI: " . $_SERVER['REQUEST_URI'] . "\n";
echo "SCRIPT_NAME: " . $_SERVER['SCRIPT_NAME'] . "\n";
echo "PHP_SELF: " . $_SERVER['PHP_SELF'] . "\n";
echo "</pre>";