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 ***********************************************************************/
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) == 'Module')
58 $modules[] = substr($p, 6);
64 add_security_role($_POST['name'], $_POST['description'], $modules, $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');
106 $row = get_security_role($id);
107 $_POST['description'] = $row['description'];
108 $_POST['name'] = $row['role'];
109 // if ($row['inactive']
110 // $_POST['inactive'] = 1;
112 $_POST['inactive'] = $row['inactive'];
113 $access = $row['areas'];
114 $modules = $row['modules'];
117 $_POST['description'] = $_POST['name'] = '';
118 unset($_POST['inactive']);
119 $access = $modules = array();
121 foreach($access as $a) $_POST['Area'.$a] = 1;
122 foreach($modules as $m) $_POST['Module'.$m] = 1;
126 $Ajax->activate('_page_body');
128 $_POST['role'] = $id;
131 //--------------------------------------------------------------------------------------------------
135 start_table("class='tablestyle_noborder'");
137 security_roles_list_cells(_("Role:"). " ", 'role', null, true, true, check_value('show_inactive'));
138 //$new_role = get_post('role')=='';
139 check_cells(_("Show inactive:"), 'show_inactive', null, true);
144 if (get_post('_show_inactive_update')) {
145 $Ajax->activate('role');
148 if (find_submit('_Module')) {
149 $Ajax->activate('details');
152 //-----------------------------------------------------------------------------------------------
153 div_start('details');
154 start_table($table_style2);
155 text_row(_("Role name:"), 'name', null, 20, 22);
156 text_row(_("Role description:"), 'description', null, 50, 52);
157 record_status_list_row(_("Current status:"), 'inactive');
160 start_table("$table_style width=50%");
162 $k = $j = 0; //row colour counter
164 foreach($security_areas as $area =>$descr ) {
165 if (($area&~0xff) != $m)
166 { // features set selection
168 label_row(sprintf(_("%s features:"), $security_modules[$m]),
169 checkbox( null, 'Module'.$m, null, true,
170 _("Set access to security features area")),
171 "class='tableheader2'", "class='tableheader'");
173 if (check_value('Module'.$m)) {
174 alt_table_row_color($k);
175 check_cells($descr, 'Area'.$area, null,
176 false, '', "align='center'");
179 hidden('Area'.$area);
185 div_start('controls');
188 submit_center('addupdate', _("Insert New Role"), true, '', 'default');
192 submit_center_first('addupdate', _("Update Role"), '', 'default');
193 submit('clone', _("Clone This Role"), true, '', true);
194 submit('delete', _("Delete This Role"), true, '', true);
195 submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');