<?php
if(!defined('CTRL'))
{
	exit("Loading stopped...missing Ctrl.php");
}
/**
 * CtrlUser
 *
 * @date 15.03.2007
 * @name CtrlModule
 * @author Margo Poolak <margo 'dot' poolak 'at' mail 'dot' ee>
 * @copyright Copyright &copy;2006 Margo Poolak. All Rights Reserved.
 * @version 2.0
 * @package System
 * @category 
 * 
 * This class uses session to remember the user logged in and its language, admin and owner status
 */
class CtrlUser extends CtrlModule
{
	/**
	* Set user as logged in
	* @param string username
	* @param string password
	*/
	public function login($username,$password='')
	{
		$this->Session->set('username',$username);
	}
	/**
	* Sets user role
	* @param string role
	*/	
	public function setRole($role)
	{
		$this->Session->set('role',$role);
	}
	/**
	* Returns user role
	* @return string role
	*/
	public function getRole()
	{
		$role = $this->Session->get('role');
		if(isset($role))
		{
			return $role;
		}
		else
		{
			return USER;
		}
	}
	/**
	* Sets user id
	*/
	public function setDomain($id)
	{
		$this->Session->set('domain',$id);
	}
	/**
	* Returns user id
	*/
	public function getDomain()
	{
		return $this->Session->get('domain');
	}	
	/**
	* Sets user id
	*/
	public function setID($id)
	{
		$this->Session->set('userid',$id);
	}
	/**
	* Returns user id
	*/
	public function getID()
	{
		return $this->Session->get('userid');
	}
	/*
	* Returns logged in username
	*@returns string
	*/
	public function getUsername()
	{
		return $this->Session->get('username');
	}
	/*
	* If username exists then the user is logged in
	*/
	public function isAuthenticated()
	{
		$auth = $this->Session->get('username');
		if(!!($auth))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	/*
	* Unsets the session variables
	*/
	public function logout()
	{
		$this->Session->destroy();
	}
}
?>