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-2008 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: group_perm.php 2273 2008-03-11 01:51:47Z rvelices $ |
---|
8 | // | last update : $Date: 2008-03-11 01:51:47 +0000 (Tue, 11 Mar 2008) $ |
---|
9 | // | last modifier : $Author: rvelices $ |
---|
10 | // | revision : $Revision: 2273 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
28 | { |
---|
29 | die ("Hacking attempt!"); |
---|
30 | } |
---|
31 | |
---|
32 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
33 | |
---|
34 | // +-----------------------------------------------------------------------+ |
---|
35 | // | Check Access and exit when user status is not ok | |
---|
36 | // +-----------------------------------------------------------------------+ |
---|
37 | check_status(ACCESS_ADMINISTRATOR); |
---|
38 | |
---|
39 | // +-----------------------------------------------------------------------+ |
---|
40 | // | variables init | |
---|
41 | // +-----------------------------------------------------------------------+ |
---|
42 | |
---|
43 | if (isset($_GET['group_id']) and is_numeric($_GET['group_id'])) |
---|
44 | { |
---|
45 | $page['group'] = $_GET['group_id']; |
---|
46 | } |
---|
47 | else |
---|
48 | { |
---|
49 | die('group_id URL parameter is missing'); |
---|
50 | } |
---|
51 | |
---|
52 | // +-----------------------------------------------------------------------+ |
---|
53 | // | updates | |
---|
54 | // +-----------------------------------------------------------------------+ |
---|
55 | |
---|
56 | if (isset($_POST['falsify']) |
---|
57 | and isset($_POST['cat_true']) |
---|
58 | and count($_POST['cat_true']) > 0) |
---|
59 | { |
---|
60 | // if you forbid access to a category, all sub-categories become |
---|
61 | // automatically forbidden |
---|
62 | $subcats = get_subcat_ids($_POST['cat_true']); |
---|
63 | $query = ' |
---|
64 | DELETE |
---|
65 | FROM '.GROUP_ACCESS_TABLE.' |
---|
66 | WHERE group_id = '.$page['group'].' |
---|
67 | AND cat_id IN ('.implode(',', $subcats).') |
---|
68 | ;'; |
---|
69 | pwg_query($query); |
---|
70 | } |
---|
71 | else if (isset($_POST['trueify']) |
---|
72 | and isset($_POST['cat_false']) |
---|
73 | and count($_POST['cat_false']) > 0) |
---|
74 | { |
---|
75 | $uppercats = get_uppercat_ids($_POST['cat_false']); |
---|
76 | $private_uppercats = array(); |
---|
77 | |
---|
78 | $query = ' |
---|
79 | SELECT id |
---|
80 | FROM '.CATEGORIES_TABLE.' |
---|
81 | WHERE id IN ('.implode(',', $uppercats).') |
---|
82 | AND status = \'private\' |
---|
83 | ;'; |
---|
84 | $result = pwg_query($query); |
---|
85 | while ($row = mysql_fetch_array($result)) |
---|
86 | { |
---|
87 | array_push($private_uppercats, $row['id']); |
---|
88 | } |
---|
89 | |
---|
90 | // retrying to authorize a category which is already authorized may cause |
---|
91 | // an error (in SQL statement), so we need to know which categories are |
---|
92 | // accesible |
---|
93 | $authorized_ids = array(); |
---|
94 | |
---|
95 | $query = ' |
---|
96 | SELECT cat_id |
---|
97 | FROM '.GROUP_ACCESS_TABLE.' |
---|
98 | WHERE group_id = '.$page['group'].' |
---|
99 | ;'; |
---|
100 | $result = pwg_query($query); |
---|
101 | |
---|
102 | while ($row = mysql_fetch_array($result)) |
---|
103 | { |
---|
104 | array_push($authorized_ids, $row['cat_id']); |
---|
105 | } |
---|
106 | |
---|
107 | $inserts = array(); |
---|
108 | $to_autorize_ids = array_diff($private_uppercats, $authorized_ids); |
---|
109 | foreach ($to_autorize_ids as $to_autorize_id) |
---|
110 | { |
---|
111 | array_push( |
---|
112 | $inserts, |
---|
113 | array( |
---|
114 | 'group_id' => $page['group'], |
---|
115 | 'cat_id' => $to_autorize_id |
---|
116 | ) |
---|
117 | ); |
---|
118 | } |
---|
119 | |
---|
120 | mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts); |
---|
121 | } |
---|
122 | |
---|
123 | // +-----------------------------------------------------------------------+ |
---|
124 | // | template init | |
---|
125 | // +-----------------------------------------------------------------------+ |
---|
126 | |
---|
127 | $template->set_filenames( |
---|
128 | array( |
---|
129 | 'group_perm' => 'admin/group_perm.tpl', |
---|
130 | 'double_select' => 'admin/double_select.tpl' |
---|
131 | ) |
---|
132 | ); |
---|
133 | |
---|
134 | $template->assign( |
---|
135 | array( |
---|
136 | 'TITLE' => |
---|
137 | sprintf( |
---|
138 | l10n('Manage permissions for group "%s"'), |
---|
139 | get_groupname($page['group'] |
---|
140 | ) |
---|
141 | ), |
---|
142 | 'L_CAT_OPTIONS_TRUE'=>l10n('authorized'), |
---|
143 | 'L_CAT_OPTIONS_FALSE'=>l10n('forbidden'), |
---|
144 | |
---|
145 | 'F_ACTION' => |
---|
146 | get_root_url(). |
---|
147 | 'admin.php?page=group_perm&group_id='. |
---|
148 | $page['group'] |
---|
149 | ) |
---|
150 | ); |
---|
151 | |
---|
152 | // only private categories are listed |
---|
153 | $query_true = ' |
---|
154 | SELECT id,name,uppercats,global_rank |
---|
155 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.GROUP_ACCESS_TABLE.' ON cat_id = id |
---|
156 | WHERE status = \'private\' |
---|
157 | AND group_id = '.$page['group'].' |
---|
158 | ;'; |
---|
159 | display_select_cat_wrapper($query_true,array(),'category_option_true'); |
---|
160 | |
---|
161 | $result = pwg_query($query_true); |
---|
162 | $authorized_ids = array(); |
---|
163 | while ($row = mysql_fetch_array($result)) |
---|
164 | { |
---|
165 | array_push($authorized_ids, $row['id']); |
---|
166 | } |
---|
167 | |
---|
168 | $query_false = ' |
---|
169 | SELECT id,name,uppercats,global_rank |
---|
170 | FROM '.CATEGORIES_TABLE.' |
---|
171 | WHERE status = \'private\''; |
---|
172 | if (count($authorized_ids) > 0) |
---|
173 | { |
---|
174 | $query_false.= ' |
---|
175 | AND id NOT IN ('.implode(',', $authorized_ids).')'; |
---|
176 | } |
---|
177 | $query_false.= ' |
---|
178 | ;'; |
---|
179 | display_select_cat_wrapper($query_false,array(),'category_option_false'); |
---|
180 | |
---|
181 | // +-----------------------------------------------------------------------+ |
---|
182 | // | html code display | |
---|
183 | // +-----------------------------------------------------------------------+ |
---|
184 | |
---|
185 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
186 | $template->assign_var_from_handle('ADMIN_CONTENT', 'group_perm'); |
---|
187 | |
---|
188 | ?> |
---|