<?

/**
* set $_SESSION['language'] parameters
*/
class defineLanguage{

	function setLanguage(){

		/*
		* LANGUAGE
		*/
		if(preg_match('/\?language=/i', $_SERVER['REQUEST_URI']) || preg_match('/\&language=/i', $_SERVER['REQUEST_URI'])){

			preg_match('/language=([a-zA-Z0-9\__]+)/se', $_SERVER['REQUEST_URI'], $match);
			$language = $match[1];
			if(strlen($language) <= 10){

				$_SESSION['language'] = $language;

				$qstr = str_replace('request=', '', $_SERVER['QUERY_STRING']);
				$qstr = str_replace('language='.$language, '', $qstr);
				$qstr = str_replace('/&', '/?', $qstr);
				if(preg_match('/\/\?/i', $qstr))
					die(header('Location:'._RootUrl.$qstr));
				else
					die(header('Location:'._RootUrl.'/'));
			}
		}

		if( !$_SESSION['language'] ){

			$_SESSION['language'] = _defaultLanguage;
		}
		if( $_GET['language'] ){

			$_SESSION['language'] = $_GET['language'];
		}
		if( $_POST['language'] ){

			$_SESSION['language'] = $_POST['language'];
		}
		if(strlen($_SESSION['language']) != 3){

			$_SESSION['language'] = _defaultLanguage;
		}
		define('_language_short_keys', json_encode(array('est' => 'et', 'eng' => 'en', 'fin' => 'fi', 'rus' => 'ru')));
	}
}

?>