New/obsolete files update on 2.2
[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_MANUF_C',41<<8);
44 define('SS_MANUF',      42<<8);
45 define('SS_MANUF_A',43<<8);
46
47 define('SS_DIM_C',      51<<8);
48 define('SS_DIM',        52<<8);
49 define('SS_DIM_A',      53<<8);
50
51 define('SS_GL_C',       61<<8);
52 define('SS_GL',         62<<8);
53 define('SS_GL_A',       63<<8);
54
55 $security_sections = array(
56  SS_SADMIN => _("System administration"),
57  SS_SETUP => _("Company setup"),
58  SS_SPEC => _("Special maintenance"),
59  SS_SALES_C => _("Sales configuration"),
60  SS_SALES => _("Sales transactions"),
61  SS_SALES_A => _("Sales related reports"),
62  SS_PURCH_C => _("Purchase configuration"),
63  SS_PURCH => _("Purchase transactions"),
64  SS_PURCH_A => _("Purchase analytics"),
65  SS_ITEMS_C => _("Inventory configuration"),
66  SS_ITEMS => _("Inventory operations"),
67  SS_ITEMS_A => _("Inventory analytics"),
68  SS_MANUF_C => _("Manufacturing configuration"),
69  SS_MANUF => _("Manufacturing transations"),
70  SS_MANUF_A => _("Manufacturing analytics"),
71  SS_DIM_C => _("Dimensions configuration"),
72  SS_DIM => _("Dimensions"),
73  SS_GL_C => _("Banking & GL configuration"),
74  SS_GL => _("Banking & GL transactions"),
75  SS_GL_A => _("Banking & GL analytics")
76 );
77
78 /*
79         This table stores security areas available in FA. 
80         Key is area identifier used to check user rights, values are
81         codes stored for each role in security_roles table and description used
82         in roles editor.
83
84         Set of allowed access areas codes is retrieved during user login from
85         security_roles table, and cached in user profile.
86
87         Special value 'SA_OPEN' is used for publicly available pages like login/logout.
88 */
89 $security_areas =array(
90 //
91 //      Site administration
92 //
93         'SA_CREATECOMPANY' =>array(SS_SADMIN|1, _("Install/update companies")),
94         'SA_CREATELANGUAGE' => array(SS_SADMIN|2, _("Install/update languages")),
95         'SA_CREATEMODULES' => array(SS_SADMIN|3, _("Install/upgrade modules")),
96         'SA_SOFTWAREUPGRADE' => array(SS_SADMIN|4, _("Software upgrades")),
97 //
98 //      Company setup
99 //
100         'SA_SETUPCOMPANY' => array(SS_SETUP|1, _("Company parameters")),
101         'SA_SECROLES' => array(SS_SETUP|2, _("Access levels edition")),
102         'SA_USERS' => array(SS_SETUP|3, _("Users setup")),
103         'SA_POSSETUP' => array(SS_SETUP|4, _("Point of sales definitions")),
104         'SA_PRINTERS' => array(SS_SETUP|5, _("Printers configuration")),
105         'SA_PRINTPROFILE' => array(SS_SETUP|6, _("Print profiles")),
106         'SA_PAYTERMS' => array(SS_SETUP|7, _("Payment terms")),
107         'SA_SHIPPING' => array(SS_SETUP|8, _("Shipping ways")),
108         'SA_CRSTATUS' => array(SS_SETUP|9, _("Credit status definitions changes")),
109         'SA_INVENTORYLOCATION' => array(SS_SETUP|10, _("Inventory locations changes")),
110         'SA_INVENTORYMOVETYPE'  => array(SS_SETUP|11, _("Inventory movement types")),
111         'SA_WORKCENTRES' => array(SS_SETUP|12, _("Manufacture work centres")),
112         'SA_FORMSETUP' => array(SS_SETUP|13, _("Forms setup")),
113 //
114 // Special and common functions
115 //
116         'SA_VOIDTRANSACTION' => array(SS_SPEC|1, _("Voiding transactions")),
117         'SA_BACKUP' => array(SS_SPEC|2, _("Database backup/restore")),
118         'SA_VIEWPRINTTRANSACTION' => array(SS_SPEC|3, _("Common view/print transactions interface")),
119         'SA_ATTACHDOCUMENT' => array(SS_SPEC|4, _("Attaching documents")),
120         'SA_SETUPDISPLAY' => array(SS_SPEC|5, _("Display preferences")), //???
121         'SA_CHGPASSWD' => array(SS_SPEC|6, _("Password changes")), //???
122
123 //
124 // Sales related functionality
125 //
126         'SA_SALESTYPES' => array(SS_SALES_C|1, _("Sales types")),
127         'SA_SALESPRICE' => array(SS_SALES_C|2, _("Sales prices edition")),
128         'SA_SALESMAN' => array(SS_SALES_C|3, _("Sales staff maintenance")),
129         'SA_SALESAREA' => array(SS_SALES_C|4, _("Sales areas maintenance")),
130         'SA_SALESGROUP' => array(SS_SALES_C|5, _("Sales groups changes")),
131         'SA_STEMPLATE' => array(SS_SALES_C|6, _("Sales templates")),
132         'SA_SRECURRENT' => array(SS_SALES_C|7, _("Recurrent invoices definitions")),
133
134         'SA_SALESTRANSVIEW' => array(SS_SALES|1,  _("Sales transactions view")),
135         'SA_CUSTOMER' => array(SS_SALES|2,  _("Sales customer and branches changes")),
136         'SA_SALESQUOTE' => array(SS_SALES|10, _("Sales quotations")),
137         'SA_SALESORDER' => array(SS_SALES|3, _("Sales orders edition")),
138         'SA_SALESDELIVERY' => array(SS_SALES|4, _("Sales deliveries edition")),
139         'SA_SALESINVOICE' => array(SS_SALES|5, _("Sales invoices edition")),
140         'SA_SALESCREDITINV' => array(SS_SALES|6, _("Sales credit notes against invoice")),
141         'SA_SALESCREDIT' => array(SS_SALES|7, _("Sales freehand credit notes")),
142         'SA_SALESPAYMNT' => array(SS_SALES|8, _("Customer payments entry")),
143         'SA_SALESALLOC' => array(SS_SALES|9, _("Customer payments allocation")),
144
145         'SA_SALESANALYTIC' => array(SS_SALES_A|1, _("Sales analytical reports")),
146         'SA_SALESBULKREP' => array(SS_SALES_A|2, _("Sales document bulk reports")),
147         'SA_PRICEREP' => array(SS_SALES_A|3, _("Sales prices listing")),
148         'SA_SALESMANREP' => array(SS_SALES_A|4, _("Sales staff listing")),
149         'SA_CUSTBULKREP' => array(SS_SALES_A|5, _("Customer bulk listing")),
150         'SA_CUSTSTATREP' => array(SS_SALES_A|6, _("Customer status report")),
151         'SA_CUSTPAYMREP' => array(SS_SALES_A|7, _("Customer payments report")),
152
153 //
154 // Purchase related functions
155 //
156         'SA_PURCHASEPRICING' => array(SS_PURCH_C|1, _("Purchase price changes")),
157
158         'SA_SUPPTRANSVIEW' => array(SS_PURCH|1, _("Supplier transactions view")),
159         'SA_SUPPLIER' => array(SS_PURCH|2, _("Suppliers changes")),
160         'SA_PURCHASEORDER' => array(SS_PURCH|3, _("Purchase order entry")),
161         'SA_GRN' => array(SS_PURCH|4, _("Purchase receive")),
162         'SA_SUPPLIERINVOICE' => array(SS_PURCH|5, _("Supplier invoices")),
163         'SA_GRNDELETE' => array(SS_PURCH|9, _("Deleting GRN items during invoice entry")),
164         'SA_SUPPLIERCREDIT' => array(SS_PURCH|6, _("Supplier credit notes")),
165         'SA_SUPPLIERPAYMNT' => array(SS_PURCH|7, _("Supplier payments")),
166         'SA_SUPPLIERALLOC' => array(SS_PURCH|8, _("Supplier payments allocations")),
167
168         'SA_SUPPLIERANALYTIC' => array(SS_PURCH_A|1, _("Supplier analytical reports")),
169         'SA_SUPPBULKREP' => array(SS_PURCH_A|2, _("Supplier document bulk reports")),
170         'SA_SUPPPAYMREP' => array(SS_PURCH_A|3, _("Supplier payments report")),
171 //
172 // Inventory 
173 //
174         'SA_ITEM' => array(SS_ITEMS_C|1, _("Stock items add/edit")),
175         'SA_SALESKIT' => array(SS_ITEMS_C|2, _("Sales kits")),
176         'SA_ITEMCATEGORY' => array(SS_ITEMS_C|3, _("Item categories")),
177         'SA_UOM' => array(SS_ITEMS_C|4, _("Units of measure")),
178
179         'SA_ITEMSSTATVIEW' => array(SS_ITEMS|1, _("Stock status view")),
180         'SA_ITEMSTRANSVIEW' => array(SS_ITEMS|2, _("Stock transactions view")),
181         'SA_FORITEMCODE' => array(SS_ITEMS|3, _("Foreign item codes entry")),
182         'SA_LOCATIONTRANSFER' => array(SS_ITEMS|4, _("Inventory location transfers")),
183         'SA_INVENTORYADJUSTMENT' => array(SS_ITEMS|5, _("Inventory adjustments")),
184
185         'SA_REORDER' => array(SS_ITEMS_A|1, _("Reorder levels")),
186         'SA_ITEMSANALYTIC' => array(SS_ITEMS_A|2, _("Items analytical reports and inquiries")),
187         'SA_ITEMSVALREP' => array(SS_ITEMS_A|3, _("Inventory valuation report")),
188
189 //
190 // Manufacturing module 
191 //
192         'SA_BOM' => array(SS_MANUF_C|1, _("Bill of Materials")),
193
194         'SA_MANUFTRANSVIEW' => array(SS_MANUF|1, _("Manufacturing operations view")),
195         'SA_WORKORDERENTRY' => array(SS_MANUF|2, _("Work order entry")),
196         'SA_MANUFISSUE' => array(SS_MANUF|3, _("Material issues entry")),
197         'SA_MANUFRECEIVE' => array(SS_MANUF|4, _("Final product receive")),
198         'SA_MANUFRELEASE' => array(SS_MANUF|5, _("Work order releases")),
199
200         'SA_WORKORDERANALYTIC' => array(SS_MANUF_A|1, _("Work order analytical reports and inquiries")),
201         'SA_WORKORDERCOST' => array(SS_MANUF_A|2, _("Manufacturing cost inquiry")),
202         'SA_MANUFBULKREP' => array(SS_SALES_A|3, _("Work order bulk reports")),
203         'SA_BOMREP' => array(SS_MANUF_A|4, _("Bill of materials reports")),
204 //
205 // Dimensions
206 //
207         'SA_DIMTAGS' => array(SS_DIM_C|1, _("Dimension tags")),
208
209         'SA_DIMTRANSVIEW' => array(SS_DIM|1, _("Dimension view")),
210
211         'SA_DIMENSION' => array(SS_DIM|2, _("Dimension entry")),
212
213         'SA_DIMENSIONREP' => array(SS_DIM|3, _("Dimension reports")),
214 //
215 // Banking and General Ledger
216 //
217         'SA_ITEMTAXTYPE' => array(SS_GL_C|1, _("Item tax type definitions")),
218         'SA_GLACCOUNT' => array(SS_GL_C|2, _("GL accounts edition")),
219         'SA_GLACCOUNTGROUP' => array(SS_GL_C|3, _("GL account groups")),
220         'SA_GLACCOUNTCLASS' => array(SS_GL_C|4, _("GL account classes")),
221         'SA_QUICKENTRY' => array(SS_GL_C|5, _("Quick GL entry definitions")),
222         'SA_CURRENCY' => array(SS_GL_C|6, _("Currencies")),
223         'SA_BANKACCOUNT' => array(SS_GL_C|7, _("Bank accounts")),
224         'SA_TAXRATES' => array(SS_GL_C|8, _("Tax rates")),
225         'SA_TAXGROUPS' => array(SS_GL_C|8, _("Tax groups")),
226         'SA_FISCALYEARS' => array(SS_GL_C|9, _("Fiscal years maintenance")),
227         'SA_GLSETUP' => array(SS_GL_C|10, _("Company GL setup")),
228         'SA_GLACCOUNTTAGS' => array(SS_GL_C|11, _("GL Account tags")),
229
230         'SA_BANKTRANSVIEW' => array(SS_GL|1, _("Bank transactions view")),
231         'SA_GLTRANSVIEW' => array(SS_GL|2, _("GL postings view")),
232         'SA_EXCHANGERATE' => array(SS_GL|3, _("Exchange rate table changes")),
233         'SA_PAYMENT' => array(SS_GL|4, _("Bank payments")),
234         'SA_DEPOSIT' => array(SS_GL|5, _("Bank deposits")),
235         'SA_BANKTRANSFER' => array(SS_GL|6, _("Bank account transfers")),
236         'SA_RECONCILE' => array(SS_GL|7, _("Bank reconciliation")),
237         'SA_JOURNALENTRY' => array(SS_GL|8, _("Manual journal entries")),
238         'SA_BANKJOURNAL' => array(SS_GL|11, _("Journal entries to bank related accounts")),
239         'SA_BUDGETENTRY' => array(SS_GL|9, _("Budget edition")),
240         'SA_STANDARDCOST' => array(SS_GL|10, _("Item standard costs")),
241
242         'SA_GLANALYTIC' => array(SS_GL_A|1, _("GL analytical reports and inquiries")),
243         'SA_TAXREP' => array(SS_GL_A|2, _("Tax reports and inquiries")),
244         'SA_BANKREP' => array(SS_GL_A|3, _("Bank reports and inquiries")),
245         'SA_GLREP' => array(SS_GL_A|4, _("GL reports and inquiries")),
246 );
247 /*
248         This function should be called whenever we want to extend core access level system
249         with new security areas and/or sections i.e.: 
250         . on any page with non-standard security areas
251         . in security roles editor
252         The call should be placed between session.inc inclusion and page() call.
253         Up to 155 security sections and 155 security areas for any extension can be installed.
254 */
255 function add_access_extensions()
256 {
257         global $security_areas, $security_sections, $installed_extensions;
258
259         foreach($installed_extensions as $extid => $ext) {
260                 $scode = 100;
261                 $acode = 100;
262                 $accext = get_access_extensions($extid);
263                 $extsections = $accext[1];
264                 $extareas = $accext[0];
265                 $extcode = $extid<<16;
266                 
267                 $trans = array();
268                 foreach($extsections as $code =>$name) {
269                         $trans[$code] = $scode<<8;
270                         // reassign section codes
271                         $security_sections[$trans[$code]|$extcode] = $name;
272                         $scode++;
273                 }
274                 foreach($extareas as $code => $area) {
275                         $section = $area[0]&0xff00;
276                         // extension modules:
277                         // if area belongs to nonstandard section
278                         // use translated section codes and
279                         // preserve lower part of area code
280                         if (isset($trans[$section])) {
281                                 $section = $trans[$section];
282                         } 
283                                 // otherwise assign next available
284                                 // area code >99
285                         $area[0] = $extcode | $section | ($acode++);
286                         $security_areas[$code] = $area;
287                 }
288         }
289 }
290 /*
291         Helper function to retrieve extension access definitions in isolated environment.
292 */
293 function get_access_extensions($id) {
294         global $path_to_root, $installed_extensions;
295         
296         $ext = $installed_extensions[$id];
297         
298         $security_sections = $security_areas = array();
299         
300         if (isset($ext['acc_file']))
301                 include($path_to_root.($ext['type'] == 'plugin' ? '/modules/':'/').$ext['path'].'/'.$ext['acc_file']);
302
303         return array($security_areas, $security_sections);
304 }
305
306 ?>