X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Flang%2Flanguage.php;h=aeb50e0ceffae7d60dd8daab3070402361a3b03b;hb=402235dd9bb7b00d0a560e70fd9ea96efdce8575;hp=bd7e2082d4d2e29f68d202e6d109f5b9133f5692;hpb=878f4303c7f8759f2e7d1f742e43c175a664ede2;p=fa-stable.git diff --git a/includes/lang/language.php b/includes/lang/language.php index bd7e2082..aeb50e0c 100644 --- a/includes/lang/language.php +++ b/includes/lang/language.php @@ -1,5 +1,14 @@ . +***********************************************************************/ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root'])) die("Restricted access"); include_once($path_to_root . "/lang/installed_languages.inc"); @@ -12,7 +21,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; @@ -35,19 +45,21 @@ class language function set_language($code) { + global $comp_path, $path_to_root; + if (isset($_SESSION['languages'][$code]) && $_SESSION['language'] != $_SESSION['languages'][$code]) { - $_SESSION['language'] = $_SESSION['languages'][$code]; - redirect(""); + // 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); + reload_page(""); } } - 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. @@ -71,7 +83,26 @@ class language } } +/* + Test if named function is defined in locale.inc file. +*/ +function has_locale($fun=null) +{ + global $path_to_root; + + if ($_SESSION['language']->is_locale_file) + { + global $path_to_root; + include_once($path_to_root . "/lang/" . + $_SESSION['language']->code . "/locale.inc"); + + if (!isset($fun) || function_exists($fun)) + return true; + } + return false; +} +session_name('FrontAccounting'.user_company()); session_start(); // this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks header("Cache-control: private"); @@ -89,6 +120,9 @@ 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("_")) { @@ -106,8 +140,9 @@ function _set($key,$value) get_text::set_var($key,$value); } -function redirect($msg) +function reload_page($msg) { + global $Ajax; // header("Location: $_SERVER['PHP_SELF'].""); // exit; echo ""; @@ -122,6 +157,7 @@ function redirect($msg) echo ""; echo ""; echo ""; + $Ajax->redirect($_SERVER['PHP_SELF']); }