<?php
// Simple test page to check what's working
echo "<!DOCTYPE html><html><head><title>Test Page</title></head><body>";
echo "<h1>ConnectPay Test Page</h1>";
echo "<p><strong>PHP is working!</strong></p>";

// Test session
echo "<h2>Session Test</h2>";
if (file_exists('services/session.php')) {
    echo "<p>✓ services/session.php exists</p>";
    try {
        include 'services/session.php';
        echo "<p>✓ Session included successfully</p>";
        echo "<p>Session user: " . ($_SESSION['user'] ?? 'Not set') . "</p>";
        echo "<p>User ID: " . ($_SESSION['user_id'] ?? 'Not set') . "</p>";
        echo "<p>Role: " . ($_SESSION['role_name'] ?? 'Not set') . "</p>";
    } catch (Exception $e) {
        echo "<p>✗ Session error: " . $e->getMessage() . "</p>";
    }
} else {
    echo "<p>✗ services/session.php not found</p>";
}

// Test database
echo "<h2>Database Test</h2>";
if (file_exists('layouts/dbconn.php')) {
    echo "<p>✓ layouts/dbconn.php exists</p>";
    try {
        require_once 'layouts/dbconn.php';
        echo "<p>✓ Database file included</p>";
        if (isset($conn)) {
            if ($conn->connect_error) {
                echo "<p>✗ Database connection error: " . $conn->connect_error . "</p>";
            } else {
                echo "<p>✓ Database connected successfully</p>";
                
                // Test a simple query
                $result = $conn->query("SELECT COUNT(*) as count FROM users");
                if ($result) {
                    $row = $result->fetch_assoc();
                    echo "<p>✓ Users table accessible, count: " . $row['count'] . "</p>";
                } else {
                    echo "<p>✗ Query failed: " . $conn->error . "</p>";
                }
            }
        } else {
            echo "<p>✗ Connection object not created</p>";
        }
    } catch (Exception $e) {
        echo "<p>✗ Database error: " . $e->getMessage() . "</p>";
    }
} else {
    echo "<p>✗ layouts/dbconn.php not found</p>";
}

// Test partials
echo "<h2>Partials Test</h2>";
$partials = ['title-meta.php', 'head-css.php', 'body.php', 'menu.php', 'footer.php', 'footer-scripts.php'];
foreach ($partials as $partial) {
    if (file_exists("partials/$partial")) {
        echo "<p>✓ partials/$partial exists</p>";
    } else {
        echo "<p>✗ partials/$partial not found</p>";
    }
}

// Show current directory and files
echo "<h2>File System Test</h2>";
echo "<p>Current directory: " . getcwd() . "</p>";
echo "<p>Files in current directory:</p>";
echo "<ul>";
$files = scandir('.');
foreach ($files as $file) {
    if ($file !== '.' && $file !== '..') {
        echo "<li>$file</li>";
    }
}
echo "</ul>";

// Show server info
echo "<h2>Server Info</h2>";
echo "<p>PHP Version: " . phpversion() . "</p>";
echo "<p>Server Software: " . ($_SERVER['SERVER_SOFTWARE'] ?? 'Unknown') . "</p>";
echo "<p>Document Root: " . ($_SERVER['DOCUMENT_ROOT'] ?? 'Unknown') . "</p>";

echo "<h2>Test Links</h2>";
echo "<p><a href='topup-wallet.php'>Test Topup Wallet Page</a></p>";
echo "<p><a href='wallet-overview.php'>Test Wallet Overview Page</a></p>";
echo "<p><a href='customer-dashboard.php'>Back to Dashboard</a></p>";

echo "</body></html>";
?>