1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * cat_perm.php * |
---|
4 | * ------------------ * |
---|
5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | * $Id: cat_perm.php 256 2004-01-03 21:30:55Z z0rglub $ |
---|
9 | * * |
---|
10 | ***************************************************************************/ |
---|
11 | |
---|
12 | /*************************************************************************** |
---|
13 | * * |
---|
14 | * This program is free software; you can redistribute it and/or modify * |
---|
15 | * it under the terms of the GNU General Public License as published by * |
---|
16 | * the Free Software Foundation; * |
---|
17 | * * |
---|
18 | ***************************************************************************/ |
---|
19 | include_once( './include/isadmin.inc.php' ); |
---|
20 | //----------------------------------------------------- template initialization |
---|
21 | $sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_perm.vtp' ); |
---|
22 | $error = array(); |
---|
23 | $tpl = array( 'permuser_authorized','permuser_forbidden','menu_groups', |
---|
24 | 'submit','menu_users','permuser_parent_forbidden' ); |
---|
25 | templatize_array( $tpl, 'lang', $sub ); |
---|
26 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
27 | //-------------------------------------------------------------- category infos |
---|
28 | if ( isset( $_GET['cat_id'] ) ) |
---|
29 | { |
---|
30 | check_cat_id( $_GET['cat_id'] ); |
---|
31 | if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) |
---|
32 | { |
---|
33 | $result = get_cat_info( $page['cat'] ); |
---|
34 | $page['cat_name'] = $result['name']; |
---|
35 | $page['id_uppercat'] = $result['id_uppercat']; |
---|
36 | } |
---|
37 | } |
---|
38 | //---------------------------------------------------------- permission updates |
---|
39 | if ( isset( $_POST['submit'] ) ) |
---|
40 | { |
---|
41 | // groups access update |
---|
42 | $query = 'DELETE'; |
---|
43 | $query.= ' FROM '.PREFIX_TABLE.'group_access'; |
---|
44 | $query.= ' WHERE cat_id = '.$page['cat']; |
---|
45 | $query.= ';'; |
---|
46 | mysql_query( $query ); |
---|
47 | $query = 'SELECT id'; |
---|
48 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
49 | $query.= ';'; |
---|
50 | $result = mysql_query( $query ); |
---|
51 | while ( $row = mysql_fetch_array( $result ) ) |
---|
52 | { |
---|
53 | $radioname = 'groupaccess-'.$row['id']; |
---|
54 | if ( $_POST[$radioname] == 0 ) |
---|
55 | { |
---|
56 | $query = 'INSERT INTO '.PREFIX_TABLE.'group_access'; |
---|
57 | $query.= ' (cat_id,group_id) VALUES'; |
---|
58 | $query.= ' ('.$page['cat'].','.$row['id'].')'; |
---|
59 | $query.= ';'; |
---|
60 | mysql_query( $query ); |
---|
61 | } |
---|
62 | } |
---|
63 | // users access update |
---|
64 | $query = 'DELETE'; |
---|
65 | $query.= ' FROM '.PREFIX_TABLE.'user_access'; |
---|
66 | $query.= ' WHERE cat_id = '.$page['cat']; |
---|
67 | $query.= ';'; |
---|
68 | mysql_query( $query ); |
---|
69 | $query = 'SELECT id'; |
---|
70 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
71 | $query.= ';'; |
---|
72 | $result = mysql_query( $query ); |
---|
73 | while ( $row = mysql_fetch_array( $result ) ) |
---|
74 | { |
---|
75 | $radioname = 'useraccess-'.$row['id']; |
---|
76 | if ( $_POST[$radioname] == 0 ) |
---|
77 | { |
---|
78 | $query = 'INSERT INTO '.PREFIX_TABLE.'user_access'; |
---|
79 | $query.= ' (cat_id,user_id) VALUES'; |
---|
80 | $query.= ' ('.$page['cat'].','.$row['id'].')'; |
---|
81 | $query.= ';'; |
---|
82 | mysql_query( $query ); |
---|
83 | } |
---|
84 | check_favorites( $row['id'] ); |
---|
85 | } |
---|
86 | // resynchronize all users |
---|
87 | synchronize_all_users(); |
---|
88 | } |
---|
89 | //---------------------------------------------------------------------- groups |
---|
90 | $query = 'SELECT id,name'; |
---|
91 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
92 | $query. ';'; |
---|
93 | $result = mysql_query( $query ); |
---|
94 | if ( mysql_num_rows( $result ) > 0 ) |
---|
95 | { |
---|
96 | $vtp->addSession( $sub, 'groups' ); |
---|
97 | // creating an array with all authorized groups for this category |
---|
98 | $query = 'SELECT group_id'; |
---|
99 | $query.= ' FROM '.PREFIX_TABLE.'group_access'; |
---|
100 | $query.= ' WHERE cat_id = '.$_GET['cat_id']; |
---|
101 | $query.= ';'; |
---|
102 | $subresult = mysql_query( $query ); |
---|
103 | $authorized_groups = array(); |
---|
104 | while ( $subrow = mysql_fetch_array( $subresult ) ) |
---|
105 | { |
---|
106 | array_push( $authorized_groups, $subrow['group_id'] ); |
---|
107 | } |
---|
108 | // displaying each group |
---|
109 | while( $row = mysql_fetch_array( $result ) ) |
---|
110 | { |
---|
111 | $vtp->addSession( $sub, 'group' ); |
---|
112 | if ( in_array( $row['id'], $authorized_groups ) ) |
---|
113 | { |
---|
114 | $vtp->setVar( $sub, 'group.color', 'green' ); |
---|
115 | $vtp->setVar( $sub, 'group.authorized_checked', ' checked="checked"' ); |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | $vtp->setVar( $sub, 'group.color', 'red' ); |
---|
120 | $vtp->setVar( $sub, 'group.forbidden_checked', ' checked="checked"' ); |
---|
121 | } |
---|
122 | $vtp->setVar( $sub, 'group.groupname', $row['name'] ); |
---|
123 | $vtp->setVar( $sub, 'group.id', $row['id'] ); |
---|
124 | $url = './admin.php?page=group_perm&group_id='.$row['id']; |
---|
125 | $vtp->setVar( $sub, 'group.group_perm_link', add_session_id( $url ) ); |
---|
126 | $vtp->closeSession( $sub, 'group' ); |
---|
127 | } |
---|
128 | $vtp->closeSession( $sub, 'groups' ); |
---|
129 | } |
---|
130 | //----------------------------------------------------------------------- users |
---|
131 | $query = 'SELECT id,username,status'; |
---|
132 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
133 | // only the webmaster can modify webmaster's permissions |
---|
134 | if ( $user['username'] != $conf['webmaster'] ) |
---|
135 | { |
---|
136 | $query.= " WHERE username != '".$conf['webmaster']."'"; |
---|
137 | } |
---|
138 | $query.= ';'; |
---|
139 | $result = mysql_query( $query ); |
---|
140 | while ( $row = mysql_fetch_array( $result ) ) |
---|
141 | { |
---|
142 | $vtp->addSession( $sub, 'user' ); |
---|
143 | $vtp->setVar( $sub, 'user.id', $row['id'] ); |
---|
144 | $url = add_session_id( './admin.php?page=user_perm&user_id='.$row['id']); |
---|
145 | $vtp->setVar( $sub, 'user.user_perm_link', $url); |
---|
146 | if ( $row['username'] == 'guest' ) |
---|
147 | { |
---|
148 | $row['username'] = $lang['guest']; |
---|
149 | } |
---|
150 | $vtp->setVar( $sub, 'user.username', $row['username'] ); |
---|
151 | |
---|
152 | // for color of user : (red means access forbidden, green authorized) we |
---|
153 | // ask all forbidden categories, including the groups rights |
---|
154 | $restrictions = get_restrictions( $row['id'], $row['status'], false ); |
---|
155 | $is_user_allowed = is_user_allowed( $page['cat'], $restrictions ); |
---|
156 | if ( $is_user_allowed == 0 ) |
---|
157 | { |
---|
158 | $vtp->setVar( $sub, 'user.color', 'green' ); |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | $vtp->setVar( $sub, 'user.color', 'red' ); |
---|
163 | } |
---|
164 | // for permission update button, we only ask forbidden categories for the |
---|
165 | // user, not taking into account the groups the user belongs to |
---|
166 | $restrictions = get_restrictions( $row['id'], $row['status'], false, false ); |
---|
167 | $is_user_allowed = is_user_allowed( $page['cat'], $restrictions ); |
---|
168 | if ( $is_user_allowed == 2 ) |
---|
169 | { |
---|
170 | $vtp->addSession( $sub, 'parent_forbidden' ); |
---|
171 | $url = './admin.php?page=cat_perm&cat_id='.$page['id_uppercat']; |
---|
172 | $vtp->setVar( $sub, 'parent_forbidden.url', add_session_id( $url ) ); |
---|
173 | $vtp->closeSession( $sub, 'parent_forbidden' ); |
---|
174 | } |
---|
175 | if ( $is_user_allowed == 0 ) |
---|
176 | { |
---|
177 | $vtp->setVar( $sub, 'user.authorized_checked', ' checked="checked"' ); |
---|
178 | } |
---|
179 | else |
---|
180 | { |
---|
181 | $vtp->setVar( $sub, 'user.forbidden_checked', ' checked="checked"' ); |
---|
182 | } |
---|
183 | // user's group(s) |
---|
184 | $query = 'SELECT g.name as groupname, g.id as groupid'; |
---|
185 | $query.= ' FROM '.PREFIX_TABLE.'groups as g'; |
---|
186 | $query.= ', '.PREFIX_TABLE.'user_group as ug'; |
---|
187 | $query.= ' WHERE ug.group_id = g.id'; |
---|
188 | $query.= ' AND ug.user_id = '.$row['id']; |
---|
189 | $query.= ';'; |
---|
190 | $subresult = mysql_query( $query ); |
---|
191 | if ( mysql_num_rows( $subresult ) > 0 ) |
---|
192 | { |
---|
193 | $vtp->addSession( $sub, 'usergroups' ); |
---|
194 | $i = 0; |
---|
195 | while( $subrow = mysql_fetch_array( $subresult ) ) |
---|
196 | { |
---|
197 | $vtp->addSession( $sub, 'usergroup' ); |
---|
198 | if ( in_array( $subrow['groupid'], $authorized_groups ) ) |
---|
199 | { |
---|
200 | $vtp->setVar( $sub, 'usergroup.color', 'green' ); |
---|
201 | } |
---|
202 | else |
---|
203 | { |
---|
204 | $vtp->setVar( $sub, 'usergroup.color', 'red' ); |
---|
205 | } |
---|
206 | $vtp->setVar( $sub, 'usergroup.name', $subrow['groupname'] ); |
---|
207 | if ( $i < mysql_num_rows( $subresult ) - 1 ) |
---|
208 | { |
---|
209 | $vtp->setVar( $sub, 'usergroup.separation', ',' ); |
---|
210 | } |
---|
211 | $vtp->closeSession( $sub, 'usergroup' ); |
---|
212 | $i++; |
---|
213 | } |
---|
214 | $vtp->closeSession( $sub, 'usergroups' ); |
---|
215 | } |
---|
216 | $vtp->closeSession( $sub, 'user' ); |
---|
217 | } |
---|
218 | //----------------------------------------------------------- sending html code |
---|
219 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
220 | ?> |
---|