Merged changes in main branch up to v.2.1.2
[fa-stable.git] / includes / lang / language.php
index a47df71d00f0507c88caa242df13c7218ef5ed9d..0727222cd09a6338c3ea56ec0c82977815a0bea3 100644 (file)
@@ -1,6 +1,16 @@
 <?php
-
-if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+// 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");
@@ -27,7 +37,6 @@ class language
                return "lang/" . $this->code;
        }
 
-
        function get_current_language_dir() 
        {
                $lang = $_SESSION['language'];
@@ -37,9 +46,9 @@ class language
        function set_language($code) 
        {
            global $comp_path, $path_to_root;
-           
-               if (isset($_SESSION['languages'][$code]) &&
-                       $_SESSION['language'] != $_SESSION['languages'][$code]) 
+               
+               $changed = $_SESSION['language']->code != $code;
+               if (isset($_SESSION['languages'][$code]) && $changed)
                {
                // flush cache as we can use several languages in one account
                    flush_dir($comp_path.'/'.user_company().'/js_cache');
@@ -47,8 +56,18 @@ class language
                        $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("");
                }
+
+               $lang = $_SESSION['language'];
+               get_text::set_language($lang->code, $lang->encoding);
+               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
        }
 
        /**
@@ -57,7 +76,7 @@ class language
      */
        function load_languages() 
        {
-               global $installed_languages;
+               global $installed_languages, $dflt_lang;
 
                $_SESSION['languages'] = array();
 
@@ -70,7 +89,7 @@ class language
         }
 
                if (!isset($_SESSION['language']))
-                       $_SESSION['language'] = $_SESSION['languages']['en_GB'];
+                       $_SESSION['language'] = $_SESSION['languages'][$dflt_lang];
        }
 
 }
@@ -93,28 +112,11 @@ function has_locale($fun=null)
        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");
-
-// Page Initialisation
-if (!isset($_SESSION['languages'])) 
+function _set($key,$value) 
 {
-       language::load_languages();
+       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) 
@@ -125,30 +127,4 @@ if (!function_exists("_"))
                return $retVal;
        }
 }
-
-function _set($key,$value) 
-{
-       get_text::set_var($key,$value);
-}
-
-function reload_page($msg) 
-{
-//     header("Location: $_SERVER['PHP_SELF']."");
-//     exit;
-       echo "<html>";
-       echo "<head>";
-    echo "<title>Changing Languages</title>";
-       echo '<meta http-equiv="refresh" content="0;url=' . $_SERVER['PHP_SELF'] . '">';
-       echo '</head>';
-       echo '<body>';
-       echo '<div>';
-       if ($msg != "")
-               echo $msg . " " . $_SERVER['PHP_SELF'];
-       echo "</div>";  
-       echo "</body>";
-       echo "</html>";
-}
-
-
-
 ?>
\ No newline at end of file