<?php
/**
 * Update Session Script
 * Run this once to update your current session with user_type from database
 * After running this, delete this file for security
 */

// Start session
session_start();

// Load configuration
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/config/autoload.php';

// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
    die('No active session found. Please login first.');
}

// Get user from database
$db = Database::getInstance();
$userId = $_SESSION['user_id'];

$sql = "SELECT user_type FROM users WHERE id = ? LIMIT 1";
$user = $db->fetchOne($sql, [$userId]);

if ($user && isset($user['user_type'])) {
    // Update session with user_type
    $_SESSION['user_type'] = $user['user_type'];
    
    echo "✓ Session updated successfully!<br>";
    echo "User ID: " . $userId . "<br>";
    echo "User Type: " . $user['user_type'] . "<br><br>";
    echo "You can now use the system. Please delete this file (update_sessions.php) for security.";
} else {
    echo "✗ Could not find user_type in database.<br>";
    echo "Make sure you have run the SQL query to add the user_type column:<br><br>";
    echo "<code>ALTER TABLE users ADD COLUMN user_type ENUM('admin', 'user') NOT NULL DEFAULT 'user' AFTER email;</code>";
}
?>
