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