[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: 2005-08-17 14:25:38 +0000 (Wed, 17 Aug 2005) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 817 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[815] | 27 | |
---|
[671] | 28 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 29 | { |
---|
[815] | 30 | die ("Hacking attempt!"); |
---|
[671] | 31 | } |
---|
[815] | 32 | include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' ); |
---|
[671] | 33 | |
---|
[815] | 34 | // +-----------------------------------------------------------------------+ |
---|
| 35 | // | variables init | |
---|
| 36 | // +-----------------------------------------------------------------------+ |
---|
| 37 | |
---|
| 38 | if (isset($_GET['group_id']) and is_numeric($_GET['group_id'])) |
---|
| 39 | { |
---|
| 40 | $page['group'] = $_GET['group_id']; |
---|
| 41 | } |
---|
| 42 | else |
---|
| 43 | { |
---|
| 44 | echo l10n('group_id URL parameter is missing'); |
---|
| 45 | exit(); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | // +-----------------------------------------------------------------------+ |
---|
| 49 | // | updates | |
---|
| 50 | // +-----------------------------------------------------------------------+ |
---|
| 51 | |
---|
[671] | 52 | if (isset($_POST['falsify']) |
---|
[815] | 53 | and isset($_POST['cat_true']) |
---|
| 54 | and count($_POST['cat_true']) > 0) |
---|
[21] | 55 | { |
---|
[671] | 56 | // if you forbid access to a category, all sub-categories become |
---|
| 57 | // automatically forbidden |
---|
| 58 | $subcats = get_subcat_ids($_POST['cat_true']); |
---|
[815] | 59 | $query = ' |
---|
| 60 | DELETE |
---|
| 61 | FROM '.GROUP_ACCESS_TABLE.' |
---|
| 62 | WHERE group_id = '.$page['group'].' |
---|
| 63 | AND cat_id IN ('.implode(',', $subcats).') |
---|
| 64 | ;'; |
---|
[671] | 65 | pwg_query($query); |
---|
| 66 | } |
---|
| 67 | else if (isset($_POST['trueify']) |
---|
| 68 | and isset($_POST['cat_false']) |
---|
| 69 | and count($_POST['cat_false']) > 0) |
---|
| 70 | { |
---|
| 71 | $uppercats = get_uppercat_ids($_POST['cat_false']); |
---|
| 72 | $private_uppercats = array(); |
---|
| 73 | |
---|
[815] | 74 | $query = ' |
---|
| 75 | SELECT id |
---|
| 76 | FROM '.CATEGORIES_TABLE.' |
---|
| 77 | WHERE id IN ('.implode(',', $uppercats).') |
---|
| 78 | AND status = \'private\' |
---|
| 79 | ;'; |
---|
[671] | 80 | $result = pwg_query($query); |
---|
| 81 | while ($row = mysql_fetch_array($result)) |
---|
[21] | 82 | { |
---|
[671] | 83 | array_push($private_uppercats, $row['id']); |
---|
[21] | 84 | } |
---|
[671] | 85 | |
---|
| 86 | // retrying to authorize a category which is already authorized may cause |
---|
| 87 | // an error (in SQL statement), so we need to know which categories are |
---|
| 88 | // accesible |
---|
| 89 | $authorized_ids = array(); |
---|
| 90 | |
---|
[815] | 91 | $query = ' |
---|
| 92 | SELECT cat_id |
---|
[671] | 93 | FROM '.GROUP_ACCESS_TABLE.' |
---|
[815] | 94 | WHERE group_id = '.$page['group'].' |
---|
| 95 | ;'; |
---|
[671] | 96 | $result = pwg_query($query); |
---|
| 97 | |
---|
| 98 | while ($row = mysql_fetch_array($result)) |
---|
[170] | 99 | { |
---|
[671] | 100 | array_push($authorized_ids, $row['cat_id']); |
---|
[170] | 101 | } |
---|
[671] | 102 | |
---|
| 103 | $inserts = array(); |
---|
| 104 | $to_autorize_ids = array_diff($private_uppercats, $authorized_ids); |
---|
| 105 | foreach ($to_autorize_ids as $to_autorize_id) |
---|
| 106 | { |
---|
[815] | 107 | array_push( |
---|
| 108 | $inserts, |
---|
| 109 | array( |
---|
| 110 | 'group_id' => $page['group'], |
---|
| 111 | 'cat_id' => $to_autorize_id |
---|
| 112 | ) |
---|
| 113 | ); |
---|
[671] | 114 | } |
---|
| 115 | |
---|
| 116 | mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts); |
---|
[21] | 117 | } |
---|
[671] | 118 | |
---|
[815] | 119 | // +-----------------------------------------------------------------------+ |
---|
| 120 | // | template init | |
---|
| 121 | // +-----------------------------------------------------------------------+ |
---|
[671] | 122 | |
---|
[817] | 123 | $template->set_filenames( |
---|
| 124 | array( |
---|
| 125 | 'group_perm' => 'admin/group_perm.tpl', |
---|
| 126 | 'double_select' => 'admin/double_select.tpl' |
---|
| 127 | ) |
---|
| 128 | ); |
---|
[671] | 129 | |
---|
[815] | 130 | $template->assign_vars( |
---|
| 131 | array( |
---|
[817] | 132 | 'TITLE' => |
---|
| 133 | sprintf( |
---|
| 134 | l10n('Manage permissions for group "%s"'), |
---|
| 135 | get_groupname($page['group'] |
---|
| 136 | ) |
---|
| 137 | ), |
---|
[815] | 138 | 'L_CAT_OPTIONS_TRUE'=>$lang['authorized'], |
---|
| 139 | 'L_CAT_OPTIONS_FALSE'=>$lang['forbidden'], |
---|
| 140 | 'L_CAT_OPTIONS_INFO'=>$lang['permuser_info'], |
---|
| 141 | |
---|
| 142 | 'F_ACTION' => |
---|
[817] | 143 | add_session_id( |
---|
| 144 | PHPWG_ROOT_PATH. |
---|
| 145 | 'admin.php?page=group_perm&group_id='. |
---|
| 146 | $page['group'] |
---|
| 147 | ) |
---|
[815] | 148 | ) |
---|
| 149 | ); |
---|
[671] | 150 | |
---|
[815] | 151 | // only private categories are listed |
---|
| 152 | $query_true = ' |
---|
[671] | 153 | SELECT id,name,uppercats,global_rank |
---|
| 154 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.GROUP_ACCESS_TABLE.' ON cat_id = id |
---|
| 155 | WHERE status = \'private\' |
---|
[815] | 156 | AND group_id = '.$page['group'].' |
---|
[671] | 157 | ;'; |
---|
[815] | 158 | display_select_cat_wrapper($query_true,array(),'category_option_true'); |
---|
| 159 | |
---|
| 160 | $result = pwg_query($query_true); |
---|
| 161 | $authorized_ids = array(); |
---|
| 162 | while ($row = mysql_fetch_array($result)) |
---|
| 163 | { |
---|
| 164 | array_push($authorized_ids, $row['id']); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | $query_false = ' |
---|
[671] | 168 | SELECT id,name,uppercats,global_rank |
---|
| 169 | FROM '.CATEGORIES_TABLE.' |
---|
| 170 | WHERE status = \'private\''; |
---|
[815] | 171 | if (count($authorized_ids) > 0) |
---|
| 172 | { |
---|
| 173 | $query_false.= ' |
---|
[671] | 174 | AND id NOT IN ('.implode(',', $authorized_ids).')'; |
---|
[815] | 175 | } |
---|
| 176 | $query_false.= ' |
---|
[671] | 177 | ;'; |
---|
[815] | 178 | display_select_cat_wrapper($query_false,array(),'category_option_false'); |
---|
[671] | 179 | |
---|
[815] | 180 | // +-----------------------------------------------------------------------+ |
---|
| 181 | // | html code display | |
---|
| 182 | // +-----------------------------------------------------------------------+ |
---|
| 183 | |
---|
[817] | 184 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
[815] | 185 | $template->assign_var_from_handle('ADMIN_CONTENT', 'group_perm'); |
---|
| 186 | |
---|
[362] | 187 | ?> |
---|