<?php
session_cache_limiter('none');
session_start();

$path = "../libraries/";

include_once $path."configuration.php";

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

try {
    if (isset($_GET['login']) && $_SESSION['s_login']) {
        $currentUser        = EfrontUserFactory::factory($_SESSION['s_login']);
        $additionalAccounts = unserialize($currentUser -> user['additional_accounts']);

        if (in_array($_GET['login'], $additionalAccounts)) {
            $newUser = EfrontUserFactory::factory($_GET['login']);
            $_SESSION['s_login']    = $newUser -> user['login'];
            $_SESSION['s_type']     = $newUser -> user['user_type'];
            $_SESSION['s_password'] = md5($newUser -> user['password'].G_MD5KEY);           
            
            if ($_SESSION['s_type'] != 'administrator' && $_SESSION['s_lessons_ID']) {
                setcookie('c_request', $_SESSION['s_type'].'.php?lessons_ID='.$_SESSION['s_lessons_ID'], time() + 300);                
            }
            echo $_SESSION['s_type'].'page.php';            
        }        
    }
} catch (Exception $e) {
    header("HTTP/1.0 500");
    echo _UNAUTHORIZEDACCESS;
    exit;    
}

?>