Recurrent Invoices: fixed buggy call to non existing function and payment terms type...
[fa-stable.git] / includes / access_levels.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 /*
13         Security sections groups various areas on both functionality and privilege levels.
14         Often analytic inquires are available only for management, and configuration
15         for administration or management staff. This is why we have those three
16         section type inside near every FA module.
17
18         Section codes 0-99 are reserved for core FA functionalities.
19         Every security section can contain up to 256 different areas.
20         External modules can extend security roles system by adding rows to 
21         $security_sections and $security_areas using section codes >=100.
22         Security areas and sections created by extension modules/plugins
23         have dynamically assigned 3-byte integer codes. The highest byte is zero
24         for sections/areas defined in this file, and extid+1 for those defined 
25         by extensions 
26 */
27 define('SS_SADMIN',     1<<8);  // site admin
28 define('SS_SETUP',      2<<8);  // company level setup
29 define('SS_SPEC',       3<<8);  // special administration
30
31 define('SS_SALES_C',11<<8); // configuration
32 define('SS_SALES',      12<<8); // transactions
33 define('SS_SALES_A',13<<8); // analytic functions/reports/inquires
34
35 define('SS_PURCH_C',21<<8);
36 define('SS_PURCH',      22<<8);
37 define('SS_PURCH_A',23<<8);
38
39 define('SS_ITEMS_C',31<<8);
40 define('SS_ITEMS',      32<<8);
41 define('SS_ITEMS_A',33<<8);
42
43 define('SS_ASSETS_C',36<<8);
44 define('SS_ASSETS',     37<<8);
45 define('SS_ASSETS_A',38<<8);
46
47 define('SS_MANUF_C',41<<8);
48 define('SS_MANUF',      42<<8);
49 define('SS_MANUF_A',43<<8);
50
51 define('SS_DIM_C',      51<<8);
52 define('SS_DIM',        52<<8);
53 define('SS_DIM_A',      53<<8);
54
55 define('SS_GL_C',       61<<8);
56 define('SS_GL',         62<<8);
57 define('SS_GL_A',       63<<8);
58
59 $security_sections = array(
60         SS_SADMIN => _("System administration"),
61         SS_SETUP => _("Company setup"),
62         SS_SPEC => _("Special maintenance"),
63         SS_SALES_C => _("Sales configuration"),
64         SS_SALES => _("Sales transactions"),
65         SS_SALES_A => _("Sales related reports"),
66         SS_PURCH_C => _("Purchase configuration"),
67         SS_PURCH => _("Purchase transactions"),
68         SS_PURCH_A => _("Purchase analytics"),
69         SS_ITEMS_C => _("Inventory configuration"),
70         SS_ITEMS => _("Inventory operations"),
71         SS_ITEMS_A => _("Inventory analytics"),
72         SS_ASSETS_C => _("Fixed Assets configuration"),
73         SS_ASSETS => _("Fixed Assets operations"),
74         SS_ASSETS_A => _("Fixed Assets analytics"),
75         SS_MANUF_C => _("Manufacturing configuration"),
76         SS_MANUF => _("Manufacturing transactions"),
77         SS_MANUF_A => _("Manufacturing analytics"),
78         SS_DIM_C => _("Dimensions configuration"),
79         SS_DIM => _("Dimensions"),
80         SS_GL_C => _("Banking & GL configuration"),
81         SS_GL => _("Banking & GL transactions"),
82         SS_GL_A => _("Banking & GL analytics")
83 );
84
85 /*
86         This table stores security areas available in FA. 
87         Key is area identifier used to check user rights, values are
88         codes stored for each role in security_roles table and description used
89         in roles editor.
90
91         Set of allowed access areas codes is retrieved during user login from
92         security_roles table, and cached in user profile.
93
94         Special value 'SA_OPEN' is used for publicly available pages like login/logout.
95 */
96 $security_areas =array(
97 //
98 //      Site administration
99 //
100         'SA_CREATECOMPANY' =>array(SS_SADMIN|1, _("Install/update companies")),
101         'SA_CREATELANGUAGE' => array(SS_SADMIN|2, _("Install/update languages")),
102         'SA_CREATEMODULES' => array(SS_SADMIN|3, _("Install/upgrade modules")),
103         'SA_SOFTWAREUPGRADE' => array(SS_SADMIN|4, _("Software upgrades")),
104 //
105 //      Company setup
106 //
107         'SA_SETUPCOMPANY' => array(SS_SETUP|1, _("Company parameters")),
108         'SA_SECROLES' => array(SS_SETUP|2, _("Access levels edition")),
109         'SA_USERS' => array(SS_SETUP|3, _("Users setup")),
110         'SA_POSSETUP' => array(SS_SETUP|4, _("Point of sales definitions")),
111         'SA_PRINTERS' => array(SS_SETUP|5, _("Printers configuration")),
112         'SA_PRINTPROFILE' => array(SS_SETUP|6, _("Print profiles")),
113         'SA_PAYTERMS' => array(SS_SETUP|7, _("Payment terms")),
114         'SA_SHIPPING' => array(SS_SETUP|8, _("Shipping ways")),
115         'SA_CRSTATUS' => array(SS_SETUP|9, _("Credit status definitions changes")),
116         'SA_INVENTORYLOCATION' => array(SS_SETUP|10, _("Inventory locations changes")),
117         'SA_INVENTORYMOVETYPE'  => array(SS_SETUP|11, _("Inventory movement types")),
118         'SA_WORKCENTRES' => array(SS_SETUP|12, _("Manufacture work centres")),
119         'SA_FORMSETUP' => array(SS_SETUP|13, _("Forms setup")),
120         'SA_CRMCATEGORY' => array(SS_SETUP|14, _("Contact categories")),
121 //
122 // Special and common functions
123 //
124         'SA_VOIDTRANSACTION' => array(SS_SPEC|1, _("Voiding transactions")),
125         'SA_BACKUP' => array(SS_SPEC|2, _("Database backup/restore")),
126         'SA_VIEWPRINTTRANSACTION' => array(SS_SPEC|3, _("Common view/print transactions interface")),
127         'SA_ATTACHDOCUMENT' => array(SS_SPEC|4, _("Attaching documents")),
128         'SA_SETUPDISPLAY' => array(SS_SPEC|5, _("Display preferences")),
129         'SA_CHGPASSWD' => array(SS_SPEC|6, _("Password changes")),
130         'SA_EDITOTHERSTRANS' => array(SS_SPEC|7, _("Edit other users transactions")),
131 //
132 // Sales related functionality
133 //
134         'SA_SALESTYPES' => array(SS_SALES_C|1, _("Sales types")),
135         'SA_SALESPRICE' => array(SS_SALES_C|2, _("Sales prices edition")),
136         'SA_SALESMAN' => array(SS_SALES_C|3, _("Sales staff maintenance")),
137         'SA_SALESAREA' => array(SS_SALES_C|4, _("Sales areas maintenance")),
138         'SA_SALESGROUP' => array(SS_SALES_C|5, _("Sales groups changes")),
139         'SA_STEMPLATE' => array(SS_SALES_C|6, _("Sales templates")),
140         'SA_SRECURRENT' => array(SS_SALES_C|7, _("Recurrent invoices definitions")),
141
142         'SA_SALESTRANSVIEW' => array(SS_SALES|1,  _("Sales transactions view")),
143         'SA_CUSTOMER' => array(SS_SALES|2,  _("Sales customer and branches changes")),
144         'SA_SALESQUOTE' => array(SS_SALES|10, _("Sales quotations")),
145         'SA_SALESORDER' => array(SS_SALES|3, _("Sales orders edition")),
146         'SA_SALESDELIVERY' => array(SS_SALES|4, _("Sales deliveries edition")),
147         'SA_SALESINVOICE' => array(SS_SALES|5, _("Sales invoices edition")),
148         'SA_SALESCREDITINV' => array(SS_SALES|6, _("Sales credit notes against invoice")),
149         'SA_SALESCREDIT' => array(SS_SALES|7, _("Sales freehand credit notes")),
150         'SA_SALESPAYMNT' => array(SS_SALES|8, _("Customer payments entry")),
151         'SA_SALESALLOC' => array(SS_SALES|9, _("Customer payments allocation")),
152
153         'SA_SALESANALYTIC' => array(SS_SALES_A|1, _("Sales analytical reports")),
154         'SA_SALESBULKREP' => array(SS_SALES_A|2, _("Sales document bulk reports")),
155         'SA_PRICEREP' => array(SS_SALES_A|3, _("Sales prices listing")),
156         'SA_SALESMANREP' => array(SS_SALES_A|4, _("Sales staff listing")),
157         'SA_CUSTBULKREP' => array(SS_SALES_A|5, _("Customer bulk listing")),
158         'SA_CUSTSTATREP' => array(SS_SALES_A|6, _("Customer status report")),
159         'SA_CUSTPAYMREP' => array(SS_SALES_A|7, _("Customer payments report")),
160
161 //
162 // Purchase related functions
163 //
164         'SA_PURCHASEPRICING' => array(SS_PURCH_C|1, _("Purchase price changes")),
165
166         'SA_SUPPTRANSVIEW' => array(SS_PURCH|1, _("Supplier transactions view")),
167         'SA_SUPPLIER' => array(SS_PURCH|2, _("Suppliers changes")),
168         'SA_PURCHASEORDER' => array(SS_PURCH|3, _("Purchase order entry")),
169         'SA_GRN' => array(SS_PURCH|4, _("Purchase receive")),
170         'SA_SUPPLIERINVOICE' => array(SS_PURCH|5, _("Supplier invoices")),
171         'SA_SUPPLIERCREDIT' => array(SS_PURCH|6, _("Supplier credit notes")),
172         'SA_SUPPLIERPAYMNT' => array(SS_PURCH|7, _("Supplier payments")),
173         'SA_SUPPLIERALLOC' => array(SS_PURCH|8, _("Supplier payments allocations")),
174
175         'SA_SUPPLIERANALYTIC' => array(SS_PURCH_A|1, _("Supplier analytical reports")),
176         'SA_SUPPBULKREP' => array(SS_PURCH_A|2, _("Supplier document bulk reports")),
177         'SA_SUPPPAYMREP' => array(SS_PURCH_A|3, _("Supplier payments report")),
178 //
179 // Inventory 
180 //
181         'SA_ITEM' => array(SS_ITEMS_C|1, _("Stock items add/edit")),
182         'SA_SALESKIT' => array(SS_ITEMS_C|2, _("Sales kits")),
183         'SA_ITEMCATEGORY' => array(SS_ITEMS_C|3, _("Item categories")),
184         'SA_UOM' => array(SS_ITEMS_C|4, _("Units of measure")),
185
186         'SA_ITEMSSTATVIEW' => array(SS_ITEMS|1, _("Stock status view")),
187         'SA_ITEMSTRANSVIEW' => array(SS_ITEMS|2, _("Stock transactions view")),
188         'SA_FORITEMCODE' => array(SS_ITEMS|3, _("Foreign item codes entry")),
189         'SA_LOCATIONTRANSFER' => array(SS_ITEMS|4, _("Inventory location transfers")),
190         'SA_INVENTORYADJUSTMENT' => array(SS_ITEMS|5, _("Inventory adjustments")),
191
192         'SA_REORDER' => array(SS_ITEMS_A|1, _("Reorder levels")),
193         'SA_ITEMSANALYTIC' => array(SS_ITEMS_A|2, _("Items analytical reports and inquiries")),
194         'SA_ITEMSVALREP' => array(SS_ITEMS_A|3, _("Inventory valuation report")),
195
196 //
197 // Fixed Assets
198 //
199         'SA_ASSET' => array(SS_ASSETS_C|1, _("Fixed Asset items add/edit")),
200         'SA_ASSETCATEGORY' => array(SS_ASSETS_C|2, _("Fixed Asset categories")),
201         'SA_ASSETCLASS' => array(SS_ASSETS_C|4, _("Fixed Asset classes")),
202
203         'SA_ASSETSTRANSVIEW' => array(SS_ASSETS|1, _("Fixed Asset transactions view")),
204         'SA_ASSETTRANSFER' => array(SS_ASSETS|2, _("Fixed Asset location transfers")),
205         'SA_ASSETDISPOSAL' => array(SS_ASSETS|3, _("Fixed Asset disposals")),
206     'SA_DEPRECIATION' => array(SS_ASSETS|4, _("Depreciation")),
207
208         'SA_ASSETSANALYTIC' => array(SS_ASSETS_A|1, _("Fixed Asset analytical reports and inquiries")),
209
210 //
211 // Manufacturing module 
212 //
213         'SA_BOM' => array(SS_MANUF_C|1, _("Bill of Materials")),
214
215         'SA_MANUFTRANSVIEW' => array(SS_MANUF|1, _("Manufacturing operations view")),
216         'SA_WORKORDERENTRY' => array(SS_MANUF|2, _("Work order entry")),
217         'SA_MANUFISSUE' => array(SS_MANUF|3, _("Material issues entry")),
218         'SA_MANUFRECEIVE' => array(SS_MANUF|4, _("Final product receive")),
219         'SA_MANUFRELEASE' => array(SS_MANUF|5, _("Work order releases")),
220
221         'SA_WORKORDERANALYTIC' => array(SS_MANUF_A|1, _("Work order analytical reports and inquiries")),
222         'SA_WORKORDERCOST' => array(SS_MANUF_A|2, _("Manufacturing cost inquiry")),
223         'SA_MANUFBULKREP' => array(SS_MANUF_A|3, _("Work order bulk reports")),
224         'SA_BOMREP' => array(SS_MANUF_A|4, _("Bill of materials reports")),
225 //
226 // Dimensions
227 //
228         'SA_DIMTAGS' => array(SS_DIM_C|1, _("Dimension tags")),
229
230         'SA_DIMTRANSVIEW' => array(SS_DIM|1, _("Dimension view")),
231
232         'SA_DIMENSION' => array(SS_DIM|2, _("Dimension entry")),
233
234         'SA_DIMENSIONREP' => array(SS_DIM|3, _("Dimension reports")),
235 //
236 // Banking and General Ledger
237 //
238         'SA_ITEMTAXTYPE' => array(SS_GL_C|1, _("Item tax type definitions")),
239         'SA_GLACCOUNT' => array(SS_GL_C|2, _("GL accounts edition")),
240         'SA_GLACCOUNTGROUP' => array(SS_GL_C|3, _("GL account groups")),
241         'SA_GLACCOUNTCLASS' => array(SS_GL_C|4, _("GL account classes")),
242         'SA_QUICKENTRY' => array(SS_GL_C|5, _("Quick GL entry definitions")),
243         'SA_CURRENCY' => array(SS_GL_C|6, _("Currencies")),
244         'SA_BANKACCOUNT' => array(SS_GL_C|7, _("Bank accounts")),
245         'SA_TAXRATES' => array(SS_GL_C|8, _("Tax rates")),
246         'SA_TAXGROUPS' => array(SS_GL_C|12, _("Tax groups")),
247         'SA_FISCALYEARS' => array(SS_GL_C|9, _("Fiscal years maintenance")),
248         'SA_GLSETUP' => array(SS_GL_C|10, _("Company GL setup")),
249         'SA_GLACCOUNTTAGS' => array(SS_GL_C|11, _("GL Account tags")),
250         'SA_GLCLOSE' => array(SS_GL_C|14, _("Closing GL transactions")),
251         'SA_GLREOPEN' => array(SS_GL_C|15, _("Reopening GL transactions")), // see below
252         'SA_MULTIFISCALYEARS' => array(SS_GL_C|13, _("Allow entry on non closed Fiscal years")),
253
254         'SA_BANKTRANSVIEW' => array(SS_GL|1, _("Bank transactions view")),
255         'SA_GLTRANSVIEW' => array(SS_GL|2, _("GL postings view")),
256         'SA_EXCHANGERATE' => array(SS_GL|3, _("Exchange rate table changes")),
257         'SA_PAYMENT' => array(SS_GL|4, _("Bank payments")),
258         'SA_DEPOSIT' => array(SS_GL|5, _("Bank deposits")),
259         'SA_BANKTRANSFER' => array(SS_GL|6, _("Bank account transfers")),
260         'SA_RECONCILE' => array(SS_GL|7, _("Bank reconciliation")),
261         'SA_JOURNALENTRY' => array(SS_GL|8, _("Manual journal entries")),
262         'SA_BANKJOURNAL' => array(SS_GL|11, _("Journal entries to bank related accounts")),
263         'SA_BUDGETENTRY' => array(SS_GL|9, _("Budget edition")),
264         'SA_STANDARDCOST' => array(SS_GL|10, _("Item standard costs")),
265         'SA_ACCRUALS' => array(SS_GL|12, _("Revenue / Cost Accruals")),
266
267         'SA_GLANALYTIC' => array(SS_GL_A|1, _("GL analytical reports and inquiries")),
268         'SA_TAXREP' => array(SS_GL_A|2, _("Tax reports and inquiries")),
269         'SA_BANKREP' => array(SS_GL_A|3, _("Bank reports and inquiries")),
270         'SA_GLREP' => array(SS_GL_A|4, _("GL reports and inquiries")),
271 );
272
273 if (!@$SysPrefs->allow_gl_reopen)
274         unset($security_areas['SA_GLREOPEN']);
275 /*
276         This function should be called whenever we want to extend core access level system
277         with new security areas and/or sections i.e.: 
278         . on any page with non-standard security areas
279         . in security roles editor
280         The call should be placed between session.inc inclusion and page() call.
281         Up to 155 security sections and 155 security areas for any extension can be installed.
282 */
283 function add_access_extensions()
284 {
285         global $security_areas, $security_sections, $installed_extensions;
286
287         foreach($installed_extensions as $extid => $ext) {
288                 $accext = hook_invoke($ext['package'], 'install_access', $dummy);
289                 if ($accext == null) continue;
290
291                 $scode = 100;
292                 $acode = 100;
293                 $extsections = $accext[1];
294                 $extareas = $accext[0];
295                 $extcode = $extid<<16;
296                 
297                 $trans = array();
298                 foreach($extsections as $code =>$name) {
299                         $trans[$code] = $scode<<8;
300                         // reassign section codes
301                         $security_sections[$trans[$code]|$extcode] = $name;
302                         $scode++;
303                 }
304                 foreach($extareas as $code => $area) {
305                         $section = $area[0]&0xff00;
306                         // extension modules:
307                         // if area belongs to nonstandard section
308                         // use translated section codes and
309                         // preserve lower part of area code
310                         if (isset($trans[$section])) {
311                                 $section = $trans[$section];
312                         } 
313                                 // otherwise assign next available
314                                 // area code >99
315                         $area[0] = $extcode | $section | ($acode++);
316                         $security_areas[$code] = $area;
317                 }
318         }
319 }
320
321 function check_edit_access($name)
322 {
323         global $input_security;
324
325         $access = @$input_security[$name];
326
327         if (!$access)
328                 $access = @$input_security['']; // default access level
329
330         if (!$access)
331                 return true; // if constraint is not defined edit access is allowed
332
333         return  user_check_access($access);
334 }
335 /*
336         Returns POST value or null if edit access to $name control is forbidden.
337 */
338 function access_post($name, $dflt=null)
339 {
340         if (!check_edit_access($name))
341                 return $dflt;
342         else
343                 return get_post($name, $dflt);
344 }
345
346 /*
347         Returns numeric input value or null if edit access to $name control is forbidden.
348 */
349 function access_num($name, $dflt=null)
350 {
351         if (!check_edit_access($name))
352                 return $dflt;
353         else
354                 return input_num($name, $dflt);
355 }