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-2004 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-11-15 21:42:55 +0000 (Mon, 15 Nov 2004) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 604 $ |
---|
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 | include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
33 | // +-----------------------------------------------------------------------+ |
---|
34 | // | modification registration | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // print '<pre>'; |
---|
37 | // print_r($_POST); |
---|
38 | // print '</pre>'; |
---|
39 | if (isset($_POST['submit']) and count($_POST['cat']) > 0) |
---|
40 | { |
---|
41 | switch ($_GET['section']) |
---|
42 | { |
---|
43 | case 'upload' : |
---|
44 | { |
---|
45 | $query = ' |
---|
46 | UPDATE '.CATEGORIES_TABLE.' |
---|
47 | SET uploadable = \''.$_POST['option'].'\' |
---|
48 | WHERE id IN ('.implode(',', $_POST['cat']).') |
---|
49 | ;'; |
---|
50 | pwg_query($query); |
---|
51 | break; |
---|
52 | } |
---|
53 | case 'comments' : |
---|
54 | { |
---|
55 | $query = ' |
---|
56 | UPDATE '.CATEGORIES_TABLE.' |
---|
57 | SET commentable = \''.$_POST['option'].'\' |
---|
58 | WHERE id IN ('.implode(',', $_POST['cat']).') |
---|
59 | ;'; |
---|
60 | pwg_query($query); |
---|
61 | break; |
---|
62 | } |
---|
63 | case 'visible' : |
---|
64 | { |
---|
65 | // locking a category => all its child categories become locked |
---|
66 | if ($_POST['option'] == 'false') |
---|
67 | { |
---|
68 | $subcats = get_subcat_ids($_POST['cat']); |
---|
69 | $query = ' |
---|
70 | UPDATE '.CATEGORIES_TABLE.' |
---|
71 | SET visible = \'false\' |
---|
72 | WHERE id IN ('.implode(',', $subcats).') |
---|
73 | ;'; |
---|
74 | pwg_query($query); |
---|
75 | } |
---|
76 | // unlocking a category => all its parent categories become unlocked |
---|
77 | if ($_POST['option'] == 'true') |
---|
78 | { |
---|
79 | $uppercats = array(); |
---|
80 | $query = ' |
---|
81 | SELECT uppercats |
---|
82 | FROM '.CATEGORIES_TABLE.' |
---|
83 | WHERE id IN ('.implode(',', $_POST['cat']).') |
---|
84 | ;'; |
---|
85 | $result = pwg_query($query); |
---|
86 | while ($row = mysql_fetch_array($result)) |
---|
87 | { |
---|
88 | $uppercats = array_merge($uppercats, |
---|
89 | explode(',', $row['uppercats'])); |
---|
90 | } |
---|
91 | $uppercats = array_unique($uppercats); |
---|
92 | |
---|
93 | $query = ' |
---|
94 | UPDATE '.CATEGORIES_TABLE.' |
---|
95 | SET visible = \'true\' |
---|
96 | WHERE id IN ('.implode(',', $uppercats).') |
---|
97 | ;'; |
---|
98 | pwg_query($query); |
---|
99 | } |
---|
100 | break; |
---|
101 | } |
---|
102 | case 'status' : |
---|
103 | { |
---|
104 | // make a category private => all its child categories become private |
---|
105 | if ($_POST['option'] == 'false') |
---|
106 | { |
---|
107 | $subcats = get_subcat_ids($_POST['cat']); |
---|
108 | $query = ' |
---|
109 | UPDATE '.CATEGORIES_TABLE.' |
---|
110 | SET status = \'private\' |
---|
111 | WHERE id IN ('.implode(',', $subcats).') |
---|
112 | ;'; |
---|
113 | pwg_query($query); |
---|
114 | } |
---|
115 | // make public a category => all its parent categories become public |
---|
116 | if ($_POST['option'] == 'true') |
---|
117 | { |
---|
118 | $uppercats = array(); |
---|
119 | $query = ' |
---|
120 | SELECT uppercats |
---|
121 | FROM '.CATEGORIES_TABLE.' |
---|
122 | WHERE id IN ('.implode(',', $_POST['cat']).') |
---|
123 | ;'; |
---|
124 | $result = pwg_query($query); |
---|
125 | while ($row = mysql_fetch_array($result)) |
---|
126 | { |
---|
127 | $uppercats = array_merge($uppercats, |
---|
128 | explode(',', $row['uppercats'])); |
---|
129 | } |
---|
130 | $uppercats = array_unique($uppercats); |
---|
131 | |
---|
132 | $query = ' |
---|
133 | UPDATE '.CATEGORIES_TABLE.' |
---|
134 | SET status = \'public\' |
---|
135 | WHERE id IN ('.implode(',', $uppercats).') |
---|
136 | ;'; |
---|
137 | pwg_query($query); |
---|
138 | } |
---|
139 | break; |
---|
140 | } |
---|
141 | } |
---|
142 | } |
---|
143 | // +-----------------------------------------------------------------------+ |
---|
144 | // | template init | |
---|
145 | // +-----------------------------------------------------------------------+ |
---|
146 | $template->set_filenames(array('cat_options'=>'admin/cat_options.tpl')); |
---|
147 | |
---|
148 | if (!isset($_GET['section'])) |
---|
149 | { |
---|
150 | $page['section'] = 'upload'; |
---|
151 | } |
---|
152 | else |
---|
153 | { |
---|
154 | $page['section'] = $_GET['section']; |
---|
155 | } |
---|
156 | |
---|
157 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&section='; |
---|
158 | $template->assign_vars( |
---|
159 | array( |
---|
160 | 'L_SUBMIT'=>$lang['submit'], |
---|
161 | 'L_RESET'=>$lang['reset'], |
---|
162 | 'L_CAT_OPTIONS_MENU_UPLOAD'=>$lang['cat_options_menu_upload'], |
---|
163 | 'L_CAT_OPTIONS_MENU_VISIBLE'=>$lang['cat_options_menu_visible'], |
---|
164 | 'L_CAT_OPTIONS_MENU_COMMENTS'=>$lang['cat_options_menu_comments'], |
---|
165 | 'L_CAT_OPTIONS_MENU_STATUS'=>$lang['cat_options_menu_status'], |
---|
166 | 'L_CAT_OPTIONS_UPLOAD_INFO'=>$lang['cat_options_upload_info'], |
---|
167 | 'L_CAT_OPTIONS_UPLOAD_TRUE'=>$lang['cat_options_upload_true'], |
---|
168 | 'L_CAT_OPTIONS_UPLOAD_FALSE'=>$lang['cat_options_upload_false'], |
---|
169 | 'L_CAT_OPTIONS_COMMENTS_INFO'=>$lang['cat_options_comments_info'], |
---|
170 | 'L_CAT_OPTIONS_COMMENTS_TRUE'=>$lang['cat_options_comments_true'], |
---|
171 | 'L_CAT_OPTIONS_COMMENTS_FALSE'=>$lang['cat_options_comments_false'], |
---|
172 | 'L_CAT_OPTIONS_VISIBLE_INFO'=>$lang['cat_options_visible_info'], |
---|
173 | 'L_CAT_OPTIONS_VISIBLE_TRUE'=>$lang['cat_options_visible_true'], |
---|
174 | 'L_CAT_OPTIONS_VISIBLE_FALSE'=>$lang['cat_options_visible_false'], |
---|
175 | 'L_CAT_OPTIONS_STATUS_INFO'=>$lang['cat_options_status_info'], |
---|
176 | 'L_CAT_OPTIONS_STATUS_TRUE'=>$lang['cat_options_status_true'], |
---|
177 | 'L_CAT_OPTIONS_STATUS_FALSE'=>$lang['cat_options_status_false'], |
---|
178 | |
---|
179 | 'U_UPLOAD'=>add_session_id($base_url.'upload'), |
---|
180 | 'U_VISIBLE'=>add_session_id($base_url.'visible'), |
---|
181 | 'U_COMMENTS'=>add_session_id($base_url.'comments'), |
---|
182 | 'U_STATUS'=>add_session_id($base_url.'status'), |
---|
183 | |
---|
184 | 'F_ACTION'=>add_session_id($base_url.$page['section']) |
---|
185 | ) |
---|
186 | ); |
---|
187 | |
---|
188 | $template->assign_vars(array(strtoupper($page['section']).'_CLASS'=>'opened')); |
---|
189 | // +-----------------------------------------------------------------------+ |
---|
190 | // | form display | |
---|
191 | // +-----------------------------------------------------------------------+ |
---|
192 | |
---|
193 | // for each section, categories in the multiselect field can be : |
---|
194 | // |
---|
195 | // - true : uploadable for upload section |
---|
196 | // - false : un-uploadable for upload section |
---|
197 | // - NA : (not applicable) for virtual categories |
---|
198 | // |
---|
199 | // for true and false status, we associates an array of category ids, |
---|
200 | // function display_select_categories will use the given CSS class for each |
---|
201 | // option |
---|
202 | $cats_true = array(); |
---|
203 | $cats_false = array(); |
---|
204 | switch ($page['section']) |
---|
205 | { |
---|
206 | case 'upload' : |
---|
207 | { |
---|
208 | $query = ' |
---|
209 | SELECT id |
---|
210 | FROM '.CATEGORIES_TABLE.' |
---|
211 | WHERE uploadable = \'true\' |
---|
212 | AND dir IS NOT NULL |
---|
213 | AND site_id = 1 |
---|
214 | ;'; |
---|
215 | $result = pwg_query($query); |
---|
216 | while ($row = mysql_fetch_array($result)) |
---|
217 | { |
---|
218 | array_push($cats_true, $row['id']); |
---|
219 | } |
---|
220 | $query = ' |
---|
221 | SELECT id |
---|
222 | FROM '.CATEGORIES_TABLE.' |
---|
223 | WHERE uploadable = \'false\' |
---|
224 | AND dir IS NOT NULL |
---|
225 | AND site_id = 1 |
---|
226 | ;'; |
---|
227 | $result = pwg_query($query); |
---|
228 | while ($row = mysql_fetch_array($result)) |
---|
229 | { |
---|
230 | array_push($cats_false, $row['id']); |
---|
231 | } |
---|
232 | |
---|
233 | $template->assign_block_vars('upload', array()); |
---|
234 | |
---|
235 | break; |
---|
236 | } |
---|
237 | case 'comments' : |
---|
238 | { |
---|
239 | $query = ' |
---|
240 | SELECT id |
---|
241 | FROM '.CATEGORIES_TABLE.' |
---|
242 | WHERE commentable = \'true\' |
---|
243 | ;'; |
---|
244 | $result = pwg_query($query); |
---|
245 | while ($row = mysql_fetch_array($result)) |
---|
246 | { |
---|
247 | array_push($cats_true, $row['id']); |
---|
248 | } |
---|
249 | $query = ' |
---|
250 | SELECT id |
---|
251 | FROM '.CATEGORIES_TABLE.' |
---|
252 | WHERE commentable = \'false\' |
---|
253 | ;'; |
---|
254 | $result = pwg_query($query); |
---|
255 | while ($row = mysql_fetch_array($result)) |
---|
256 | { |
---|
257 | array_push($cats_false, $row['id']); |
---|
258 | } |
---|
259 | |
---|
260 | $template->assign_block_vars('comments', array()); |
---|
261 | |
---|
262 | break; |
---|
263 | } |
---|
264 | case 'visible' : |
---|
265 | { |
---|
266 | $query = ' |
---|
267 | SELECT id |
---|
268 | FROM '.CATEGORIES_TABLE.' |
---|
269 | WHERE visible = \'true\' |
---|
270 | ;'; |
---|
271 | $result = pwg_query($query); |
---|
272 | while ($row = mysql_fetch_array($result)) |
---|
273 | { |
---|
274 | array_push($cats_true, $row['id']); |
---|
275 | } |
---|
276 | $query = ' |
---|
277 | SELECT id |
---|
278 | FROM '.CATEGORIES_TABLE.' |
---|
279 | WHERE visible = \'false\' |
---|
280 | ;'; |
---|
281 | $result = pwg_query($query); |
---|
282 | while ($row = mysql_fetch_array($result)) |
---|
283 | { |
---|
284 | array_push($cats_false, $row['id']); |
---|
285 | } |
---|
286 | |
---|
287 | $template->assign_block_vars('visible', array()); |
---|
288 | |
---|
289 | break; |
---|
290 | } |
---|
291 | case 'status' : |
---|
292 | { |
---|
293 | $query = ' |
---|
294 | SELECT id |
---|
295 | FROM '.CATEGORIES_TABLE.' |
---|
296 | WHERE status = \'public\' |
---|
297 | ;'; |
---|
298 | $result = pwg_query($query); |
---|
299 | while ($row = mysql_fetch_array($result)) |
---|
300 | { |
---|
301 | array_push($cats_true, $row['id']); |
---|
302 | } |
---|
303 | $query = ' |
---|
304 | SELECT id |
---|
305 | FROM '.CATEGORIES_TABLE.' |
---|
306 | WHERE status = \'private\' |
---|
307 | ;'; |
---|
308 | $result = pwg_query($query); |
---|
309 | while ($row = mysql_fetch_array($result)) |
---|
310 | { |
---|
311 | array_push($cats_false, $row['id']); |
---|
312 | } |
---|
313 | |
---|
314 | $template->assign_block_vars('status', array()); |
---|
315 | |
---|
316 | break; |
---|
317 | } |
---|
318 | } |
---|
319 | $CSS_classes = array('optionTrue'=>$cats_true, |
---|
320 | 'optionFalse'=>$cats_false); |
---|
321 | |
---|
322 | $user['expand'] = true; |
---|
323 | $structure = create_user_structure(''); |
---|
324 | display_select_categories($structure, |
---|
325 | ' ', |
---|
326 | array(), |
---|
327 | 'category_option', |
---|
328 | $CSS_classes); |
---|
329 | // +-----------------------------------------------------------------------+ |
---|
330 | // | sending html code | |
---|
331 | // +-----------------------------------------------------------------------+ |
---|
332 | $template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options'); |
---|
333 | ?> |
---|