X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Flang%2Flanguage.php;h=824a528ca7ee2da58d35a6aef0c6c13f656064a6;hb=16b19d2a0218d206004c9b957344c6cd15835e15;hp=629a15a0c28c176805d8837eb188b47b835eaf3b;hpb=f6e1b649fc75750383b17c2ced6a5c1d6f19fe2e;p=fa-stable.git diff --git a/includes/lang/language.php b/includes/lang/language.php index 629a15a0..824a528c 100644 --- a/includes/lang/language.php +++ b/includes/lang/language.php @@ -1,6 +1,16 @@ . +***********************************************************************/ +// Prevent register_globals vulnerability +if (isset($_GET['path_to_root']) || isset($_POST['path_to_root'])) die("Restricted access"); include_once($path_to_root . "/lang/installed_languages.inc"); include_once($path_to_root . "/includes/lang/gettext.php"); @@ -12,13 +22,16 @@ class language var $encoding; // eg. UTF-8, CP1256, ISO8859-1 var $dir; // Currently support for Left-to-Right (ltr) and // Right-To-Left (rtl) - - function language($name, $code, $encoding) + var $is_locale_file; + + function language($name, $code, $encoding, $dir = 'ltr') { + global $dflt_lang; + $this->name = $name; - $this->code = $code; + $this->code = $code ? $code : ($dflt_lang ? $dflt_lang : 'en_GB'); $this->encoding = $encoding; - $this->dir = "ltr"; + $this->dir = $dir; } function get_language_dir() @@ -26,7 +39,6 @@ class language return "lang/" . $this->code; } - function get_current_language_dir() { $lang = $_SESSION['language']; @@ -35,103 +47,49 @@ class language function set_language($code) { - global $comp_path; - - if (isset($_SESSION['languages'][$code]) && - $_SESSION['language'] != $_SESSION['languages'][$code]) + global $comp_path, $path_to_root, $installed_languages; + + $changed = $this->code != $code; + $lang = array_search_value($code, $installed_languages, 'code'); + + if ($lang && $changed) { - // flush cache as we can use several languages in one account - flush_dir($comp_path.'/'.user_company().'/js_cache'); - $_SESSION['language'] = $_SESSION['languages'][$code]; - reload_page(""); + flush_dir($comp_path.'/'.user_company().'/js_cache'); + + $this->name = $lang['name']; + $this->code = $lang['code']; + $this->encoding = $lang['encoding']; + $this->dir = isset($lang['rtl']) ? 'rtl' : 'ltr'; + $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc"; + $this->is_locale_file = file_exists($locale); } - } - function get_stylesheet() - { - return 'lang/' . $_SESSION['language']->code . '/stylesheet.css'; - } - - /** - * This method loads an array of language objects into a session variable - * called $_SESSIONS['languages']. Only supported languages are added. - */ - function load_languages() - { - global $installed_languages; + $_SESSION['get_text']->set_language($this->code, $this->encoding); + $_SESSION['get_text']->add_domain($this->code, $path_to_root . "/lang"); - $_SESSION['languages'] = array(); + // Necessary for ajax calls. Due to bug in php 4.3.10 for this + // version set globally in php.ini + ini_set('default_charset', $this->encoding); - foreach ($installed_languages as $lang) - { - $l = new language($lang['name'],$lang['code'],$lang['encoding']); - if (isset($lang['rtl'])) - $l->dir = "rtl"; - $_SESSION['languages'][$l->code] = $l; - } - - if (!isset($_SESSION['language'])) - $_SESSION['language'] = $_SESSION['languages']['en_GB']; + if (isset($_SESSION['App']) && $changed) + $_SESSION['App']->init(); // refresh menu } - } -session_start(); -// this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks -header("Cache-control: private"); - -// Page Initialisation -if (!isset($_SESSION['languages'])) +function _set($key,$value) { - language::load_languages(); + $_SESSION['get_text']->set_var($key,$value); } -$lang = $_SESSION['language']; - -// get_text support -get_text::init(); -get_text::set_language($lang->code, $lang->encoding); -//get_text::add_domain("wa", $path_to_root . "/lang"); -get_text::add_domain($lang->code, $path_to_root . "/lang"); -// Unnecessary for ajax calls. -// Due to bug in php 4.3.10 for this version set globally in php.ini -ini_set('default_charset', $_SESSION['language']->encoding); - if (!function_exists("_")) { function _($text) { - $retVal = get_text::gettext($text); + $retVal = $_SESSION['get_text']->gettext($text); if ($retVal == "") return $text; return $retVal; } } - -function _set($key,$value) -{ - get_text::set_var($key,$value); -} - -function reload_page($msg) -{ -// header("Location: $_SERVER['PHP_SELF'].""); -// exit; - echo ""; - echo "
"; - echo "