[21] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
| 3 | * cat_perm.php * |
---|
| 4 | * ------------------ * |
---|
[57] | 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[21] | 7 | * * |
---|
[57] | 8 | * $Id: cat_perm.php 103 2003-09-14 16:06:31Z z0rglub $ |
---|
| 9 | * * |
---|
[21] | 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 ); |
---|
[29] | 26 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
[21] | 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 | // echo "<div class=\"info\">".$lang['permuser_info_message']." [ <a href=\"".add_session_id_to_url( "./admin.php?page=cat" )."\">".$lang['editcat_back']."</a> ]</div>"; |
---|
| 87 | } |
---|
| 88 | //---------------------------------------------------------------------- groups |
---|
| 89 | $query = 'SELECT id,name'; |
---|
| 90 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
| 91 | $query. ';'; |
---|
| 92 | $result = mysql_query( $query ); |
---|
| 93 | if ( mysql_num_rows( $result ) > 0 ) |
---|
| 94 | { |
---|
| 95 | $vtp->addSession( $sub, 'groups' ); |
---|
| 96 | // creating an array with all authorized groups for this category |
---|
| 97 | $query = 'SELECT group_id'; |
---|
| 98 | $query.= ' FROM '.PREFIX_TABLE.'group_access'; |
---|
| 99 | $query.= ' WHERE cat_id = '.$_GET['cat_id']; |
---|
| 100 | $query.= ';'; |
---|
| 101 | $subresult = mysql_query( $query ); |
---|
| 102 | $authorized_groups = array(); |
---|
| 103 | while ( $subrow = mysql_fetch_array( $subresult ) ) |
---|
| 104 | { |
---|
| 105 | array_push( $authorized_groups, $subrow['group_id'] ); |
---|
| 106 | } |
---|
| 107 | // displaying each group |
---|
| 108 | while( $row = mysql_fetch_array( $result ) ) |
---|
| 109 | { |
---|
| 110 | $vtp->addSession( $sub, 'group' ); |
---|
| 111 | if ( in_array( $row['id'], $authorized_groups ) ) |
---|
| 112 | { |
---|
| 113 | $vtp->setVar( $sub, 'group.color', 'green' ); |
---|
| 114 | $vtp->setVar( $sub, 'group.authorized_checked', ' checked="checked"' ); |
---|
| 115 | } |
---|
| 116 | else |
---|
| 117 | { |
---|
| 118 | $vtp->setVar( $sub, 'group.color', 'red' ); |
---|
| 119 | $vtp->setVar( $sub, 'group.forbidden_checked', ' checked="checked"' ); |
---|
| 120 | } |
---|
| 121 | $vtp->setVar( $sub, 'group.groupname', $row['name'] ); |
---|
| 122 | $vtp->setVar( $sub, 'group.id', $row['id'] ); |
---|
[103] | 123 | $url = './admin.php?page=group_perm&group_id='.$row['id']; |
---|
| 124 | $vtp->setVar( $sub, 'group.group_perm_link', add_session_id( $url ) ); |
---|
[21] | 125 | $vtp->closeSession( $sub, 'group' ); |
---|
| 126 | } |
---|
| 127 | $vtp->closeSession( $sub, 'groups' ); |
---|
| 128 | } |
---|
| 129 | //----------------------------------------------------------------------- users |
---|
| 130 | $query = 'SELECT id,username,status'; |
---|
| 131 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
| 132 | $query.= " WHERE username != '".$conf['webmaster']."'"; |
---|
| 133 | $query.= ';'; |
---|
| 134 | $result = mysql_query( $query ); |
---|
| 135 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 136 | { |
---|
| 137 | $vtp->addSession( $sub, 'user' ); |
---|
| 138 | $vtp->setVar( $sub, 'user.id', $row['id'] ); |
---|
| 139 | $url = add_session_id( './admin.php?page=user_perm&user_id='.$row['id']); |
---|
| 140 | $vtp->setVar( $sub, 'user.user_perm_link', $url); |
---|
| 141 | if ( $row['username'] == 'guest' ) |
---|
| 142 | { |
---|
| 143 | $row['username'] = $lang['guest']; |
---|
| 144 | } |
---|
| 145 | $vtp->setVar( $sub, 'user.username', $row['username'] ); |
---|
| 146 | |
---|
| 147 | // for color of user : (red means access forbidden, green authorized) we |
---|
| 148 | // ask all forbidden categories, including the groups rights |
---|
| 149 | $restrictions = get_restrictions( $row['id'], $row['status'], false ); |
---|
| 150 | $is_user_allowed = is_user_allowed( $page['cat'], $restrictions ); |
---|
| 151 | if ( $is_user_allowed == 0 ) |
---|
| 152 | { |
---|
| 153 | $vtp->setVar( $sub, 'user.color', 'green' ); |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | $vtp->setVar( $sub, 'user.color', 'red' ); |
---|
| 158 | } |
---|
| 159 | // for permission update button, we only ask forbidden categories for the |
---|
| 160 | // user, not taking into account the groups the user belongs to |
---|
| 161 | $restrictions = get_restrictions( $row['id'], $row['status'], false, false ); |
---|
| 162 | $is_user_allowed = is_user_allowed( $page['cat'], $restrictions ); |
---|
| 163 | if ( $is_user_allowed == 2 ) |
---|
| 164 | { |
---|
| 165 | $vtp->addSession( $sub, 'parent_forbidden' ); |
---|
| 166 | $url = './admin.php?page=cat_perm&cat_id='.$page['id_uppercat']; |
---|
| 167 | $vtp->setVar( $sub, 'parent_forbidden.url', add_session_id( $url ) ); |
---|
| 168 | $vtp->closeSession( $sub, 'parent_forbidden' ); |
---|
| 169 | } |
---|
| 170 | if ( $is_user_allowed == 0 ) |
---|
| 171 | { |
---|
| 172 | $vtp->setVar( $sub, 'user.authorized_checked', ' checked="checked"' ); |
---|
| 173 | } |
---|
| 174 | else |
---|
| 175 | { |
---|
| 176 | $vtp->setVar( $sub, 'user.forbidden_checked', ' checked="checked"' ); |
---|
| 177 | } |
---|
| 178 | // user's group(s) |
---|
| 179 | $query = 'SELECT g.name as groupname, g.id as groupid'; |
---|
| 180 | $query.= ' FROM '.PREFIX_TABLE.'groups as g'; |
---|
| 181 | $query.= ', '.PREFIX_TABLE.'user_group as ug'; |
---|
| 182 | $query.= ' WHERE ug.group_id = g.id'; |
---|
| 183 | $query.= ' AND ug.user_id = '.$row['id']; |
---|
| 184 | $query.= ';'; |
---|
| 185 | $subresult = mysql_query( $query ); |
---|
| 186 | if ( mysql_num_rows( $subresult ) > 0 ) |
---|
| 187 | { |
---|
| 188 | $vtp->addSession( $sub, 'usergroups' ); |
---|
| 189 | $i = 0; |
---|
| 190 | while( $subrow = mysql_fetch_array( $subresult ) ) |
---|
| 191 | { |
---|
| 192 | $vtp->addSession( $sub, 'usergroup' ); |
---|
| 193 | if ( in_array( $subrow['groupid'], $authorized_groups ) ) |
---|
| 194 | { |
---|
| 195 | $vtp->setVar( $sub, 'usergroup.color', 'green' ); |
---|
| 196 | } |
---|
| 197 | else |
---|
| 198 | { |
---|
| 199 | $vtp->setVar( $sub, 'usergroup.color', 'red' ); |
---|
| 200 | } |
---|
| 201 | $vtp->setVar( $sub, 'usergroup.name', $subrow['groupname'] ); |
---|
| 202 | if ( $i < mysql_num_rows( $subresult ) - 1 ) |
---|
| 203 | { |
---|
| 204 | $vtp->setVar( $sub, 'usergroup.separation', ',' ); |
---|
| 205 | } |
---|
| 206 | $vtp->closeSession( $sub, 'usergroup' ); |
---|
| 207 | $i++; |
---|
| 208 | } |
---|
| 209 | $vtp->closeSession( $sub, 'usergroups' ); |
---|
| 210 | } |
---|
| 211 | $vtp->closeSession( $sub, 'user' ); |
---|
| 212 | } |
---|
| 213 | //----------------------------------------------------------- sending html code |
---|
| 214 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
| 215 | ?> |
---|