1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1900 $ |
---|
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 | |
---|
28 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
29 | { |
---|
30 | die ("Hacking attempt!"); |
---|
31 | } |
---|
32 | |
---|
33 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | check_status(ACCESS_ADMINISTRATOR); |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | variables init | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | |
---|
44 | if (isset($_GET['group_id']) and is_numeric($_GET['group_id'])) |
---|
45 | { |
---|
46 | $page['group'] = $_GET['group_id']; |
---|
47 | } |
---|
48 | else |
---|
49 | { |
---|
50 | echo l10n('group_id URL parameter is missing'); |
---|
51 | exit(); |
---|
52 | } |
---|
53 | |
---|
54 | // +-----------------------------------------------------------------------+ |
---|
55 | // | updates | |
---|
56 | // +-----------------------------------------------------------------------+ |
---|
57 | |
---|
58 | if (isset($_POST['falsify']) |
---|
59 | and isset($_POST['cat_true']) |
---|
60 | and count($_POST['cat_true']) > 0) |
---|
61 | { |
---|
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 |
---|
67 | FROM '.GROUP_ACCESS_TABLE.' |
---|
68 | WHERE group_id = '.$page['group'].' |
---|
69 | AND cat_id IN ('.implode(',', $subcats).') |
---|
70 | ;'; |
---|
71 | pwg_query($query); |
---|
72 | } |
---|
73 | else if (isset($_POST['trueify']) |
---|
74 | and isset($_POST['cat_false']) |
---|
75 | and count($_POST['cat_false']) > 0) |
---|
76 | { |
---|
77 | $uppercats = get_uppercat_ids($_POST['cat_false']); |
---|
78 | $private_uppercats = array(); |
---|
79 | |
---|
80 | $query = ' |
---|
81 | SELECT id |
---|
82 | FROM '.CATEGORIES_TABLE.' |
---|
83 | WHERE id IN ('.implode(',', $uppercats).') |
---|
84 | AND status = \'private\' |
---|
85 | ;'; |
---|
86 | $result = pwg_query($query); |
---|
87 | while ($row = mysql_fetch_array($result)) |
---|
88 | { |
---|
89 | array_push($private_uppercats, $row['id']); |
---|
90 | } |
---|
91 | |
---|
92 | // retrying to authorize a category which is already authorized may cause |
---|
93 | // an error (in SQL statement), so we need to know which categories are |
---|
94 | // accesible |
---|
95 | $authorized_ids = array(); |
---|
96 | |
---|
97 | $query = ' |
---|
98 | SELECT cat_id |
---|
99 | FROM '.GROUP_ACCESS_TABLE.' |
---|
100 | WHERE group_id = '.$page['group'].' |
---|
101 | ;'; |
---|
102 | $result = pwg_query($query); |
---|
103 | |
---|
104 | while ($row = mysql_fetch_array($result)) |
---|
105 | { |
---|
106 | array_push($authorized_ids, $row['cat_id']); |
---|
107 | } |
---|
108 | |
---|
109 | $inserts = array(); |
---|
110 | $to_autorize_ids = array_diff($private_uppercats, $authorized_ids); |
---|
111 | foreach ($to_autorize_ids as $to_autorize_id) |
---|
112 | { |
---|
113 | array_push( |
---|
114 | $inserts, |
---|
115 | array( |
---|
116 | 'group_id' => $page['group'], |
---|
117 | 'cat_id' => $to_autorize_id |
---|
118 | ) |
---|
119 | ); |
---|
120 | } |
---|
121 | |
---|
122 | mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts); |
---|
123 | } |
---|
124 | |
---|
125 | // +-----------------------------------------------------------------------+ |
---|
126 | // | template init | |
---|
127 | // +-----------------------------------------------------------------------+ |
---|
128 | |
---|
129 | $template->set_filenames( |
---|
130 | array( |
---|
131 | 'group_perm' => 'admin/group_perm.tpl', |
---|
132 | 'double_select' => 'admin/double_select.tpl' |
---|
133 | ) |
---|
134 | ); |
---|
135 | |
---|
136 | $template->assign_vars( |
---|
137 | array( |
---|
138 | 'TITLE' => |
---|
139 | sprintf( |
---|
140 | l10n('Manage permissions for group "%s"'), |
---|
141 | get_groupname($page['group'] |
---|
142 | ) |
---|
143 | ), |
---|
144 | 'L_CAT_OPTIONS_TRUE'=>$lang['authorized'], |
---|
145 | 'L_CAT_OPTIONS_FALSE'=>$lang['forbidden'], |
---|
146 | 'L_CAT_OPTIONS_INFO'=>$lang['permuser_info'], |
---|
147 | |
---|
148 | 'F_ACTION' => |
---|
149 | PHPWG_ROOT_PATH. |
---|
150 | 'admin.php?page=group_perm&group_id='. |
---|
151 | $page['group'] |
---|
152 | ) |
---|
153 | ); |
---|
154 | |
---|
155 | // only private categories are listed |
---|
156 | $query_true = ' |
---|
157 | SELECT id,name,uppercats,global_rank |
---|
158 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.GROUP_ACCESS_TABLE.' ON cat_id = id |
---|
159 | WHERE status = \'private\' |
---|
160 | AND group_id = '.$page['group'].' |
---|
161 | ;'; |
---|
162 | display_select_cat_wrapper($query_true,array(),'category_option_true'); |
---|
163 | |
---|
164 | $result = pwg_query($query_true); |
---|
165 | $authorized_ids = array(); |
---|
166 | while ($row = mysql_fetch_array($result)) |
---|
167 | { |
---|
168 | array_push($authorized_ids, $row['id']); |
---|
169 | } |
---|
170 | |
---|
171 | $query_false = ' |
---|
172 | SELECT id,name,uppercats,global_rank |
---|
173 | FROM '.CATEGORIES_TABLE.' |
---|
174 | WHERE status = \'private\''; |
---|
175 | if (count($authorized_ids) > 0) |
---|
176 | { |
---|
177 | $query_false.= ' |
---|
178 | AND id NOT IN ('.implode(',', $authorized_ids).')'; |
---|
179 | } |
---|
180 | $query_false.= ' |
---|
181 | ;'; |
---|
182 | display_select_cat_wrapper($query_false,array(),'category_option_false'); |
---|
183 | |
---|
184 | // +-----------------------------------------------------------------------+ |
---|
185 | // | html code display | |
---|
186 | // +-----------------------------------------------------------------------+ |
---|
187 | |
---|
188 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
189 | $template->assign_var_from_handle('ADMIN_CONTENT', 'group_perm'); |
---|
190 | |
---|
191 | ?> |
---|