<?php
class UserHelper extends Controller{
	
	
	
	public function check_user_login()
	{
		if(FALSE !== $this->loadSession()->hasSession("login") && FALSE !== $this->loadSession()->hasSession("user_id") && FALSE !== $this->loadSession()->hasSession("job_type") && FALSE !== $this->loadSession()->hasSession("admin_type") && $_SESSION['job_type'] == 1 && $_SESSION['admin_type'] == 1)                                                  
		{
			return TRUE;
		}else{
			return FALSE;
		}
		
	}
	
    public function get_user_lang()
	{
		if(isset($_SESSION['login'],$_SESSION['job_type'],$_SESSION['user_id']) && $_SESSION['login'] == TRUE)
		{
			// get user id from session
			$user_id = $this->loadSession()->getSession("user_id");
			// get user data for header
			$dataView['userData'] = $this->loadModel("UserModel")->retriveDataById("id",$user_id);
			if($dataView['userData'] == NULL)
			{
				$this->redirect("error","index");
				exit();
			}
			
			$this->loadSession(array("lang"=>$dataView['userData']['user_language']))->setSession();
			return TRUE;
		}else if(isset($_SESSION['lang'])){
			$this->loadSession(array("lang"=>$_SESSION['lang']))->setSession();
			return TRUE;
		}
		$this->loadSession(array("lang"=>"en"))->setSession();
		return TRUE;
	}
	
}
?>