<?php 
class Session{
	
	public function __construct(){

		if(!isset($_SESSION)){
			session_start(); 
		}
			// pour debugger le déroulemnt des appels de modules
			//echo "Session active est ".session_id()." - Module Session(construct)  at ".microtime(true).' sec'."<br/>"; 
	}
	public function setMessage($message,$type = 'success'){
		$_SESSION['message'] = array(
			'message' => $message,
			'type'	=> $type
		); 
	}

	public function message(){
		if(isset($_SESSION['message']['message'])){
			$html = '<div class="alert-'.$_SESSION['message']['type'].'">'.$_SESSION['message']['message'].'</div>'; 
			$_SESSION['message'] = array(); 
			return $html; 
		}
	}

	public function write($key,$value){
		$_SESSION[$key] = $value;
	}

	public function read($key = null){
		if($key){
			if(isset($_SESSION[$key])){
				return $_SESSION[$key]; 
			}else{
				return false; 
			}
		}else{
			return $_SESSION; 
		}
	}

	public function isLogged(){
		
		return isset($_SESSION['s_adherent']->role);
	}

} // fin de classe