Fixed language file switching on package version change.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 25 Jul 2010 09:22:42 +0000 (09:22 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 25 Jul 2010 09:22:42 +0000 (09:22 +0000)
admin/db/company_db.inc
includes/current_user.inc
includes/lang/language.php
includes/session.inc

index b39884548a193016e2efeae2e486969c1d83f99b..521851386c458b319ba848dea8ecfd06e8486f6b 100644 (file)
@@ -30,7 +30,7 @@ function update_company_prefs( $params, $pref = TB_PREF )
        $prefs can be preference name, array of names, or null for all preferences.
        
 */
-function get_company_pref($prefs = null, $tbpref = TB_PREF)
+function get_company_pref($prefs = null, $tbpref = null)
 {
        global $SysPrefs, $core_version;
        
@@ -38,6 +38,9 @@ function get_company_pref($prefs = null, $tbpref = TB_PREF)
 
                $_SESSION['SysPrefs'] = new sys_prefs();
 
+               if (!isset($tbpref))
+                       $tbpref = TB_PREF;
+
                $sql = "SELECT name, value FROM {$tbpref}sys_prefs";
                $result = @db_query($sql); // supress errors before 2.3 db structure upgrade
 
index 571779925f73e168c480498deea62b49b90d5ae9..a7a35303fc73aea76e4375991e87473220a268f4 100644 (file)
@@ -281,7 +281,9 @@ function user_numeric($input) {
 
 function user_company()
 {
-       return $_SESSION["wa_current_user"]->company;
+       global $def_coy;
+       
+       return isset($_SESSION["wa_current_user"]) ? $_SESSION["wa_current_user"]->company : $def_coy;
 }
 
 function user_pos()
@@ -499,4 +501,33 @@ function array_search_key($needle, $haystack, $valuekey=null)
        $keys = array_search_keys($needle, $haystack, $valuekey);
        return @$keys[0];
 }
+
+function flush_dir($path, $wipe = false) 
+{
+       $dir = opendir($path);
+       while(false !== ($fname = readdir($dir))) {
+               if($fname=='.' || $fname=='..' || $fname=='CVS' || (!$wipe && $fname=='index.php')) continue;
+               if(is_dir($path.'/'.$fname)) {
+                   flush_dir($path.'/'.$fname, $wipe);
+                   if ($wipe) @rmdir($path.'/'.$fname);
+               } else
+                   @unlink($path.'/'.$fname);
+       }
+}
+/*
+       Returns current path to company private folder.
+       (Current path can change after chdir).
+*/
+function company_path($comp=null)
+{
+       global $path_to_root, $comp_path;
+
+       if (!isset($comp))
+               $comp = user_company();
+
+       // if path is relative, set current path_to_root
+       return ($comp_path[0]=='.' ? $path_to_root.'/'.basename($comp_path) : $comp_path)
+                       . '/'.$comp;
+}
+
 ?>
\ No newline at end of file
index 54302ebe5a1fe887ff1359a3ae51a633d865fbfb..f6a09ded5243ad9bff4f52276862271b52d43fc3 100644 (file)
@@ -50,8 +50,8 @@ class language
        {
            global $path_to_root, $installed_languages;
 
-               $changed = $this->code != $code;
                $lang = array_search_value($code, $installed_languages, 'code');
+               $changed = $this->code != $code || $this->version != $lang['version'];
 
                if ($lang && $changed)
                {
index 54de6a15f44d613cb326ef02b9a53d8aff81dd18..4a6b083a8e1cae90787c14cc5aebd00a8823be73 100644 (file)
@@ -180,6 +180,7 @@ session_start();
 // this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks
 header("Cache-control: private");
 
+include_once($path_to_root . "/config.php");
 get_text_init();
 
 // Page Initialisation
@@ -200,7 +201,6 @@ if (file_exists($path_to_root . "/lang/".$_SESSION['language']->code."/locale.in
 }
 
 include_once($path_to_root . "/includes/access_levels.inc");
-include_once($path_to_root . "/config.php");
 include_once($path_to_root . "/version.php");
 include_once($path_to_root . "/includes/main.inc");