From: Janusz Dobrowolski Date: Tue, 17 Feb 2015 22:27:06 +0000 (+0100) Subject: Fixed initialization of company specific settings in SysPrefs. X-Git-Tag: v2.4.2~19^2~250 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=33cabd27cc1bb3aaed559ba37691b7b27d45896e Fixed initialization of company specific settings in SysPrefs. --- diff --git a/admin/db/company_db.inc b/admin/db/company_db.inc index a9834360..479f92ac 100644 --- a/admin/db/company_db.inc +++ b/admin/db/company_db.inc @@ -33,28 +33,11 @@ function update_company_prefs($params) function get_company_pref($prefs = null) { global $SysPrefs, $db_version; - - if (!isset($_SESSION['SysPrefs']->prefs)) { // cached preferences - -// $_SESSION['SysPrefs'] = new sys_prefs(); - - $sql = "SELECT name, value FROM ".TB_PREF."sys_prefs"; - $result = @db_query($sql); // supress errors before 2.3 db structure upgrade - if(!$result) - return null; - - while($pref = db_fetch_assoc($result)) { - $_SESSION['SysPrefs']->prefs[$pref['name']] = $pref['value']; - } + if (!isset($SysPrefs->prefs)) // just after first login or reset + $SysPrefs->refresh_company_prefs(); - $SysPrefs = &$_SESSION['SysPrefs']; - - // update current db status for info in log file - $SysPrefs->db_ok = $SysPrefs->prefs['version_id'] == $db_version; - } - - $all = $_SESSION['SysPrefs']->prefs; + $all = $SysPrefs->prefs; if (!$prefs) return $all; @@ -65,7 +48,7 @@ function get_company_pref($prefs = null) foreach($prefs as $name) $ret[$name] = $all[$name]; - return $ret; + return $ret; } function get_company_prefs() @@ -82,10 +65,13 @@ function set_company_pref($pref, $category, $type, $length, $value) function refresh_sys_prefs() { + global $SysPrefs; + // flush_dir(user_js_cache()); // clear cache unset($_SESSION['SysPrefs']); $_SESSION['SysPrefs'] = new sys_prefs(); - get_company_prefs(); + $SysPrefs = &$_SESSION['SysPrefs']; + $SysPrefs->refresh_company_prefs(); } function get_base_sales_type() diff --git a/includes/prefs/sysprefs.inc b/includes/prefs/sysprefs.inc index 0ff68cbd..9a8213c8 100644 --- a/includes/prefs/sysprefs.inc +++ b/includes/prefs/sysprefs.inc @@ -11,6 +11,11 @@ ***********************************************************************/ include_once($path_to_root . "/admin/db/company_db.inc"); +/* + System and per company prefferences. + Object is created only with site wide preffernces. + After user login refresh_company_prefs method have to be called to initialize company specific settings. +*/ class sys_prefs { var $prefs; @@ -18,13 +23,13 @@ class sys_prefs function sys_prefs() { - global $path_to_root; + global $path_to_root, $db_version; + // retrieve set system wide preferences include $path_to_root.'/config.default.php'; if (file_exists($path_to_root.'/config.php')) include $path_to_root.'/config.php'; - // set system wide preferences foreach(get_defined_vars() as $name => $value) $this->$name = $value; @@ -37,6 +42,27 @@ class sys_prefs ini_set('date.timezone', $this->time_zone); } + /* + Initialize company specific preferrencies. + */ + function refresh_company_prefs() + { + global $db_version; + + $sql = "SELECT name, value FROM ".TB_PREF."sys_prefs"; + $result = @db_query($sql); // supress errors before 2.3 db structure upgrade + + if(!$result) + return null; + + while($pref = db_fetch_assoc($result)) { + $this->prefs[$pref['name']] = $pref['value']; + } + + // update current db status for info in log file + $this->db_ok = $this->prefs['version_id'] == $db_version; + } + function allow_negative_stock() { return $this->prefs['allow_negative_stock']; diff --git a/includes/session.inc b/includes/session.inc index d9fd8c30..65bc9929 100644 --- a/includes/session.inc +++ b/includes/session.inc @@ -240,7 +240,7 @@ function check_page_security($page_security) _("Security settings have not been defined for your user account.") . "
" . _("Please contact your system administrator.") : _("Please remove \$security_groups and \$security_headings arrays from config.php file!"); - } elseif (!$_SESSION['SysPrefs']->db_ok && !$_SESSION["wa_current_user"]->can_access('SA_SOFTWAREUPGRADE')) + } elseif (!$SysPrefs->db_ok && !$_SESSION["wa_current_user"]->can_access('SA_SOFTWAREUPGRADE')) { $msg = _('Access to application has been blocked until database upgrade is completed by system administrator.'); } @@ -262,7 +262,7 @@ function check_page_security($page_security) end_page(@$_REQUEST['popup']); exit; } - if (!$_SESSION['SysPrefs']->db_ok + if (!$SysPrefs->db_ok && !in_array($page_security, array('SA_SOFTWAREUPGRADE', 'SA_OPEN', 'SA_BACKUP'))) { display_error(_('System is blocked after source upgrade until database is updated on System/Software Upgrade page')); @@ -380,6 +380,8 @@ foreach ($installed_extensions as $ext) if (file_exists($path_to_root.'/'.$ext['path'].'/hooks.php')) include_once($path_to_root.'/'.$ext['path'].'/hooks.php'); } +$Session_manager = new SessionManager(); +$Session_manager->sessionStart('FA'.md5(dirname(__FILE__))); $_SESSION['SysPrefs'] = new sys_prefs(); @@ -418,9 +420,6 @@ ini_set('session.gc_maxlifetime', 36000); // 10hrs hook_session_start(@$_POST["company_login_name"]); -$Session_manager = new SessionManager(); -$Session_manager->sessionStart('FA'.md5(dirname(__FILE__))); - // this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks header("Cache-control: private"); @@ -554,18 +553,20 @@ if (!defined('FA_LOGOUT_PHP_FILE')){ $lang->set_language($_SESSION['language']->code); } } else - { set_global_connection(); - if (db_fixed()) - db_set_encoding($_SESSION['language']->encoding); - } + { + set_global_connection(); + + if (db_fixed()) + db_set_encoding($_SESSION['language']->encoding); + $SysPrefs->refresh_company_prefs(); + } if (!isset($_SESSION["App"])) { $_SESSION["App"] = new front_accounting(); $_SESSION["App"]->init(); } } - // POST vars cleanup needed for direct reuse. // We quote all values later with db_escape() before db update. $_POST = strip_quotes($_POST); diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index 7a339972..586ca105 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -633,9 +633,9 @@ function handle_cancel_order() function create_cart($type, $trans_no) { - global $Refs; + global $Refs, $SysPrefs; - if (!$_SESSION['SysPrefs']->db_ok) // create_cart is called before page() where the check is done + if (!$SysPrefs->db_ok) // create_cart is called before page() where the check is done return; processing_start();