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;
foreach($prefs as $name)
$ret[$name] = $all[$name];
- return $ret;
+ return $ret;
}
function get_company_prefs()
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()
***********************************************************************/
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;
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;
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'];
_("Security settings have not been defined for your user account.")
. "<br>" . _("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.');
}
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'));
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();
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");
$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);
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();