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 page(_("Access setup"));
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/access_levels.inc");
20 include_once($path_to_root . "/admin/db/security_db.inc");
22 $new_role = get_post('role')=='' || get_post('cancel') || get_post('clone');
23 //--------------------------------------------------------------------------------------------------
24 if (list_updated('role')) {
25 $Ajax->activate('details');
26 $Ajax->activate('controls');
34 if (get_post('addupdate'))
37 if ($_POST['description'] == '')
40 display_error( _("Role description cannot be empty."));
41 set_focus('description');
43 elseif ($_POST['name'] == '')
46 display_error( _("Role name cannot be empty."));
50 if ($input_error == 0)
54 foreach($_POST as $p =>$val) {
55 if (substr($p,0,4) == 'Area')
56 $areas[] = substr($p, 4);
57 if (substr($p,0,6) == 'Section')
58 $sections[] = substr($p, 6);
64 add_security_role($_POST['name'], $_POST['description'], $sections, $areas);
65 display_notification(_("New security role has been added."));
68 update_security_role($_POST['role'], $_POST['name'], $_POST['description'],
70 update_record_status($_POST['role'], get_post('inactive'),
71 'security_roles', 'id');
73 display_notification(_("Security role has been updated."));
77 $Ajax->activate('_page_body');
81 //--------------------------------------------------------------------------------------------------
83 if (get_post('delete'))
85 if (check_role_used(get_post('role'))) {
86 display_error(_("This role is currently assigned to some users and cannot be deleted"));
88 delete_security_role(get_post('role'));
89 display_notification(_("Security role has been sucessfully deleted."));
90 unset($_POST['role']);
92 $Ajax->activate('_page_body');
95 if (get_post('cancel'))
97 unset($_POST['role']);
98 $Ajax->activate('_page_body');
101 if (!isset($_POST['role']) || get_post('clone') || list_updated('role')) {
102 $id = get_post('role');
103 $clone = get_post('clone');
107 $row = get_security_role($id);
108 $_POST['description'] = $row['description'];
109 $_POST['name'] = $row['role'];
110 // if ($row['inactive']
111 // $_POST['inactive'] = 1;
113 $_POST['inactive'] = $row['inactive'];
114 $access = $row['areas'];
115 $sections = $row['sections'];
118 $_POST['description'] = $_POST['name'] = '';
119 unset($_POST['inactive']);
120 $access = $sections = array();
122 foreach($access as $a) $_POST['Area'.$a] = 1;
123 foreach($sections as $s) $_POST['Section'.$s] = 1;
127 $Ajax->activate('_page_body');
129 $_POST['role'] = $id;
132 //--------------------------------------------------------------------------------------------------
136 start_table("class='tablestyle_noborder'");
138 security_roles_list_cells(_("Role:"). " ", 'role', null, true, true, check_value('show_inactive'));
139 $new_role = get_post('role')=='';
140 check_cells(_("Show inactive:"), 'show_inactive', null, true);
145 if (get_post('_show_inactive_update')) {
146 $Ajax->activate('role');
149 if (find_submit('_Section')) {
150 $Ajax->activate('details');
153 //-----------------------------------------------------------------------------------------------
154 div_start('details');
155 start_table($table_style2);
156 text_row(_("Role name:"), 'name', null, 20, 22);
157 text_row(_("Role description:"), 'description', null, 50, 52);
158 record_status_list_row(_("Current status:"), 'inactive');
161 start_table("$table_style width=40%");
163 $k = $j = 0; //row colour counter
165 asort($security_areas); // in the case installed external modules has added some lines
166 foreach($security_areas as $area =>$parms ) {
167 if (($parms[0]&~0xff) != $m)
168 { // features set selection
169 $m = $parms[0] & ~0xff;
170 label_row($security_sections[$m].':',
171 checkbox( null, 'Section'.$m, null, true,
172 _("On/off set of features")),
173 "class='tableheader2'", "class='tableheader'");
175 if (check_value('Section'.$m)) {
176 alt_table_row_color($k);
177 check_cells($parms[1], 'Area'.$parms[0], null,
178 false, '', "align='center'");
181 hidden('Area'.$parms[0]);
187 div_start('controls');
191 submit_center_first('Update', _("Update view"), '', null);
192 submit_center_last('addupdate', _("Insert New Role"), '', 'default');
196 submit_center_first('addupdate', _("Save Role"), '', 'default');
197 submit('Update', _("Update view"), true, '', null);
198 submit('clone', _("Clone This Role"), true, '', true);
199 submit('delete', _("Delete This Role"), true, '', true);
200 submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');