1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | user_perm.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-02-11 23:20:38 +0000 (Wed, 11 Feb 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 362 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | include_once( './admin/include/isadmin.inc.php' ); |
---|
28 | //----------------------------------------------------- template initialization |
---|
29 | $sub = $vtp->Open( './template/'.$user['template'].'/admin/user_perm.vtp' ); |
---|
30 | $error = array(); |
---|
31 | $tpl = array( 'permuser_authorized','permuser_forbidden','submit', |
---|
32 | 'permuser_parent_forbidden','permuser_info_message', |
---|
33 | 'adduser_info_back','permuser_only_private' ); |
---|
34 | templatize_array( $tpl, 'lang', $sub ); |
---|
35 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
36 | //--------------------------------------------------------------------- updates |
---|
37 | if ( isset( $_POST['submit'] ) ) |
---|
38 | { |
---|
39 | // cleaning the user_access table for this user |
---|
40 | $query = 'DELETE FROM '.PREFIX_TABLE.'user_access'; |
---|
41 | $query.= ' WHERE user_id = '.$_GET['user_id']; |
---|
42 | $query.= ';'; |
---|
43 | mysql_query( $query ); |
---|
44 | // selecting all private categories |
---|
45 | $query = 'SELECT id'; |
---|
46 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
47 | $query.= " WHERE status = 'private'"; |
---|
48 | $query.= ';'; |
---|
49 | $result = mysql_query( $query ); |
---|
50 | while ( $row = mysql_fetch_array( $result ) ) |
---|
51 | { |
---|
52 | $radioname = 'access-'.$row['id']; |
---|
53 | if ( $_POST[$radioname] == 0 ) |
---|
54 | { |
---|
55 | $query = 'INSERT INTO '.PREFIX_TABLE.'user_access'; |
---|
56 | $query.= ' (user_id,cat_id) VALUES'; |
---|
57 | $query.= ' ('.$_GET['user_id'].','.$row['id'].')'; |
---|
58 | $query.= ';'; |
---|
59 | mysql_query ( $query ); |
---|
60 | } |
---|
61 | } |
---|
62 | check_favorites( $_GET['user_id'] ); |
---|
63 | synchronize_user( $_GET['user_id'] ); |
---|
64 | $vtp->addSession( $sub, 'confirmation' ); |
---|
65 | $url = './admin.php?page=user_list'; |
---|
66 | $vtp->setVar( $sub, 'confirmation.back_url', add_session_id( $url ) ); |
---|
67 | $vtp->closeSession( $sub, 'confirmation' ); |
---|
68 | } |
---|
69 | //---------------------------------------------------------------- form display |
---|
70 | $restrictions = get_user_restrictions( $_GET['user_id'], $page['user_status'], |
---|
71 | false, false ); |
---|
72 | $action = './admin.php?page=user_perm&user_id='.$_GET['user_id']; |
---|
73 | $vtp->setVar( $sub, 'action', add_session_id( $action ) ); |
---|
74 | // Association of group_ids with group_names -> caching informations |
---|
75 | $query = 'SELECT id,name'; |
---|
76 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
77 | $query.= ';'; |
---|
78 | $result = mysql_query( $query ); |
---|
79 | $groups = array(); |
---|
80 | while ( $row = mysql_fetch_array( $result ) ) |
---|
81 | { |
---|
82 | $groups[$row['id']] = $row['name']; |
---|
83 | } |
---|
84 | // Listing of groups the user belongs to |
---|
85 | $query = 'SELECT ug.group_id as groupid'; |
---|
86 | $query.= ' FROM '.PREFIX_TABLE.'user_group as ug'; |
---|
87 | $query.= ' WHERE user_id = '.$_GET['user_id']; |
---|
88 | $query.= ';'; |
---|
89 | $result = mysql_query( $query ); |
---|
90 | $usergroups = array(); |
---|
91 | while ( $row = mysql_fetch_array( $result ) ) |
---|
92 | { |
---|
93 | array_push( $usergroups, $row['groupid'] ); |
---|
94 | } |
---|
95 | // only private categories are listed |
---|
96 | $query = 'SELECT id'; |
---|
97 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
98 | $query.= " WHERE status = 'private'"; |
---|
99 | $query.= ';'; |
---|
100 | $result = mysql_query( $query ); |
---|
101 | while ( $row = mysql_fetch_array( $result ) ) |
---|
102 | { |
---|
103 | $vtp->addSession( $sub, 'category' ); |
---|
104 | $vtp->setVar( $sub, 'category.id', $row['id'] ); |
---|
105 | // we have to know whether the user is authorized to access this |
---|
106 | // category. The category can be accessible for this user thanks to his |
---|
107 | // personnal access rights OR thanks to the access rights of a group he |
---|
108 | // belongs to. |
---|
109 | // 1. group access : |
---|
110 | // retrieving all authorized groups for this category and for this user |
---|
111 | $query = 'SELECT ga.group_id as groupid'; |
---|
112 | $query.= ' FROM '.PREFIX_TABLE.'group_access as ga'; |
---|
113 | $query.= ', '.PREFIX_TABLE.'user_group as ug'; |
---|
114 | $query.= ' WHERE ga.group_id = ug.group_id'; |
---|
115 | $query.= ' AND ug.user_id = '.$_GET['user_id']; |
---|
116 | $query.= ' AND cat_id = '.$row['id']; |
---|
117 | $query.= ';'; |
---|
118 | $subresult = mysql_query( $query ); |
---|
119 | $authorized_groups = array(); |
---|
120 | while ( $subrow = mysql_fetch_array( $subresult ) ) |
---|
121 | { |
---|
122 | array_push( $authorized_groups, $subrow['groupid'] ); |
---|
123 | } |
---|
124 | // 2. personnal access |
---|
125 | $is_user_allowed = is_user_allowed( $row['id'], $restrictions ); |
---|
126 | // link to the category permission management |
---|
127 | $url = './admin.php?page=cat_perm&cat_id='.$row['id']; |
---|
128 | $vtp->setVar( $sub, 'category.cat_perm_link', add_session_id( $url ) ); |
---|
129 | // color of the category : green if the user is allowed by himself or |
---|
130 | // thanks to a group he belongs to |
---|
131 | if ( $is_user_allowed == 0 or count( $authorized_groups ) > 0 ) |
---|
132 | { |
---|
133 | $vtp->setVar( $sub, 'category.color', 'green' ); |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | $vtp->setVar( $sub, 'category.color', 'red' ); |
---|
138 | } |
---|
139 | // category name |
---|
140 | $cat_infos = get_cat_info( $row['id'] ); |
---|
141 | $name = get_cat_display_name( $cat_infos['name'],' > ', |
---|
142 | 'font-weight:bold;' ); |
---|
143 | $vtp->setVar( $sub, 'category.name', $name ); |
---|
144 | // usergroups |
---|
145 | if ( count( $usergroups ) > 0 ) |
---|
146 | { |
---|
147 | $vtp->addSession( $sub, 'usergroups' ); |
---|
148 | foreach ( $usergroups as $i => $usergroup ) { |
---|
149 | $vtp->addSession( $sub, 'usergroup' ); |
---|
150 | $vtp->setVar( $sub, 'usergroup.name', $groups[$usergroup] ); |
---|
151 | $url = './admin.php?page=group_perm&group_id='.$usergroup; |
---|
152 | $vtp->setVar( $sub, 'usergroup.url', add_session_id( $url ) ); |
---|
153 | if ( in_array( $usergroup, $authorized_groups ) ) |
---|
154 | { |
---|
155 | $vtp->setVar( $sub, 'usergroup.color', 'green' ); |
---|
156 | } |
---|
157 | else |
---|
158 | { |
---|
159 | $vtp->setVar( $sub, 'usergroup.color', 'red' ); |
---|
160 | } |
---|
161 | if ( $i < count( $usergroups ) - 1 ) |
---|
162 | { |
---|
163 | $vtp->setVar( $sub, 'usergroup.separation', ',' ); |
---|
164 | } |
---|
165 | $vtp->closeSession( $sub, 'usergroup' ); |
---|
166 | } |
---|
167 | $vtp->closeSession( $sub, 'usergroups' ); |
---|
168 | } |
---|
169 | // any subcat forbidden for this user ? |
---|
170 | if ( $is_user_allowed == 2 ) |
---|
171 | { |
---|
172 | $vtp->addSession( $sub, 'parent_forbidden' ); |
---|
173 | $vtp->closeSession( $sub, 'parent_forbidden' ); |
---|
174 | } |
---|
175 | // personnal forbidden or authorized access ? |
---|
176 | if ( $is_user_allowed == 0 ) |
---|
177 | { |
---|
178 | $vtp->setVar( $sub, 'category.authorized_checked', ' checked="checked"' ); |
---|
179 | } |
---|
180 | else |
---|
181 | { |
---|
182 | $vtp->setVar( $sub, 'category.forbidden_checked', ' checked="checked"' ); |
---|
183 | } |
---|
184 | $vtp->closeSession( $sub, 'category' ); |
---|
185 | } |
---|
186 | //----------------------------------------------------------- sending html code |
---|
187 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
188 | ?> |
---|