Fixed display issues when different settings were used for various app users (javascr...
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 25 Dec 2014 17:31:05 +0000 (18:31 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 28 Dec 2014 18:27:34 +0000 (19:27 +0100)
access/login.php
admin/db/company_db.inc
includes/current_user.inc
includes/lang/language.php
includes/main.inc
includes/page/header.inc
includes/ui/ui_view.inc

index 45294376db2c38bfc262a99fac70dd554ab62cf2..b2bad446a0ae408754c1c3f1005c6836b3bb596e 100644 (file)
@@ -43,6 +43,7 @@ function defaultCompany()
                document.getElementById('log_msg').innerHTML='$demo_text'}, 1000*$login_delay);</script>";
            $demo_text = $blocked_msg;
        }
+       flush_dir(user_js_cache());
        if (!isset($def_coy))
                $def_coy = 0;
        $def_theme = "default";
index 9fd2e68c27adf2931ce65aeb9bb01586bd801526..d0f85e4006e6095aa658c1830438c9f45d703527 100644 (file)
@@ -82,7 +82,7 @@ function set_company_pref($pref, $category, $type, $length, $value)
 
 function refresh_sys_prefs()
 {
-       flush_dir(company_path().'/js_cache'); // clear cache
+       flush_dir(user_js_cache()); // clear cache
        unset($_SESSION['SysPrefs']);
        get_company_prefs();
 }
index 26b288a1e884463a22dd677521f04f205c041a25..eea6d1b9d5a423e98c49aa941bcbedbed7f5498e 100644 (file)
@@ -136,6 +136,7 @@ class current_user
                        $this->logged = true;
                                $this->last_act = time();
                                $this->timeout = session_timeout();
+                               flush_dir(user_js_cache()); // refresh cache on login
                        }
                }
                return $this->logged;
@@ -598,6 +599,18 @@ function add_user_js_data() {
   add_js_source($js);
 }
 
+function user_js_cache($id=null)
+{
+       global $path_to_root;
+
+       if (!$id)
+               $id = @$_SESSION['wa_current_user']->user;
+
+       if (!$id)
+               $id = 0; // before login
+       return $path_to_root.'/company/'.user_company().'/js_cache/'.$id;
+}
+
 //--------------------------------------------------------------------------
 
 function session_timeout()
@@ -688,7 +701,7 @@ function recalculate_cols(&$cols)
 
 function flush_dir($path, $wipe = false) 
 {
-       $dir = opendir($path);
+       $dir = @opendir($path);
        if(!$dir)
                return;
 
index c090f1fc1e3d4b18903e0abe89a5d23671da8980..752c7e44c85fce1d4316b35046677d238cc0fcc9 100644 (file)
@@ -55,9 +55,6 @@ class language
 
                if ($lang && $changed)
                {
-               // flush cache as we can use several languages in one account
-                       flush_dir(company_path().'/js_cache');
-
                        $this->name = $lang['name'];
                        $this->code = $lang['code'];
                        $this->encoding = $lang['encoding'];
index 8ef038ca1f06e63e39959c250889781cebee05f1..018fb2b0cdc9b0869d2418969b231d838518563c 100644 (file)
@@ -69,13 +69,34 @@ function cache_js_file($fpath, $text)
 
        if(!$go_debug) $text = js_compress($text);
 
-        $file = fopen($fpath, 'w');
+    $file = force_open($fpath);
        if (!$file) return false;
        if (!fwrite($file, $text)) return false;
        return fclose($file);
 
 }
 
+/*
+       Open file for writing with creration of subfolders if needed.
+*/
+function force_open($fname)
+{
+       $file = pathinfo($fname);
+
+       $path = $fname[0] == '/' ? '/' : '';
+       $tree = explode('/', $file['dirname']);
+       foreach($tree as $level) {
+               $path .= $level;
+               if (!file_exists($path)) {
+                       if (!mkdir($path)) {
+                               return null;
+                       }
+               }
+               $path .= '/';
+       }
+       return fopen($fname, 'w');
+}
+
 function add_js_file($filename) 
 {
          global $js_static;
index 0ae62638bf7570f688d1f7b85585b9060f07f602..61c155855b3f21953b69108df06ebe09ff5ef490 100644 (file)
@@ -52,7 +52,8 @@ function send_scripts()
        $js ='';
        foreach($js_static as $jsfile)
        {
-           $fpath = company_path().'/js_cache/'.$jsfile;
+               $cached_name = basename($jsfile);
+               $fpath = user_js_cache().'/'.$cached_name;
            // compress also static files
                if (!file_exists($fpath) || $go_debug)
                        cache_js_file($fpath, file_get_contents($js_path.$jsfile));
index 8c8bae8db127b0e5982b3b46c392593debad1336..768447bca9083fce1d48698a0ff4808be494762e 100644 (file)
@@ -889,7 +889,7 @@ function reset_focus()
 function get_js_date_picker()
 {
     global $go_debug;
-    $fpath = company_path().'/js_cache/'.'date_picker.js';
+    $fpath = user_js_cache().'/'.'date_picker.js';
 
     if (!file_exists($fpath) || $go_debug) {