<?php
//Developer: core tech web designTechnology
// Switch back from user impersonation to admin account

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Check if currently impersonating
if (!isset($_SESSION['admin_impersonating']) || $_SESSION['admin_impersonating'] !== true) {
    header('Location: http://' . $_SERVER['HTTP_HOST'] . '/llcpro/jediprime/CompleteVTU/signin.php');
    exit();
}

// Restore admin session
$admin_id = $_SESSION['admin_original_user_id'];
$admin_email = $_SESSION['admin_original_email'];

// Clear impersonation flags
unset($_SESSION['admin_impersonating']);
unset($_SESSION['admin_original_user_id']);
unset($_SESSION['admin_original_email']);

// Restore admin session
$_SESSION['user_id'] = $admin_id;
$_SESSION['user_email'] = $admin_email;
$_SESSION['logged_in'] = true;
$_SESSION['verified'] = true;
$_SESSION['is_admin'] = 1;

// Redirect back to admin dashboard
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/llcpro/jediprime/CompleteVTU/admin/dashboard.php');
exit();
