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";
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();
}
$this->logged = true;
$this->last_act = time();
$this->timeout = session_timeout();
+ flush_dir(user_js_cache()); // refresh cache on login
}
}
return $this->logged;
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()
function flush_dir($path, $wipe = false)
{
- $dir = opendir($path);
+ $dir = @opendir($path);
if(!$dir)
return;
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'];
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;
$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));
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) {