X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Flang%2Flanguage.php;h=f9b86b17ceaf2bfb84cfb10a54c87b893315dca1;hb=510d6e1925c4d1621ae3efd85e117cc9bb4320f0;hp=876abd1544fd4bf35e79689ed6f3b38ba5019e44;hpb=c2d8171259968d683568f3a5915b541f075fd194;p=fa-stable.git diff --git a/includes/lang/language.php b/includes/lang/language.php index 876abd15..f9b86b17 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,7 +22,8 @@ class language var $encoding; // eg. UTF-8, CP1256, ISO8859-1 var $dir; // Currently support for Left-to-Right (ltr) and // Right-To-Left (rtl) - + var $is_locale_file; + function language($name, $code, $encoding) { $this->name = $name; @@ -26,7 +37,6 @@ class language return "lang/" . $this->code; } - function get_current_language_dir() { $lang = $_SESSION['language']; @@ -35,26 +45,37 @@ class language function set_language($code) { - if (isset($_SESSION['languages'][$code]) && - $_SESSION['language'] != $_SESSION['languages'][$code]) + global $comp_path, $path_to_root; + + $changed = $_SESSION['language']->code != $code; + if (isset($_SESSION['languages'][$code]) && $changed) { - $_SESSION['language'] = $_SESSION['languages'][$code]; - reload_page(""); + // flush cache as we can use several languages in one account + flush_dir($comp_path.'/'.user_company().'/js_cache'); + $_SESSION['language'] = $_SESSION['languages'][$code]; + $locale = $path_to_root . "/lang/" . $_SESSION['language']->code . "/locale.inc"; + // check id file exists only once for session + $_SESSION['language']->is_locale_file = file_exists($locale); } + $lang = $_SESSION['language']; + $_SESSION['get_text']->set_language($lang->code, $lang->encoding); + $_SESSION['get_text']->add_domain($lang->code, $path_to_root . "/lang"); + + // Necessary for ajax calls. Due to bug in php 4.3.10 for this + // version set globally in php.ini + ini_set('default_charset', $lang->encoding); + + if (isset($_SESSION['App']) && $changed) + $_SESSION['App']->init(); // refresh menu } - - 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; + global $installed_languages, $dflt_lang; $_SESSION['languages'] = array(); @@ -67,66 +88,22 @@ class language } if (!isset($_SESSION['language'])) - $_SESSION['language'] = $_SESSION['languages']['en_GB']; + $_SESSION['language'] = $_SESSION['languages'][$dflt_lang]; } -} - -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 php4.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 "