PHP7 compatibility fixes.
[fa-stable.git] / includes / prefs / sysprefs.inc
1 <?php
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/company_db.inc");
13
14 /*
15         System and per company prefferences.
16         Object is created only with site wide preffernces.
17         After user login refresh method have to be called to re-initialize company specific settings.
18 */
19 class sys_prefs 
20 {
21         var $prefs;
22         var $db_ok; // check whether database has been upgraded after src update.
23
24         function __construct()
25         {
26                 global $path_to_root;
27
28                 // retrieve set system wide preferences
29                 include $path_to_root.'/config.default.php';
30                 if (file_exists($path_to_root.'/config.php'))
31                         include $path_to_root.'/config.php';
32
33                 foreach(get_defined_vars() as $name => $value)
34                         $this->$name = $value;
35
36                 if (!@$this->time_zone)
37                         $this->time_zone = ini_get('date.timezone');
38
39                 if (!$this->time_zone)
40                         $this->time_zone = 'Europe/Berlin';
41                         
42                 if (!isset($this->use_popup_search))
43                         $this->use_popup_search = false;
44
45             ini_set('date.timezone', $this->time_zone);
46         }
47
48         /*
49                 Re-initialize company preferrencies.
50         */
51         function refresh()
52         {
53                 global $db_version;
54
55                 $sql = "SELECT name, value FROM ".TB_PREF."sys_prefs";
56                 $result = @db_query($sql); // supress errors before 2.3 db structure upgrade
57
58                 if(!$result)
59                         return null;
60
61                 while($pref = db_fetch_assoc($result)) {
62                         $this->prefs[$pref['name']] = $pref['value'];
63                 }
64
65                 // update current db status for info in log file
66                 $this->db_ok = $this->prefs['version_id'] == $db_version;
67         }
68
69         function allow_negative_stock() 
70         {
71                 return $this->prefs['allow_negative_stock'];
72         }
73
74     /* Sherifoz 26.06.03 Proportion by which items can be received over the quantity that is specified in a purchase
75     invoice
76     The figure entered is interpreted as a percentage ie 10 means 0.1 or 10% not 10 times
77     */
78         function over_receive_allowance() 
79         {
80                 return $this->prefs['po_over_receive'];
81         }
82         
83     /* Proportion by which a purchase invoice line is an overcharge for a purchase order item received
84     is an overcharge. If the overcharge is more than this percentage then an error is reported and
85     purchase invoice line cannot be entered
86     The figure entered is interpreted as a percentage ie 20 means 0.2 or 20% not 20 times
87     */  
88         function over_charge_allowance() 
89         {
90                 return $this->prefs['po_over_charge'];
91         }
92         
93         function default_credit_limit() 
94         {
95                 return $this->prefs['default_credit_limit'];
96         }                               
97         
98         function default_wo_required_by() 
99         {
100                 return $this->prefs['default_workorder_required'];
101         }
102
103         function default_quote_valid_days() 
104         {
105                 return $this->prefs['default_quote_valid_days'];
106         }
107
108         function default_delivery_required_by() 
109         {
110                 return $this->prefs['default_delivery_required'];
111         }
112
113         function default_receival_required_by() 
114         {
115                 return $this->prefs['default_receival_required'];
116         }
117
118         function default_dimension_required_by() 
119         {
120                 return $this->prefs['default_dim_required'];
121         }       
122         
123         function auto_currency_revaluation() 
124         {
125                 return $this->prefs['auto_curr_reval'];
126         }       
127         
128         function allocation_settled_allowance()
129         {
130                 return $this->config_allocation_settled_allowance;
131         }
132
133         function no_zero_lines_amount() 
134         {
135                 return $this->prefs['no_zero_lines_amount'];
136         }
137
138         function show_po_item_codes() 
139         {
140                 return $this->prefs['show_po_item_codes'];
141         }
142
143         function accounts_alpha() 
144         {
145                 return $this->prefs['accounts_alpha'];
146         }
147
148         function loc_notification() 
149         {
150                 return $this->prefs['loc_notification'];
151         }
152
153         function print_invoice_no() 
154         {
155                 return $this->prefs['print_invoice_no'];
156         }
157
158         function allow_negative_prices() 
159         {
160                 return $this->prefs['allow_negative_prices'];
161         }
162
163         function print_item_images_on_quote() 
164         {
165                 return $this->prefs['print_item_images_on_quote'];
166         }
167
168         function alternative_tax_include_on_docs() 
169         {
170                 return $this->prefs['alternative_tax_include_on_docs'];
171         }
172
173         function suppress_tax_rates() 
174         {
175                 return $this->prefs['suppress_tax_rates'];
176         }
177
178         function backup_dir($comp=null)
179         {
180                 if (!isset($comp))
181                         $comp = user_company();
182
183                 if (isset($this->backup_path))
184                         return sprintf($this->backup_path, $comp);
185                 else
186                         return $this->comp_path.'/'.$comp."/backup/";
187         }
188 }
189