<?php
require_once($global['root-model']."Crud.php");
$obj_crud = new Crud();

require_once($global['root-model']."Admin.php");
$obj_user = new Admin();

if($obj_user->admin_check_login() == 0){
	if(isset($_COOKIE['mailTnp'])) {
		$O_email = $_COOKIE['mailTnp'];
		$O_password = $_COOKIE['passTnp'];
		$enc_pass = encrypt_key($O_password);
        $result = $obj_user->login($obj_crud, $O_email, $enc_pass);
        if($result == 1){
            //nothing
        } else {
        	header("Location:{$path['login']}?notLogin");
        }
    } else {
    	header("Location:{$path['login']}?notLogin");
	}
}


if(isset($_GET['action']) && $_GET['action'] == 'logout'){
    if($obj_user->admin_logout()){
    	if(isset($_COOKIE['mailTnp'])) {
    		setcookie("mailTnp", "", time() - 3600);
    		setcookie("passTnp", "", time() - 3600);
    	}
		header("Location:{$path['login']}?logout");
    }
}
?>