2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root. "/admin/db/payment_terms_db.inc");
15 Update main or gl company setup.
17 function update_company_prefs($params)
19 begin_transaction(__FUNCTION__, func_get_args());
21 $sql = "UPDATE ".TB_PREF."sys_prefs SET value = ";
22 foreach($params as $name => $value) {
23 if (!db_query($sql. db_escape($value). " WHERE name=".db_escape($name),
24 "The company prefferences could not be updated "))
26 // update cached value
27 $_SESSION['SysPrefs']->prefs[$name] = $value;
34 Get company preferences. Returns cached values from global variable SysPrefs
35 or retrieved from database if SysPrefs values are not set.
36 $prefs can be preference name, array of names, or null for all preferences.
39 function get_company_pref($prefs = null)
41 global $SysPrefs, $db_version;
43 if (!isset($SysPrefs->prefs)) // just after first login or reset
46 $all = $SysPrefs->prefs;
48 if ($prefs && is_string($prefs))
57 function get_company_prefs()
59 return get_company_pref(null);
62 function set_company_pref($pref, $category, $type, $length, $value)
64 begin_transaction(__FUNCTION__, func_get_args());
66 $sql = "REPLACE `".TB_PREF."sys_prefs` SET `name`=".db_escape($pref).", `category`=".db_escape($category)
67 .", `type`=".db_escape($type).", `length`=".db_escape($length).", `value`=".db_escape($value);
68 $result = db_query($sql, "cannot set company pref");
75 function get_base_sales_type()
77 return get_company_pref('base_sales');
80 function get_company_extensions($id = -1) {
83 $file = $path_to_root.($id == -1 ? '' : '/company/'.(int)$id).'/installed_extensions.php';
84 $installed_extensions = array();
88 return $installed_extensions;
91 //---------------------------------------------------------------------------------------------
93 // Resets $theme references in users records to 'default'.
95 function clean_user_themes($theme)
97 global $db_connections, $db;
99 begin_transaction(__FUNCTION__, func_get_args());
101 $comp = user_company();
103 $connections = $db_connections; // do not use db_connections directly here, or script will hang due to db_connections usage inside the loop
104 foreach ($connections as $n => $conn) {
105 $db = $_SESSION["wa_current_user"]->set_db_connection($n);
106 $sql = "UPDATE {$conn['tbpref']}users SET theme='default' WHERE theme='$theme'";
107 if (!db_query($sql, 'Cannot update user theme settings'))
110 $db = $_SESSION["wa_current_user"]->set_db_connection($comp);
111 $_SESSION['wa_current_user']->prefs->theme = 'default';
113 commit_transaction();