<?php
// Filename: switch_view.php
require 'config.php';
requireLogin();

// 1. Switch to Teacher Mode
if (isset($_GET['mode']) && $_GET['mode'] === 'teacher') {
    // Only allow high-level roles to switch down
    $allowed_admins = ['admin', 'principal', 'assistant', 'timetable_coord'];
    
    if (in_array($_SESSION['role'], $allowed_admins)) {
        $_SESSION['original_role'] = $_SESSION['role']; // Save real role
        $_SESSION['role'] = 'teacher'; // Become teacher
    }
}

// 2. Restore Admin Mode
if (isset($_GET['mode']) && $_GET['mode'] === 'restore') {
    if (isset($_SESSION['original_role'])) {
        $_SESSION['role'] = $_SESSION['original_role']; // Restore real role
        unset($_SESSION['original_role']); // Clear backup
    }
}

// Redirect back to Dashboard
header("Location: dashboard.php");
exit;
?>