<?php
/**
 * Session Test Script - Verify multi-user session system
 */
require_once 'session_manager.php';

// Start session for testing
session_start();

echo "<h2>Multi-User Session System Test</h2>";

// Test SessionManager instance
$sessionManager = SessionManager::getInstance();
echo "<h3>✅ SessionManager initialized successfully</h3>";

// Display all user configurations
echo "<h3>📋 User Configuration:</h3>";
$activeSessions = $sessionManager->getActiveSessions();
foreach ($activeSessions as $username => $info) {
    echo "<div style='margin: 10px; padding: 10px; border: 1px solid #ccc; border-radius: 5px;'>";
    echo "<strong>Username:</strong> {$username}<br>";
    echo "<strong>Session Name:</strong> {$info['session_name']}<br>";
    echo "<strong>Image Path:</strong> {$info['image_path']}<br>";
    echo "<strong>Status:</strong> {$info['status']}<br>";
    echo "</div>";
}

// Test current session if logged in
if (isset($_SESSION['username'])) {
    echo "<h3>🔐 Current Session Info:</h3>";
    echo "<strong>Logged in as:</strong> " . $_SESSION['username'] . "<br>";
    echo "<strong>Session ID:</strong> " . session_id() . "<br>";
    echo "<strong>User Image Path:</strong> " . $sessionManager->getCurrentUserImagePath() . "<br>";
} else {
    echo "<h3>❌ No active session</h3>";
    echo "<p>Please log in through the main interface to test session functionality.</p>";
}

// Test folder structure
echo "<h3>📁 Chart Image Folders:</h3>";
$baseImagePath = '../img/chart-img/';
$users = ['unrealengine_developer', 'unrealengine_admin', 'unrealengine_user1', 'unrealengine_user2'];

foreach ($users as $user) {
    $userPath = $baseImagePath . $user . '/';
    $exists = file_exists($userPath) ? '✅' : '❌';
    $writable = is_writable($userPath) ? '✅' : '❌';
    echo "<div style='margin: 5px;'>";
    echo "<strong>{$user}:</strong> Exists {$exists} | Writable {$writable} | Path: {$userPath}";
    echo "</div>";
}

echo "<hr>";
echo "<p><strong>Test completed!</strong> Each user now has isolated sessions and separate chart image folders.</p>";
echo "<p><a href='../index.php'>← Back to Trading Platform</a></p>";
?>

<style>
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
h2, h3 { color: #333; }
div { background: white; }
</style>