[21] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[675] | 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[362] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[362] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2006-03-22 01:01:47 +0000 (Wed, 22 Mar 2006) $ |
---|
| 10 | // | last modifier : $Author: rvelices $ |
---|
| 11 | // | revision : $Revision: 1092 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[393] | 27 | |
---|
[657] | 28 | if (!defined('IN_ADMIN')) |
---|
[393] | 29 | { |
---|
[657] | 30 | die('Hacking attempt!'); |
---|
[393] | 31 | } |
---|
| 32 | |
---|
[1072] | 33 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 34 | |
---|
[815] | 35 | // +-----------------------------------------------------------------------+ |
---|
[1072] | 36 | // | Check Access and exit when user status is not ok | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 39 | |
---|
| 40 | // +-----------------------------------------------------------------------+ |
---|
[815] | 41 | // | variables init | |
---|
| 42 | // +-----------------------------------------------------------------------+ |
---|
| 43 | |
---|
| 44 | if (isset($_GET['user_id']) and is_numeric($_GET['user_id'])) |
---|
[393] | 45 | { |
---|
[815] | 46 | $page['user'] = $_GET['user_id']; |
---|
[393] | 47 | } |
---|
[815] | 48 | else |
---|
[709] | 49 | { |
---|
[815] | 50 | echo l10n('user_id URL parameter is missing'); |
---|
| 51 | exit(); |
---|
[709] | 52 | } |
---|
[815] | 53 | |
---|
| 54 | // +-----------------------------------------------------------------------+ |
---|
| 55 | // | updates | |
---|
| 56 | // +-----------------------------------------------------------------------+ |
---|
| 57 | |
---|
| 58 | if (isset($_POST['falsify']) |
---|
| 59 | and isset($_POST['cat_true']) |
---|
| 60 | and count($_POST['cat_true']) > 0) |
---|
[393] | 61 | { |
---|
[657] | 62 | // if you forbid access to a category, all sub-categories become |
---|
| 63 | // automatically forbidden |
---|
| 64 | $subcats = get_subcat_ids($_POST['cat_true']); |
---|
| 65 | $query = ' |
---|
| 66 | DELETE FROM '.USER_ACCESS_TABLE.' |
---|
[815] | 67 | WHERE user_id = '.$page['user'].' |
---|
[657] | 68 | AND cat_id IN ('.implode(',', $subcats).') |
---|
| 69 | ;'; |
---|
| 70 | pwg_query($query); |
---|
| 71 | } |
---|
| 72 | else if (isset($_POST['trueify']) |
---|
| 73 | and isset($_POST['cat_false']) |
---|
| 74 | and count($_POST['cat_false']) > 0) |
---|
| 75 | { |
---|
| 76 | $uppercats = get_uppercat_ids($_POST['cat_false']); |
---|
| 77 | $private_uppercats = array(); |
---|
| 78 | |
---|
| 79 | $query = ' |
---|
| 80 | SELECT id |
---|
| 81 | FROM '.CATEGORIES_TABLE.' |
---|
| 82 | WHERE id IN ('.implode(',', $uppercats).') |
---|
| 83 | AND status = \'private\' |
---|
| 84 | ;'; |
---|
| 85 | $result = pwg_query($query); |
---|
| 86 | while ($row = mysql_fetch_array($result)) |
---|
[21] | 87 | { |
---|
[657] | 88 | array_push($private_uppercats, $row['id']); |
---|
[655] | 89 | } |
---|
[657] | 90 | |
---|
| 91 | // retrying to authorize a category which is already authorized may cause |
---|
| 92 | // an error (in SQL statement), so we need to know which categories are |
---|
| 93 | // accesible |
---|
| 94 | $authorized_ids = array(); |
---|
[1092] | 95 | |
---|
[657] | 96 | $query = ' |
---|
| 97 | SELECT cat_id |
---|
| 98 | FROM '.USER_ACCESS_TABLE.' |
---|
[815] | 99 | WHERE user_id = '.$page['user'].' |
---|
[657] | 100 | ;'; |
---|
| 101 | $result = pwg_query($query); |
---|
[1092] | 102 | |
---|
[657] | 103 | while ($row = mysql_fetch_array($result)) |
---|
[655] | 104 | { |
---|
[657] | 105 | array_push($authorized_ids, $row['cat_id']); |
---|
[21] | 106 | } |
---|
[1092] | 107 | |
---|
[657] | 108 | $inserts = array(); |
---|
| 109 | $to_autorize_ids = array_diff($private_uppercats, $authorized_ids); |
---|
| 110 | foreach ($to_autorize_ids as $to_autorize_id) |
---|
| 111 | { |
---|
[815] | 112 | array_push($inserts, array('user_id' => $page['user'], |
---|
[657] | 113 | 'cat_id' => $to_autorize_id)); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $inserts); |
---|
[21] | 117 | } |
---|
[655] | 118 | |
---|
[817] | 119 | // +-----------------------------------------------------------------------+ |
---|
| 120 | // | template init | |
---|
| 121 | // +-----------------------------------------------------------------------+ |
---|
| 122 | |
---|
| 123 | $template->set_filenames( |
---|
| 124 | array( |
---|
| 125 | 'user_perm' => 'admin/user_perm.tpl', |
---|
| 126 | 'double_select' => 'admin/double_select.tpl' |
---|
| 127 | ) |
---|
| 128 | ); |
---|
| 129 | |
---|
[815] | 130 | $template->assign_vars( |
---|
| 131 | array( |
---|
[817] | 132 | 'TITLE' => |
---|
| 133 | sprintf( |
---|
| 134 | l10n('Manage permissions for user "%s"'), |
---|
| 135 | get_username($page['user'] |
---|
| 136 | ) |
---|
| 137 | ), |
---|
[815] | 138 | 'L_CAT_OPTIONS_TRUE'=>$lang['authorized'], |
---|
| 139 | 'L_CAT_OPTIONS_FALSE'=>$lang['forbidden'], |
---|
[1092] | 140 | |
---|
[815] | 141 | 'F_ACTION' => |
---|
| 142 | PHPWG_ROOT_PATH. |
---|
| 143 | 'admin.php?page=user_perm'. |
---|
| 144 | '&user_id='.$page['user'] |
---|
| 145 | ) |
---|
| 146 | ); |
---|
[655] | 147 | |
---|
[818] | 148 | |
---|
| 149 | // retrieve category ids authorized to the groups the user belongs to |
---|
| 150 | $group_authorized = array(); |
---|
| 151 | |
---|
| 152 | $query = ' |
---|
| 153 | SELECT DISTINCT cat_id, c.uppercats, c.global_rank |
---|
| 154 | FROM '.USER_GROUP_TABLE.' AS ug |
---|
| 155 | INNER JOIN '.GROUP_ACCESS_TABLE.' AS ga |
---|
| 156 | ON ug.group_id = ga.group_id |
---|
| 157 | INNER JOIN '.CATEGORIES_TABLE.' AS c |
---|
| 158 | ON c.id = ga.cat_id |
---|
| 159 | WHERE ug.user_id = '.$page['user'].' |
---|
| 160 | ;'; |
---|
| 161 | $result = pwg_query($query); |
---|
| 162 | |
---|
| 163 | if (mysql_num_rows($result) > 0) |
---|
| 164 | { |
---|
| 165 | $template->assign_block_vars('groups', array()); |
---|
| 166 | |
---|
| 167 | $cats = array(); |
---|
| 168 | while ($row = mysql_fetch_array($result)) |
---|
| 169 | { |
---|
| 170 | array_push($cats, $row); |
---|
| 171 | array_push($group_authorized, $row['cat_id']); |
---|
| 172 | } |
---|
| 173 | usort($cats, 'global_rank_compare'); |
---|
| 174 | |
---|
| 175 | foreach ($cats as $category) |
---|
| 176 | { |
---|
| 177 | $template->assign_block_vars( |
---|
| 178 | 'groups.category', |
---|
| 179 | array( |
---|
[1092] | 180 | 'NAME' => get_cat_display_name_cache($category['uppercats'], null, false) |
---|
[818] | 181 | ) |
---|
| 182 | ); |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
[815] | 186 | // only private categories are listed |
---|
| 187 | $query_true = ' |
---|
[657] | 188 | SELECT id,name,uppercats,global_rank |
---|
| 189 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_ACCESS_TABLE.' ON cat_id = id |
---|
| 190 | WHERE status = \'private\' |
---|
[818] | 191 | AND user_id = '.$page['user']; |
---|
| 192 | if (count($group_authorized) > 0) |
---|
| 193 | { |
---|
| 194 | $query_true.= ' |
---|
| 195 | AND cat_id NOT IN ('.implode(',', $group_authorized).')'; |
---|
| 196 | } |
---|
| 197 | $query_true.= ' |
---|
[657] | 198 | ;'; |
---|
[815] | 199 | display_select_cat_wrapper($query_true,array(),'category_option_true'); |
---|
[1092] | 200 | |
---|
[815] | 201 | $result = pwg_query($query_true); |
---|
| 202 | $authorized_ids = array(); |
---|
| 203 | while ($row = mysql_fetch_array($result)) |
---|
| 204 | { |
---|
| 205 | array_push($authorized_ids, $row['id']); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | $query_false = ' |
---|
[657] | 209 | SELECT id,name,uppercats,global_rank |
---|
| 210 | FROM '.CATEGORIES_TABLE.' |
---|
| 211 | WHERE status = \'private\''; |
---|
[815] | 212 | if (count($authorized_ids) > 0) |
---|
| 213 | { |
---|
| 214 | $query_false.= ' |
---|
[657] | 215 | AND id NOT IN ('.implode(',', $authorized_ids).')'; |
---|
[815] | 216 | } |
---|
[818] | 217 | if (count($group_authorized) > 0) |
---|
| 218 | { |
---|
| 219 | $query_false.= ' |
---|
| 220 | AND id NOT IN ('.implode(',', $group_authorized).')'; |
---|
| 221 | } |
---|
[815] | 222 | $query_false.= ' |
---|
[657] | 223 | ;'; |
---|
[815] | 224 | display_select_cat_wrapper($query_false,array(),'category_option_false'); |
---|
| 225 | |
---|
[817] | 226 | // +-----------------------------------------------------------------------+ |
---|
| 227 | // | sending html code | |
---|
| 228 | // +-----------------------------------------------------------------------+ |
---|
[815] | 229 | |
---|
[817] | 230 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
[815] | 231 | $template->assign_var_from_handle('ADMIN_CONTENT', 'user_perm'); |
---|
[362] | 232 | ?> |
---|