<?php

// Match login.php session lifetime

$sessionLifetime = 86400; // 24 hours

ini_set('session.gc_maxlifetime', $sessionLifetime);

ini_set('session.cookie_lifetime', $sessionLifetime);



session_name("teacher_portal");

session_start();



// Detect tab_id

if (isset($_GET['tab_id']) && $_GET['tab_id'] !== '') {

    $tabSessionID = $_GET['tab_id'];

    $_SESSION['current_tab_id'] = $tabSessionID;

} elseif (isset($_SESSION['current_tab_id'])) {

    $tabSessionID = $_SESSION['current_tab_id'];

} else {

    header("Location: teacher.php?error=2");

    exit();

}



// Ensure tab exists

if (!isset($_SESSION['tabs'][$tabSessionID])) {

    header("Location: teacher.php?error=3");

    exit();

}



// Keep session alive

$_SESSION['tabs'][$tabSessionID]['last_active'] = time();



// Load tab-specific data into global vars (for old code compatibility)

$tabData = $_SESSION['tabs'][$tabSessionID];

$_SESSION['sid']        = $tabData['sid'];

$_SESSION['name']       = $tabData['name'];

$_SESSION['lastname']   = $tabData['lastname'];

$_SESSION['permission'] = $tabData['permission'];

$_SESSION['email']      = $tabData['email'];

$_SESSION['login']      = $tabData['login'];

