From 99c698c6fca8ef2fd7933eac66f9b7fbf24f45d7 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Sun, 22 Mar 2015 11:20:11 +0100 Subject: [PATCH] Added missing company settings to upgrade script, fixed company settings refreshing method. --- admin/backups.php | 2 +- admin/company_preferences.php | 14 --------- admin/db/company_db.inc | 13 +------- admin/gl_setup.php | 49 ------------------------------- admin/includes/fa_patch.class.inc | 4 ++- includes/db/connect_db_mysql.inc | 3 +- includes/db/connect_db_mysqli.inc | 4 +-- includes/prefs/sysprefs.inc | 8 ++--- includes/session.inc | 2 +- sql/alter2.4.sql | 14 +++++++++ 10 files changed, 28 insertions(+), 85 deletions(-) diff --git a/admin/backups.php b/admin/backups.php index 1168b4f2..0c039dea 100644 --- a/admin/backups.php +++ b/admin/backups.php @@ -140,7 +140,7 @@ if (get_post('restore')) { if ($backup_name) { if (db_import($backup_path, $conn)) display_notification(_("Restore backup completed.")); - refresh_sys_prefs(); // re-read system setup + $SysPrefs->refesh(); // re-read system setup } else display_error(_("Select backup file first.")); } diff --git a/admin/company_preferences.php b/admin/company_preferences.php index b889aeb9..186d06bf 100644 --- a/admin/company_preferences.php +++ b/admin/company_preferences.php @@ -117,20 +117,6 @@ if (isset($_POST['update']) && $_POST['update'] != "") $Ajax->activate('_page_body'); } /* end of if submit */ -//--------------------------------------------------------------------------------------------- -if (get_company_pref('bcc_email') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations - set_company_pref('bcc_email', 'setup.company', 'varchar', 100, ''); - refresh_sys_prefs(); -} -if (get_company_pref('alternative_tax_include_on_docs') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations - set_company_pref('alternative_tax_include_on_docs', 'setup.company', 'tinyint', 1, '0'); - refresh_sys_prefs(); -} -if (get_company_pref('suppress_tax_rates') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations - set_company_pref('suppress_tax_rates', 'setup.company', 'tinyint', 1, '0'); - refresh_sys_prefs(); -} - start_form(true); $myrow = get_company_prefs(); diff --git a/admin/db/company_db.inc b/admin/db/company_db.inc index 479f92ac..447307b8 100644 --- a/admin/db/company_db.inc +++ b/admin/db/company_db.inc @@ -35,7 +35,7 @@ function get_company_pref($prefs = null) global $SysPrefs, $db_version; if (!isset($SysPrefs->prefs)) // just after first login or reset - $SysPrefs->refresh_company_prefs(); + $SysPrefs->refresh(); $all = $SysPrefs->prefs; @@ -63,17 +63,6 @@ function set_company_pref($pref, $category, $type, $length, $value) return db_query($sql, "cannot set company pref"); } -function refresh_sys_prefs() -{ - global $SysPrefs; - -// flush_dir(user_js_cache()); // clear cache - unset($_SESSION['SysPrefs']); - $_SESSION['SysPrefs'] = new sys_prefs(); - $SysPrefs = &$_SESSION['SysPrefs']; - $SysPrefs->refresh_company_prefs(); -} - function get_base_sales_type() { return get_company_pref('base_sales'); diff --git a/admin/gl_setup.php b/admin/gl_setup.php index cb53aba9..3836493b 100644 --- a/admin/gl_setup.php +++ b/admin/gl_setup.php @@ -94,55 +94,6 @@ start_outer_table(TABLESTYLE2); table_section(1); -if (get_company_pref('grn_clearing_act') === null) { // available from 2.3.1, can be not defined on pre-2.4 installations - set_company_pref('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0); - refresh_sys_prefs(); -} -if (get_company_pref('default_receival_required') === null) { // new in 2.4 installations - set_company_pref('default_receival_required', 'glsetup.purchase', 'smallint', 6, '10'); - refresh_sys_prefs(); -} - -if (get_company_pref('default_quote_valid_days') === null) { // available from 2.3.23, can be not defined on pre-2.4 installations - set_company_pref('default_quote_valid_days', 'glsetup.sales', 'smallint', 6, 30); - refresh_sys_prefs(); -} - -if (get_company_pref('no_zero_lines_amount') === null) { // new in 2.4 installations - set_company_pref('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1'); - refresh_sys_prefs(); -} - -if (get_company_pref('show_po_item_codes') === null) { // new in 2.4 installations - set_company_pref('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0'); - refresh_sys_prefs(); -} - -if (get_company_pref('accounts_alpha') === null) { // new in 2.4 installations - set_company_pref('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0'); - refresh_sys_prefs(); -} - -if (get_company_pref('loc_notification') === null) { // new in 2.4 installations - set_company_pref('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0'); - refresh_sys_prefs(); -} - -if (get_company_pref('print_invoice_no') === null) { // new in 2.4 installations - set_company_pref('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0'); - refresh_sys_prefs(); -} - -if (get_company_pref('allow_negative_prices') === null) { // new in 2.4 installations - set_company_pref('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1'); - refresh_sys_prefs(); -} - -if (get_company_pref('print_item_images_on_quote') === null) { // new in 2.4 installations - set_company_pref('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0'); - refresh_sys_prefs(); -} - $myrow = get_company_prefs(); $_POST['retained_earnings_act'] = $myrow["retained_earnings_act"]; diff --git a/admin/includes/fa_patch.class.inc b/admin/includes/fa_patch.class.inc index 631df820..880e24b9 100644 --- a/admin/includes/fa_patch.class.inc +++ b/admin/includes/fa_patch.class.inc @@ -207,6 +207,8 @@ class fa_patch { */ function get_site_status($connections) { + global $SysPrefs; + $info = array(); foreach($connections as $i => $conn) @@ -221,7 +223,7 @@ function get_site_status($connections) } } set_global_connection(); - refresh_sys_prefs(); + $SysPrefs->refresh(); return $info; } diff --git a/includes/db/connect_db_mysql.inc b/includes/db/connect_db_mysql.inc index 622745ce..f6417e45 100644 --- a/includes/db/connect_db_mysql.inc +++ b/includes/db/connect_db_mysql.inc @@ -14,7 +14,7 @@ define('SQL_MODE', ''); // STRICT_ALL_TABLES,NO_ZERO_IN_DATE ? function set_global_connection($company=-1) { - global $db, $path_to_root, $db_connections; + global $db, $path_to_root, $db_connections, $SysPrefs; include ($path_to_root . "/config_db.php"); if ($company == -1) @@ -35,6 +35,7 @@ function set_global_connection($company=-1) ///// We are, however, investigating the existing code to be compatible in the future. db_query("SET sql_mode = '".SQL_MODE."'"); ///// + $SysPrefs->refresh(); return $db; } diff --git a/includes/db/connect_db_mysqli.inc b/includes/db/connect_db_mysqli.inc index 65b4a339..0654c460 100644 --- a/includes/db/connect_db_mysqli.inc +++ b/includes/db/connect_db_mysqli.inc @@ -16,7 +16,7 @@ $db_last_inserted_id = 0; function set_global_connection($company=-1) { - global $db, $path_to_root, $db_connections; + global $db, $path_to_root, $db_connections, $SysPrefs; include ($path_to_root . "/config_db.php"); if ($company == -1) @@ -37,7 +37,7 @@ function set_global_connection($company=-1) ///// We are, however, investigating the existing code to be compatible in the future. db_query("SET sql_mode = '".SQL_MODE."'"); ///// - refresh_sys_prefs(); + $SysPrefs->refresh(); return $db; } diff --git a/includes/prefs/sysprefs.inc b/includes/prefs/sysprefs.inc index 9a8213c8..cade4c2d 100644 --- a/includes/prefs/sysprefs.inc +++ b/includes/prefs/sysprefs.inc @@ -14,7 +14,7 @@ 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. + After user login refresh method have to be called to re-initialize company specific settings. */ class sys_prefs { @@ -23,7 +23,7 @@ class sys_prefs function sys_prefs() { - global $path_to_root, $db_version; + global $path_to_root; // retrieve set system wide preferences include $path_to_root.'/config.default.php'; @@ -43,9 +43,9 @@ class sys_prefs } /* - Initialize company specific preferrencies. + Re-initialize company preferrencies. */ - function refresh_company_prefs() + function refresh() { global $db_version; diff --git a/includes/session.inc b/includes/session.inc index 65bc9929..d8a82f8b 100644 --- a/includes/session.inc +++ b/includes/session.inc @@ -559,7 +559,7 @@ if (!defined('FA_LOGOUT_PHP_FILE')){ if (db_fixed()) db_set_encoding($_SESSION['language']->encoding); - $SysPrefs->refresh_company_prefs(); + $SysPrefs->refresh(); } if (!isset($_SESSION["App"])) { $_SESSION["App"] = new front_accounting(); diff --git a/sql/alter2.4.sql b/sql/alter2.4.sql index e2bf6278..b2546519 100644 --- a/sql/alter2.4.sql +++ b/sql/alter2.4.sql @@ -208,3 +208,17 @@ UPDATE `0_trans_tax_details` reg SET reg.reg_type=0 WHERE reg.trans_type IN(10, 11); +INSERT IGNORE INTO `0_sys_prefs` VALUES + ('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0), + ('default_receival_required', 'glsetup.purchase', 'smallint', 6, '10'), + ('default_quote_valid_days', 'glsetup.sales', 'smallint', 6, 30), + ('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1'), + ('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0'), + ('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0'), + ('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0'), + ('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0'), + ('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1'), + ('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0'), + ('bcc_email', 'setup.company', 'varchar', 100, ''), + ('alternative_tax_include_on_docs', 'setup.company', 'tinyint', 1, '0'), + ('suppress_tax_rates', 'setup.company', 'tinyint', 1, '0'); -- 2.30.2