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 if (list_updated('role')) {
27 $Ajax->activate('details');
28 $Ajax->activate('controls');
36 if (get_post('addupdate'))
39 if ($_POST['description'] == '')
42 display_error( _("Role description cannot be empty."));
43 set_focus('description');
45 elseif ($_POST['name'] == '')
48 display_error( _("Role name cannot be empty."));
51 // prevent accidental editor lockup by removing SA_SECROLES
52 if (get_post('role') == $_SESSION['wa_current_user']->access) {
53 if (!isset($_POST['Area'.$security_areas['SA_SECROLES'][0]])
54 || !isset($_POST['Section'.SS_SETUP])) {
55 display_error(_("Access level edition in Company setup section have to be enabled for your account."));
57 set_focus(!isset($_POST['Section'.SS_SETUP])
58 ? 'Section'.SS_SETUP : 'Area'.$security_areas['SA_SECROLES'][0]);
62 if ($input_error == 0)
66 foreach($_POST as $p =>$val) {
67 if (substr($p,0,4) == 'Area')
68 $areas[] = substr($p, 4);
69 if (substr($p,0,7) == 'Section')
70 $sections[] = substr($p, 7);
77 add_security_role($_POST['name'], $_POST['description'], $sections, $areas);
78 display_notification(_("New security role has been added."));
81 update_security_role($_POST['role'], $_POST['name'], $_POST['description'],
83 update_record_status($_POST['role'], get_post('inactive'),
84 'security_roles', 'id');
86 display_notification(_("Security role has been updated."));
90 $Ajax->activate('_page_body');
94 //--------------------------------------------------------------------------------------------------
96 if (get_post('delete'))
98 if (check_role_used(get_post('role'))) {
99 display_error(_("This role is currently assigned to some users and cannot be deleted"));
101 delete_security_role(get_post('role'));
102 display_notification(_("Security role has been sucessfully deleted."));
103 unset($_POST['role']);
105 $Ajax->activate('_page_body');
108 if (get_post('cancel'))
110 unset($_POST['role']);
111 $Ajax->activate('_page_body');
114 if (!isset($_POST['role']) || get_post('clone') || list_updated('role')) {
115 $id = get_post('role');
116 $clone = get_post('clone');
120 $row = get_security_role($id);
121 $_POST['description'] = $row['description'];
122 $_POST['name'] = $row['role'];
123 // if ($row['inactive']
124 // $_POST['inactive'] = 1;
126 $_POST['inactive'] = $row['inactive'];
127 $access = $row['areas'];
128 $sections = $row['sections'];
131 $_POST['description'] = $_POST['name'] = '';
132 unset($_POST['inactive']);
133 $access = $sections = array();
135 foreach($access as $a) $_POST['Area'.$a] = 1;
136 foreach($sections as $s) $_POST['Section'.$s] = 1;
140 $Ajax->activate('_page_body');
142 $_POST['role'] = $id;
145 //--------------------------------------------------------------------------------------------------
149 start_table("class='tablestyle_noborder'");
151 security_roles_list_cells(_("Role:"). " ", 'role', null, true, true, check_value('show_inactive'));
152 $new_role = get_post('role')=='';
153 check_cells(_("Show inactive:"), 'show_inactive', null, true);
158 if (get_post('_show_inactive_update')) {
159 $Ajax->activate('role');
162 if (find_submit('_Section')) {
163 $Ajax->activate('details');
166 //-----------------------------------------------------------------------------------------------
167 div_start('details');
168 start_table($table_style2);
169 text_row(_("Role name:"), 'name', null, 20, 22);
170 text_row(_("Role description:"), 'description', null, 50, 52);
171 record_status_list_row(_("Current status:"), 'inactive');
174 start_table("$table_style width=40%");
176 $k = $j = 0; //row colour counter
178 asort($security_areas); // in the case installed external modules has added some lines
179 foreach($security_areas as $area =>$parms ) {
180 // system setup areas are accessable only for site admins i.e.
181 // admins of first registered company
182 if (user_company() && (($parms[0]&~0xff) == SS_SADMIN)) continue;
184 if (($parms[0]&~0xff) != $m)
185 { // features set selection
186 $m = $parms[0] & ~0xff;
187 label_row($security_sections[$m].':',
188 checkbox( null, 'Section'.$m, null, true,
189 _("On/off set of features")),
190 "class='tableheader2'", "class='tableheader'");
192 if (check_value('Section'.$m)) {
193 alt_table_row_color($k);
194 check_cells($parms[1], 'Area'.$parms[0], null,
195 false, '', "align='center'");
198 hidden('Area'.$parms[0]);
204 div_start('controls');
208 submit_center_first('Update', _("Update view"), '', null);
209 submit_center_last('addupdate', _("Insert New Role"), '', 'default');
213 submit_center_first('addupdate', _("Save Role"), '', 'default');
214 submit('Update', _("Update view"), true, '', null);
215 submit('clone', _("Clone This Role"), true, '', true);
216 submit('delete', _("Delete This Role"), true, '', true);
217 submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');