<?php
/**
 * Language
 *
 * @date 15.03.2007
 * @name Language
 * @author Margo Poolak <margo 'dot' poolak 'at' mail 'dot' ee>
 * @copyright Copyright &copy;2006 Margo Poolak. All Rights Reserved.
 * @version 2.0
 * @package System.Library
 * @category 
 * 
 * Language handling class
 */
if(!defined('DEFAULT_LANGUAGE'))
{
	define('DEFAULT_LANGUAGE',	'en');
}
class Language
{
	private $_accept_language = array();// accepted languages
	/*
	* Sets accepted language by browser
	*/
	public function __construct()
	{
		$language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
		$strpos = strpos($language,";");
		if($strpos !== false)
		{
			$languages = explode(";",$language);
			$language = $languages[0];
		}
		$this->_accept_language = explode(",",$language);
	}
	/*
	* Checks is that language allowed
	* @returns boolean
	*/
	public function IsAllowed($language)
	{
		if(in_array($language,$this->_accept_language))
		{
			return true;
		}
		return false;
	}
	/*
	* Is the language primary
	* @returns boolean if the language is primary
	*/
	public function IsPrimary($language)
	{
		if(is_array($this->_accept_language) || isset($this->_accept_language[0]))
		{
			return $this->_accept_language[0] == $language;
		}
		return false;
	}
	/*
	* What is the primary language requested
	* @returns string of primary language
	*/
	public function GetPrimaryLanguage()
	{
		if(is_array($this->_accept_language) || isset($this->_accept_language[0]))
		{
			return $this->_accept_language[0] ;
		}
		return DEFAULT_LANGUAGE;
	}
	/*
	* Array accepted language
	* @returns array of accepted languages
	*/
	public function Listing()
	{
		return $this->_accept_language;
	}
}
?>