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-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: cat_options.php 1961 2007-04-19 06:01:28Z rub $ |
---|
8 | // | last update : $Date: 2007-04-19 06:01:28 +0000 (Thu, 19 Apr 2007) $ |
---|
9 | // | last modifier : $Author: rub $ |
---|
10 | // | revision : $Revision: 1961 $ |
---|
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 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_tabsheet.inc.php'); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | check_status(ACCESS_ADMINISTRATOR); |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | modification registration | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | |
---|
44 | // print '<pre>'; |
---|
45 | // print_r($_POST); |
---|
46 | // print '</pre>'; |
---|
47 | if (isset($_POST['falsify']) |
---|
48 | and isset($_POST['cat_true']) |
---|
49 | and count($_POST['cat_true']) > 0) |
---|
50 | { |
---|
51 | switch ($_GET['section']) |
---|
52 | { |
---|
53 | case 'upload' : |
---|
54 | { |
---|
55 | $query = ' |
---|
56 | UPDATE '.CATEGORIES_TABLE.' |
---|
57 | SET uploadable = \'false\' |
---|
58 | WHERE id IN ('.implode(',', $_POST['cat_true']).') |
---|
59 | ;'; |
---|
60 | pwg_query($query); |
---|
61 | break; |
---|
62 | } |
---|
63 | case 'comments' : |
---|
64 | { |
---|
65 | $query = ' |
---|
66 | UPDATE '.CATEGORIES_TABLE.' |
---|
67 | SET commentable = \'false\' |
---|
68 | WHERE id IN ('.implode(',', $_POST['cat_true']).') |
---|
69 | ;'; |
---|
70 | pwg_query($query); |
---|
71 | break; |
---|
72 | } |
---|
73 | case 'visible' : |
---|
74 | { |
---|
75 | set_cat_visible($_POST['cat_true'], 'false'); |
---|
76 | break; |
---|
77 | } |
---|
78 | case 'status' : |
---|
79 | { |
---|
80 | set_cat_status($_POST['cat_true'], 'private'); |
---|
81 | break; |
---|
82 | } |
---|
83 | case 'representative' : |
---|
84 | { |
---|
85 | $query = ' |
---|
86 | UPDATE '.CATEGORIES_TABLE.' |
---|
87 | SET representative_picture_id = NULL |
---|
88 | WHERE id IN ('.implode(',', $_POST['cat_true']).') |
---|
89 | ;'; |
---|
90 | pwg_query($query); |
---|
91 | break; |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | else if (isset($_POST['trueify']) |
---|
96 | and isset($_POST['cat_false']) |
---|
97 | and count($_POST['cat_false']) > 0) |
---|
98 | { |
---|
99 | switch ($_GET['section']) |
---|
100 | { |
---|
101 | case 'upload' : |
---|
102 | { |
---|
103 | $query = ' |
---|
104 | UPDATE '.CATEGORIES_TABLE.' |
---|
105 | SET uploadable = \'true\' |
---|
106 | WHERE id IN ('.implode(',', $_POST['cat_false']).') |
---|
107 | ;'; |
---|
108 | pwg_query($query); |
---|
109 | break; |
---|
110 | } |
---|
111 | case 'comments' : |
---|
112 | { |
---|
113 | $query = ' |
---|
114 | UPDATE '.CATEGORIES_TABLE.' |
---|
115 | SET commentable = \'true\' |
---|
116 | WHERE id IN ('.implode(',', $_POST['cat_false']).') |
---|
117 | ;'; |
---|
118 | pwg_query($query); |
---|
119 | break; |
---|
120 | } |
---|
121 | case 'visible' : |
---|
122 | { |
---|
123 | set_cat_visible($_POST['cat_false'], 'true'); |
---|
124 | break; |
---|
125 | } |
---|
126 | case 'status' : |
---|
127 | { |
---|
128 | set_cat_status($_POST['cat_false'], 'public'); |
---|
129 | break; |
---|
130 | } |
---|
131 | case 'representative' : |
---|
132 | { |
---|
133 | // theoretically, all categories in $_POST['cat_false'] contain at |
---|
134 | // least one element, so PhpWebGallery can find a representant. |
---|
135 | set_random_representant($_POST['cat_false']); |
---|
136 | break; |
---|
137 | } |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | // +-----------------------------------------------------------------------+ |
---|
142 | // | template init | |
---|
143 | // +-----------------------------------------------------------------------+ |
---|
144 | |
---|
145 | $template->set_filenames( |
---|
146 | array( |
---|
147 | 'cat_options' => 'admin/cat_options.tpl', |
---|
148 | 'double_select' => 'admin/double_select.tpl' |
---|
149 | ) |
---|
150 | ); |
---|
151 | |
---|
152 | $page['section'] = isset($_GET['section']) ? $_GET['section'] : 'upload'; |
---|
153 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&section='; |
---|
154 | |
---|
155 | $template->assign_vars( |
---|
156 | array( |
---|
157 | 'L_SUBMIT'=>$lang['submit'], |
---|
158 | 'L_RESET'=>$lang['reset'], |
---|
159 | |
---|
160 | 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_options', |
---|
161 | |
---|
162 | 'F_ACTION'=>$base_url.$page['section'] |
---|
163 | ) |
---|
164 | ); |
---|
165 | |
---|
166 | // TabSheet initialization |
---|
167 | $opt_link = $link_start.'cat_options&section='; |
---|
168 | $page['tabsheet'] = array |
---|
169 | ( |
---|
170 | 'upload' => array |
---|
171 | ( |
---|
172 | 'caption' => l10n('upload'), |
---|
173 | 'url' => $opt_link.'upload' |
---|
174 | ), |
---|
175 | 'comments' => array |
---|
176 | ( |
---|
177 | 'caption' => l10n('comments'), |
---|
178 | 'url' => $opt_link.'comments' |
---|
179 | ), |
---|
180 | 'visible' => array |
---|
181 | ( |
---|
182 | 'caption' => l10n('lock'), |
---|
183 | 'url' => $opt_link.'visible' |
---|
184 | ), |
---|
185 | 'status' => array |
---|
186 | ( |
---|
187 | 'caption' => l10n('cat_security'), |
---|
188 | 'url' => $opt_link.'status' |
---|
189 | ) |
---|
190 | ); |
---|
191 | |
---|
192 | if ($conf['allow_random_representative']) |
---|
193 | { |
---|
194 | $page['tabsheet']['representative'] = |
---|
195 | array |
---|
196 | ( |
---|
197 | 'caption' => l10n('Representative'), |
---|
198 | 'url' => $opt_link.'representative' |
---|
199 | ); |
---|
200 | } |
---|
201 | $page['tabsheet'][$page['section']]['selected'] = true; |
---|
202 | |
---|
203 | // Assign tabsheet to template |
---|
204 | template_assign_tabsheet(); |
---|
205 | |
---|
206 | // +-----------------------------------------------------------------------+ |
---|
207 | // | form display | |
---|
208 | // +-----------------------------------------------------------------------+ |
---|
209 | |
---|
210 | // for each section, categories in the multiselect field can be : |
---|
211 | // |
---|
212 | // - true : uploadable for upload section |
---|
213 | // - false : un-uploadable for upload section |
---|
214 | // - NA : (not applicable) for virtual categories |
---|
215 | // |
---|
216 | // for true and false status, we associates an array of category ids, |
---|
217 | // function display_select_categories will use the given CSS class for each |
---|
218 | // option |
---|
219 | $cats_true = array(); |
---|
220 | $cats_false = array(); |
---|
221 | switch ($page['section']) |
---|
222 | { |
---|
223 | case 'upload' : |
---|
224 | { |
---|
225 | $query_true = ' |
---|
226 | SELECT id,name,uppercats,global_rank |
---|
227 | FROM '.CATEGORIES_TABLE.' |
---|
228 | WHERE uploadable = \'true\' |
---|
229 | AND dir IS NOT NULL |
---|
230 | AND site_id = 1 |
---|
231 | ;'; |
---|
232 | $query_false = ' |
---|
233 | SELECT id,name,uppercats,global_rank |
---|
234 | FROM '.CATEGORIES_TABLE.' |
---|
235 | WHERE uploadable = \'false\' |
---|
236 | AND dir IS NOT NULL |
---|
237 | AND site_id = 1 |
---|
238 | ;'; |
---|
239 | $template->assign_vars( |
---|
240 | array( |
---|
241 | 'L_SECTION' => $lang['cat_upload_title'], |
---|
242 | 'L_CAT_OPTIONS_TRUE' => $lang['authorized'], |
---|
243 | 'L_CAT_OPTIONS_FALSE' => $lang['forbidden'], |
---|
244 | ) |
---|
245 | ); |
---|
246 | break; |
---|
247 | } |
---|
248 | case 'comments' : |
---|
249 | { |
---|
250 | $query_true = ' |
---|
251 | SELECT id,name,uppercats,global_rank |
---|
252 | FROM '.CATEGORIES_TABLE.' |
---|
253 | WHERE commentable = \'true\' |
---|
254 | ;'; |
---|
255 | $query_false = ' |
---|
256 | SELECT id,name,uppercats,global_rank |
---|
257 | FROM '.CATEGORIES_TABLE.' |
---|
258 | WHERE commentable = \'false\' |
---|
259 | ;'; |
---|
260 | $template->assign_vars( |
---|
261 | array( |
---|
262 | 'L_SECTION' => $lang['cat_comments_title'], |
---|
263 | 'L_CAT_OPTIONS_TRUE' => $lang['authorized'], |
---|
264 | 'L_CAT_OPTIONS_FALSE' => $lang['forbidden'], |
---|
265 | ) |
---|
266 | ); |
---|
267 | break; |
---|
268 | } |
---|
269 | case 'visible' : |
---|
270 | { |
---|
271 | $query_true = ' |
---|
272 | SELECT id,name,uppercats,global_rank |
---|
273 | FROM '.CATEGORIES_TABLE.' |
---|
274 | WHERE visible = \'true\' |
---|
275 | ;'; |
---|
276 | $query_false = ' |
---|
277 | SELECT id,name,uppercats,global_rank |
---|
278 | FROM '.CATEGORIES_TABLE.' |
---|
279 | WHERE visible = \'false\' |
---|
280 | ;'; |
---|
281 | $template->assign_vars( |
---|
282 | array( |
---|
283 | 'L_SECTION' => $lang['cat_lock_title'], |
---|
284 | 'L_CAT_OPTIONS_TRUE' => $lang['unlocked'], |
---|
285 | 'L_CAT_OPTIONS_FALSE' => $lang['locked'], |
---|
286 | ) |
---|
287 | ); |
---|
288 | break; |
---|
289 | } |
---|
290 | case 'status' : |
---|
291 | { |
---|
292 | $query_true = ' |
---|
293 | SELECT id,name,uppercats,global_rank |
---|
294 | FROM '.CATEGORIES_TABLE.' |
---|
295 | WHERE status = \'public\' |
---|
296 | ;'; |
---|
297 | $query_false = ' |
---|
298 | SELECT id,name,uppercats,global_rank |
---|
299 | FROM '.CATEGORIES_TABLE.' |
---|
300 | WHERE status = \'private\' |
---|
301 | ;'; |
---|
302 | $template->assign_vars( |
---|
303 | array( |
---|
304 | 'L_SECTION' => $lang['cat_status_title'], |
---|
305 | 'L_CAT_OPTIONS_TRUE' => $lang['cat_public'], |
---|
306 | 'L_CAT_OPTIONS_FALSE' => $lang['cat_private'], |
---|
307 | ) |
---|
308 | ); |
---|
309 | break; |
---|
310 | } |
---|
311 | case 'representative' : |
---|
312 | { |
---|
313 | $query_true = ' |
---|
314 | SELECT id,name,uppercats,global_rank |
---|
315 | FROM '.CATEGORIES_TABLE.' |
---|
316 | WHERE representative_picture_id IS NOT NULL |
---|
317 | ;'; |
---|
318 | $query_false = ' |
---|
319 | SELECT id,name,uppercats,global_rank |
---|
320 | FROM '.CATEGORIES_TABLE.' |
---|
321 | WHERE nb_images != 0 |
---|
322 | AND representative_picture_id IS NULL |
---|
323 | ;'; |
---|
324 | $template->assign_vars( |
---|
325 | array( |
---|
326 | 'L_SECTION' => l10n('Representative'), |
---|
327 | 'L_CAT_OPTIONS_TRUE' => l10n('singly represented'), |
---|
328 | 'L_CAT_OPTIONS_FALSE' => l10n('randomly represented') |
---|
329 | ) |
---|
330 | ); |
---|
331 | break; |
---|
332 | } |
---|
333 | } |
---|
334 | display_select_cat_wrapper($query_true,array(),'category_option_true'); |
---|
335 | display_select_cat_wrapper($query_false,array(),'category_option_false'); |
---|
336 | |
---|
337 | // +-----------------------------------------------------------------------+ |
---|
338 | // | sending html code | |
---|
339 | // +-----------------------------------------------------------------------+ |
---|
340 | |
---|
341 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
342 | $template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options'); |
---|
343 | ?> |
---|