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 $page_security = 'SA_SECROLES';
14 include_once($path_to_root . "/includes/session.inc");
16 add_access_extensions();
18 page(_("Access setup"));
20 include_once($path_to_root . "/includes/ui.inc");
21 include_once($path_to_root . "/includes/access_levels.inc");
22 include_once($path_to_root . "/admin/db/security_db.inc");
24 $new_role = get_post('role')=='' || get_post('cancel') || get_post('clone');
25 //--------------------------------------------------------------------------------------------------
26 // Following compare function is used for sorting areas
27 // in such a way that security areas defined by module/plugin
28 // is properly placed under related section regardless of
29 // unique extension number
31 function comp_areas($area1, $area2)
33 return ($area1[0]&0xffff)-($area2[0]&0xffff);
36 //--------------------------------------------------------------------------------------------------
37 if (list_updated('role')) {
38 $Ajax->activate('details');
39 $Ajax->activate('controls');
47 if (get_post('addupdate'))
50 if ($_POST['description'] == '')
53 display_error( _("Role description cannot be empty."));
54 set_focus('description');
56 elseif ($_POST['name'] == '')
59 display_error( _("Role name cannot be empty."));
62 // prevent accidental editor lockup by removing SA_SECROLES
63 if (get_post('role') == $_SESSION['wa_current_user']->access) {
64 if (!isset($_POST['Area'.$security_areas['SA_SECROLES'][0]])
65 || !isset($_POST['Section'.SS_SETUP])) {
66 display_error(_("Access level edition in Company setup section have to be enabled for your account."));
68 set_focus(!isset($_POST['Section'.SS_SETUP])
69 ? 'Section'.SS_SETUP : 'Area'.$security_areas['SA_SECROLES'][0]);
73 if ($input_error == 0)
77 foreach($_POST as $p =>$val) {
78 if (substr($p,0,4) == 'Area') {
80 if (($a&~0xffff) && (($a&0xff00)<(99<<8))) {
81 $sections[] = $a&~0xff; // add extended section for plugins
85 if (substr($p,0,7) == 'Section')
86 $sections[] = substr($p, 7);
88 uasort($areas, 'comp_areas');
90 $sections = array_values($sections);
94 add_security_role($_POST['name'], $_POST['description'], $sections, $areas);
95 display_notification(_("New security role has been added."));
98 update_security_role($_POST['role'], $_POST['name'], $_POST['description'],
100 update_record_status($_POST['role'], get_post('inactive'),
101 'security_roles', 'id');
103 display_notification(_("Security role has been updated."));
107 $Ajax->activate('_page_body');
111 //--------------------------------------------------------------------------------------------------
113 if (get_post('delete'))
115 if (check_role_used(get_post('role'))) {
116 display_error(_("This role is currently assigned to some users and cannot be deleted"));
118 delete_security_role(get_post('role'));
119 display_notification(_("Security role has been sucessfully deleted."));
120 unset($_POST['role']);
122 $Ajax->activate('_page_body');
125 if (get_post('cancel'))
127 unset($_POST['role']);
128 $Ajax->activate('_page_body');
131 if (!isset($_POST['role']) || get_post('clone') || list_updated('role')) {
132 $id = get_post('role');
133 $clone = get_post('clone');
137 $row = get_security_role($id);
138 $_POST['description'] = $row['description'];
139 $_POST['name'] = $row['role'];
140 // if ($row['inactive']
141 // $_POST['inactive'] = 1;
143 $_POST['inactive'] = $row['inactive'];
144 $access = $row['areas'];
145 $sections = $row['sections'];
148 $_POST['description'] = $_POST['name'] = '';
149 unset($_POST['inactive']);
150 $access = $sections = array();
152 foreach($access as $a) $_POST['Area'.$a] = 1;
153 foreach($sections as $s) $_POST['Section'.$s] = 1;
157 $Ajax->activate('_page_body');
159 $_POST['role'] = $id;
162 //--------------------------------------------------------------------------------------------------
166 start_table("class='tablestyle_noborder'");
168 security_roles_list_cells(_("Role:"). " ", 'role', null, true, true, check_value('show_inactive'));
169 $new_role = get_post('role')=='';
170 check_cells(_("Show inactive:"), 'show_inactive', null, true);
175 if (get_post('_show_inactive_update')) {
176 $Ajax->activate('role');
179 if (find_submit('_Section')) {
180 $Ajax->activate('details');
182 //-----------------------------------------------------------------------------------------------
183 div_start('details');
184 start_table($table_style2);
185 text_row(_("Role name:"), 'name', null, 20, 22);
186 text_row(_("Role description:"), 'description', null, 50, 52);
187 record_status_list_row(_("Current status:"), 'inactive');
190 start_table("$table_style width=40%");
192 $k = $j = 0; //row colour counter
193 $ext = $sec = $m = -1;
194 uasort($security_areas,'comp_areas');
195 foreach($security_areas as $area =>$parms ) {
196 // system setup areas are accessable only for site admins i.e.
197 // admins of first registered company
198 if (user_company() && (($parms[0]&0xff00) == SS_SADMIN)) continue;
200 $newsec = ($parms[0]>>8)&0xff;
201 $newext = $parms[0]>>16;
202 if ($newsec != $sec || (($newext != $ext) && ($newsec>99)))
203 { // features set selection
206 $m = $parms[0] & ~0xff;
207 // if(!isset($security_sections[$m]))
208 // display_error(sprintf("Bad section %X:", $m));
209 label_row($security_sections[$m].':',
210 checkbox( null, 'Section'.$m, null, true,
211 _("On/off set of features")),
212 "class='tableheader2'", "class='tableheader'");
214 if (check_value('Section'.$m)) {
215 alt_table_row_color($k);
216 check_cells($parms[1], 'Area'.$parms[0], null,
217 false, '', "align='center'");
220 hidden('Area'.$parms[0]);
226 div_start('controls');
230 submit_center_first('Update', _("Update view"), '', null);
231 submit_center_last('addupdate', _("Insert New Role"), '', 'default');
235 submit_center_first('addupdate', _("Save Role"), '', 'default');
236 submit('Update', _("Update view"), true, '', null);
237 submit('clone', _("Clone This Role"), true, '', true);
238 submit('delete', _("Delete This Role"), true, '', true);
239 submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');