<?php

class session
{
    public static function createSession(array $_array, string $_type = "user")
    {
        $_SESSION[$_type] = $_array;
    }

    public static function getId(string $_type = "user")
    {
        return $_SESSION[$_type]["id"];
    }

    public static function getValue(string $_val, string $_type = "user")
    {
        return $_SESSION[$_type][$_val];
    }

    public static function getName(string $_type = "user")
    {
        return $_SESSION[$_type]["prenom"] . " " . $_SESSION[$_type]["nom"];
    }

    public static function getType(string $_type = "user")
    {
        return $_SESSION[$_type]["idType"];
    }

    public static function isConnect(string $_type = "user")
    {
        return (isset($_SESSION[$_type]["id"])) ? TRUE : FALSE;
    }

    public static function access(array $_type){
        return (in_array($_SESSION["user"]["idType"], $_type)) ? TRUE : FALSE;
    }

    public static function isEspaceControleurs(){
        return ($_SERVER['HTTP_HOST'] == DOMAIN_CONTROL) ? TRUE : FALSE;
    }

    public static function isEspaceSalaries(){
        return ($_SERVER['HTTP_HOST'] == DOMAIN_EVENTS) ? TRUE : FALSE;
    }

    public static function setTemp(array $_array, string $_name = NULL){
        if($_name == NULL){
            $_SESSION["TEMP"]["tmp"] = $_array;
        } else {
            $_SESSION["TEMP"][$_name] = $_array;
        }
    }

    public static function getTemp(string $_name = NULL){
        if(empty($_SESSION["TEMP"])){ 
            return NULL; 
        } elseif($_name == NULL){
            $return = $_SESSION["TEMP"]["tmp"];
        } else {
            $return = $_SESSION["TEMP"][$_name];
        }
        self::resetTemp();
        return $return;
    }

    public static function resetTemp(string $_name = NULL){
        unset($_SESSION["TEMP"]);
    }

}
