1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 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 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
31 | |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | // | Check Access and exit when user status is not ok | |
---|
34 | // +-----------------------------------------------------------------------+ |
---|
35 | check_status(ACCESS_ADMINISTRATOR); |
---|
36 | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | // | modification registration | |
---|
39 | // +-----------------------------------------------------------------------+ |
---|
40 | |
---|
41 | // print '<pre>'; |
---|
42 | // print_r($_POST); |
---|
43 | // print '</pre>'; |
---|
44 | if (isset($_POST['falsify']) |
---|
45 | and isset($_POST['cat_true']) |
---|
46 | and count($_POST['cat_true']) > 0) |
---|
47 | { |
---|
48 | switch ($_GET['section']) |
---|
49 | { |
---|
50 | case 'upload' : |
---|
51 | { |
---|
52 | $query = ' |
---|
53 | UPDATE '.CATEGORIES_TABLE.' |
---|
54 | SET uploadable = \'false\' |
---|
55 | WHERE id IN ('.implode(',', $_POST['cat_true']).') |
---|
56 | ;'; |
---|
57 | pwg_query($query); |
---|
58 | break; |
---|
59 | } |
---|
60 | case 'comments' : |
---|
61 | { |
---|
62 | $query = ' |
---|
63 | UPDATE '.CATEGORIES_TABLE.' |
---|
64 | SET commentable = \'false\' |
---|
65 | WHERE id IN ('.implode(',', $_POST['cat_true']).') |
---|
66 | ;'; |
---|
67 | pwg_query($query); |
---|
68 | break; |
---|
69 | } |
---|
70 | case 'visible' : |
---|
71 | { |
---|
72 | set_cat_visible($_POST['cat_true'], 'false'); |
---|
73 | break; |
---|
74 | } |
---|
75 | case 'status' : |
---|
76 | { |
---|
77 | set_cat_status($_POST['cat_true'], 'private'); |
---|
78 | break; |
---|
79 | } |
---|
80 | case 'representative' : |
---|
81 | { |
---|
82 | $query = ' |
---|
83 | UPDATE '.CATEGORIES_TABLE.' |
---|
84 | SET representative_picture_id = NULL |
---|
85 | WHERE id IN ('.implode(',', $_POST['cat_true']).') |
---|
86 | ;'; |
---|
87 | pwg_query($query); |
---|
88 | break; |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | else if (isset($_POST['trueify']) |
---|
93 | and isset($_POST['cat_false']) |
---|
94 | and count($_POST['cat_false']) > 0) |
---|
95 | { |
---|
96 | switch ($_GET['section']) |
---|
97 | { |
---|
98 | case 'upload' : |
---|
99 | { |
---|
100 | $query = ' |
---|
101 | UPDATE '.CATEGORIES_TABLE.' |
---|
102 | SET uploadable = \'true\' |
---|
103 | WHERE id IN ('.implode(',', $_POST['cat_false']).') |
---|
104 | ;'; |
---|
105 | pwg_query($query); |
---|
106 | break; |
---|
107 | } |
---|
108 | case 'comments' : |
---|
109 | { |
---|
110 | $query = ' |
---|
111 | UPDATE '.CATEGORIES_TABLE.' |
---|
112 | SET commentable = \'true\' |
---|
113 | WHERE id IN ('.implode(',', $_POST['cat_false']).') |
---|
114 | ;'; |
---|
115 | pwg_query($query); |
---|
116 | break; |
---|
117 | } |
---|
118 | case 'visible' : |
---|
119 | { |
---|
120 | set_cat_visible($_POST['cat_false'], 'true'); |
---|
121 | break; |
---|
122 | } |
---|
123 | case 'status' : |
---|
124 | { |
---|
125 | set_cat_status($_POST['cat_false'], 'public'); |
---|
126 | break; |
---|
127 | } |
---|
128 | case 'representative' : |
---|
129 | { |
---|
130 | // theoretically, all categories in $_POST['cat_false'] contain at |
---|
131 | // least one element, so Piwigo can find a representant. |
---|
132 | set_random_representant($_POST['cat_false']); |
---|
133 | break; |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | // +-----------------------------------------------------------------------+ |
---|
139 | // | template init | |
---|
140 | // +-----------------------------------------------------------------------+ |
---|
141 | |
---|
142 | $template->set_filenames( |
---|
143 | array( |
---|
144 | 'cat_options' => 'cat_options.tpl', |
---|
145 | 'double_select' => 'double_select.tpl' |
---|
146 | ) |
---|
147 | ); |
---|
148 | |
---|
149 | $page['section'] = isset($_GET['section']) ? $_GET['section'] : 'status'; |
---|
150 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&section='; |
---|
151 | |
---|
152 | $template->assign( |
---|
153 | array( |
---|
154 | 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_options', |
---|
155 | 'F_ACTION'=>$base_url.$page['section'] |
---|
156 | ) |
---|
157 | ); |
---|
158 | |
---|
159 | // TabSheet |
---|
160 | $tabsheet = new tabsheet(); |
---|
161 | // TabSheet initialization |
---|
162 | $opt_link = $link_start.'cat_options&section='; |
---|
163 | $tabsheet->add('status', l10n('Public / Private'), $opt_link.'status'); |
---|
164 | $tabsheet->add('visible', l10n('Lock'), $opt_link.'visible'); |
---|
165 | $tabsheet->add('Upload', l10n('Upload'), $opt_link.'Upload'); |
---|
166 | $tabsheet->add('Comments', l10n('Comments'), $opt_link.'Comments'); |
---|
167 | if ($conf['allow_random_representative']) |
---|
168 | { |
---|
169 | $tabsheet->add('representative', l10n('Representative'), $opt_link.'representative'); |
---|
170 | } |
---|
171 | // TabSheet selection |
---|
172 | $tabsheet->select($page['section']); |
---|
173 | // Assign tabsheet to template |
---|
174 | $tabsheet->assign(); |
---|
175 | |
---|
176 | // +-----------------------------------------------------------------------+ |
---|
177 | // | form display | |
---|
178 | // +-----------------------------------------------------------------------+ |
---|
179 | |
---|
180 | // for each section, categories in the multiselect field can be : |
---|
181 | // |
---|
182 | // - true : uploadable for upload section |
---|
183 | // - false : un-uploadable for upload section |
---|
184 | // - NA : (not applicable) for virtual categories |
---|
185 | // |
---|
186 | // for true and false status, we associates an array of category ids, |
---|
187 | // function display_select_categories will use the given CSS class for each |
---|
188 | // option |
---|
189 | $cats_true = array(); |
---|
190 | $cats_false = array(); |
---|
191 | switch ($page['section']) |
---|
192 | { |
---|
193 | case 'upload' : |
---|
194 | { |
---|
195 | $query_true = ' |
---|
196 | SELECT id,name,uppercats,global_rank |
---|
197 | FROM '.CATEGORIES_TABLE.' |
---|
198 | WHERE uploadable = \'true\' |
---|
199 | AND dir IS NOT NULL |
---|
200 | AND site_id = 1 |
---|
201 | ;'; |
---|
202 | $query_false = ' |
---|
203 | SELECT id,name,uppercats,global_rank |
---|
204 | FROM '.CATEGORIES_TABLE.' |
---|
205 | WHERE uploadable = \'false\' |
---|
206 | AND dir IS NOT NULL |
---|
207 | AND site_id = 1 |
---|
208 | ;'; |
---|
209 | $template->assign( |
---|
210 | array( |
---|
211 | 'L_SECTION' => l10n('Select uploadable categories'), |
---|
212 | 'L_CAT_OPTIONS_TRUE' => l10n('Authorized'), |
---|
213 | 'L_CAT_OPTIONS_FALSE' => l10n('Forbidden'), |
---|
214 | ) |
---|
215 | ); |
---|
216 | break; |
---|
217 | } |
---|
218 | case 'comments' : |
---|
219 | { |
---|
220 | $query_true = ' |
---|
221 | SELECT id,name,uppercats,global_rank |
---|
222 | FROM '.CATEGORIES_TABLE.' |
---|
223 | WHERE commentable = \'true\' |
---|
224 | ;'; |
---|
225 | $query_false = ' |
---|
226 | SELECT id,name,uppercats,global_rank |
---|
227 | FROM '.CATEGORIES_TABLE.' |
---|
228 | WHERE commentable = \'false\' |
---|
229 | ;'; |
---|
230 | $template->assign( |
---|
231 | array( |
---|
232 | 'L_SECTION' => l10n('Authorize users to add comments on selected categories'), |
---|
233 | 'L_CAT_OPTIONS_TRUE' => l10n('Authorized'), |
---|
234 | 'L_CAT_OPTIONS_FALSE' => l10n('Forbidden'), |
---|
235 | ) |
---|
236 | ); |
---|
237 | break; |
---|
238 | } |
---|
239 | case 'visible' : |
---|
240 | { |
---|
241 | $query_true = ' |
---|
242 | SELECT id,name,uppercats,global_rank |
---|
243 | FROM '.CATEGORIES_TABLE.' |
---|
244 | WHERE visible = \'true\' |
---|
245 | ;'; |
---|
246 | $query_false = ' |
---|
247 | SELECT id,name,uppercats,global_rank |
---|
248 | FROM '.CATEGORIES_TABLE.' |
---|
249 | WHERE visible = \'false\' |
---|
250 | ;'; |
---|
251 | $template->assign( |
---|
252 | array( |
---|
253 | 'L_SECTION' => l10n('Lock categories'), |
---|
254 | 'L_CAT_OPTIONS_TRUE' => l10n('Unlocked'), |
---|
255 | 'L_CAT_OPTIONS_FALSE' => l10n('Locked'), |
---|
256 | ) |
---|
257 | ); |
---|
258 | break; |
---|
259 | } |
---|
260 | case 'status' : |
---|
261 | { |
---|
262 | $query_true = ' |
---|
263 | SELECT id,name,uppercats,global_rank |
---|
264 | FROM '.CATEGORIES_TABLE.' |
---|
265 | WHERE status = \'public\' |
---|
266 | ;'; |
---|
267 | $query_false = ' |
---|
268 | SELECT id,name,uppercats,global_rank |
---|
269 | FROM '.CATEGORIES_TABLE.' |
---|
270 | WHERE status = \'private\' |
---|
271 | ;'; |
---|
272 | $template->assign( |
---|
273 | array( |
---|
274 | 'L_SECTION' => l10n('Manage authorizations for selected categories'), |
---|
275 | 'L_CAT_OPTIONS_TRUE' => l10n('Public category'), |
---|
276 | 'L_CAT_OPTIONS_FALSE' => l10n('Private category'), |
---|
277 | ) |
---|
278 | ); |
---|
279 | break; |
---|
280 | } |
---|
281 | case 'representative' : |
---|
282 | { |
---|
283 | $query_true = ' |
---|
284 | SELECT id,name,uppercats,global_rank |
---|
285 | FROM '.CATEGORIES_TABLE.' |
---|
286 | WHERE representative_picture_id IS NOT NULL |
---|
287 | ;'; |
---|
288 | $query_false = ' |
---|
289 | SELECT DISTINCT id,name,uppercats,global_rank |
---|
290 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=category_id |
---|
291 | WHERE representative_picture_id IS NULL |
---|
292 | ;'; |
---|
293 | $template->assign( |
---|
294 | array( |
---|
295 | 'L_SECTION' => l10n('Representative'), |
---|
296 | 'L_CAT_OPTIONS_TRUE' => l10n('singly represented'), |
---|
297 | 'L_CAT_OPTIONS_FALSE' => l10n('randomly represented') |
---|
298 | ) |
---|
299 | ); |
---|
300 | break; |
---|
301 | } |
---|
302 | } |
---|
303 | display_select_cat_wrapper($query_true,array(),'category_option_true'); |
---|
304 | display_select_cat_wrapper($query_false,array(),'category_option_false'); |
---|
305 | |
---|
306 | // +-----------------------------------------------------------------------+ |
---|
307 | // | sending html code | |
---|
308 | // +-----------------------------------------------------------------------+ |
---|
309 | |
---|
310 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
311 | $template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options'); |
---|
312 | ?> |
---|