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."));
52 if ($input_error == 0)
56 foreach($_POST as $p =>$val) {
57 if (substr($p,0,4) == 'Area')
58 $areas[] = substr($p, 4);
59 if (substr($p,0,7) == 'Section')
60 $sections[] = substr($p, 7);
66 add_security_role($_POST['name'], $_POST['description'], $sections, $areas);
67 display_notification(_("New security role has been added."));
70 update_security_role($_POST['role'], $_POST['name'], $_POST['description'],
72 update_record_status($_POST['role'], get_post('inactive'),
73 'security_roles', 'id');
75 display_notification(_("Security role has been updated."));
79 $Ajax->activate('_page_body');
83 //--------------------------------------------------------------------------------------------------
85 if (get_post('delete'))
87 if (check_role_used(get_post('role'))) {
88 display_error(_("This role is currently assigned to some users and cannot be deleted"));
90 delete_security_role(get_post('role'));
91 display_notification(_("Security role has been sucessfully deleted."));
92 unset($_POST['role']);
94 $Ajax->activate('_page_body');
97 if (get_post('cancel'))
99 unset($_POST['role']);
100 $Ajax->activate('_page_body');
103 if (!isset($_POST['role']) || get_post('clone') || list_updated('role')) {
104 $id = get_post('role');
105 $clone = get_post('clone');
109 $row = get_security_role($id);
110 $_POST['description'] = $row['description'];
111 $_POST['name'] = $row['role'];
112 // if ($row['inactive']
113 // $_POST['inactive'] = 1;
115 $_POST['inactive'] = $row['inactive'];
116 $access = $row['areas'];
117 $sections = $row['sections'];
120 $_POST['description'] = $_POST['name'] = '';
121 unset($_POST['inactive']);
122 $access = $sections = array();
124 foreach($access as $a) $_POST['Area'.$a] = 1;
125 foreach($sections as $s) $_POST['Section'.$s] = 1;
129 $Ajax->activate('_page_body');
131 $_POST['role'] = $id;
134 //--------------------------------------------------------------------------------------------------
138 start_table("class='tablestyle_noborder'");
140 security_roles_list_cells(_("Role:"). " ", 'role', null, true, true, check_value('show_inactive'));
141 $new_role = get_post('role')=='';
142 check_cells(_("Show inactive:"), 'show_inactive', null, true);
147 if (get_post('_show_inactive_update')) {
148 $Ajax->activate('role');
151 if (find_submit('_Section')) {
152 $Ajax->activate('details');
155 //-----------------------------------------------------------------------------------------------
156 div_start('details');
157 start_table($table_style2);
158 text_row(_("Role name:"), 'name', null, 20, 22);
159 text_row(_("Role description:"), 'description', null, 50, 52);
160 record_status_list_row(_("Current status:"), 'inactive');
163 start_table("$table_style width=40%");
165 $k = $j = 0; //row colour counter
167 asort($security_areas); // in the case installed external modules has added some lines
168 foreach($security_areas as $area =>$parms ) {
169 if (($parms[0]&~0xff) != $m)
170 { // features set selection
171 $m = $parms[0] & ~0xff;
172 label_row($security_sections[$m].':',
173 checkbox( null, 'Section'.$m, null, true,
174 _("On/off set of features")),
175 "class='tableheader2'", "class='tableheader'");
177 if (check_value('Section'.$m)) {
178 alt_table_row_color($k);
179 check_cells($parms[1], 'Area'.$parms[0], null,
180 false, '', "align='center'");
183 hidden('Area'.$parms[0]);
189 div_start('controls');
193 submit_center_first('Update', _("Update view"), '', null);
194 submit_center_last('addupdate', _("Insert New Role"), '', 'default');
198 submit_center_first('addupdate', _("Save Role"), '', 'default');
199 submit('Update', _("Update view"), true, '', null);
200 submit('clone', _("Clone This Role"), true, '', true);
201 submit('delete', _("Delete This Role"), true, '', true);
202 submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');