55e56b556ae7fcab6f6b0fc52e8cd872b6a183cf
[fa-stable.git] / admin / db / security_db.inc
1 <?php
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 //--------------------------------------------------------------------------------------------------
13
14 function get_security_role($id)
15 {
16         $sql = "SELECT * FROM ".TB_PREF."security_roles WHERE id='$id'";
17         $ret = db_query($sql, "could not retrieve security roles");
18         $row = db_fetch($ret);
19         $row['areas'] = explode(';', $row['areas']);
20         $row['modules'] = explode(';', $row['modules']);
21         return $row;
22 }
23
24 //--------------------------------------------------------------------------------------------------
25
26 function add_security_role($name, $description, $modules, $areas)
27 {
28         $sql = "INSERT INTO ".TB_PREF."security_roles (role, description, modules, areas)
29         VALUES ("
30         .db_escape($name).","
31         .db_escape($description).","
32         .db_escape(implode(';',$modules)).","
33         .db_escape(implode(';',$areas)).")";
34
35         db_query($sql, "could not add new security role");
36 }
37
38 //--------------------------------------------------------------------------------------------------
39
40 function update_security_role($id, $name, $description, $modules, $areas)
41 {
42         $sql = "UPDATE ".TB_PREF."security_roles SET role=".db_escape($name)
43         .",description=".db_escape($description)
44         .",modules=".db_escape(implode(';',$modules))
45         .",areas=".db_escape(implode(';',$areas))
46         ." WHERE id=$id";
47         db_query($sql, "could not update role");
48 }
49 //--------------------------------------------------------------------------------------------------
50
51 function delete_security_role($id)
52 {
53         $sql = "DELETE FROM ".TB_PREF."security_roles WHERE id=$id";
54
55         db_query($sql, "could not delete role");
56 }
57 //--------------------------------------------------------------------------------------------------
58
59 function check_role_used($id) {
60         $sql = "SELECT count(*) FROM ".TB_PREF."users WHERE full_access=$id";
61         $ret = db_query($sql, 'cannot check role usage');
62         $row = db_fetch($ret);
63         return $row[0];
64 }
65 ?>