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-12-05 21:28:40 +0000 (Sun, 05 Dec 2004) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 635 $ |
---|
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 | // | initialization | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | $errors = array(); |
---|
37 | $infos = array(); |
---|
38 | $categories = array(); |
---|
39 | $navigation = $lang['home']; |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | virtual categories management | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | // request to delete a virtual category |
---|
44 | if (isset($_GET['delete']) and is_numeric($_GET['delete'])) |
---|
45 | { |
---|
46 | $to_delete_categories = array(); |
---|
47 | array_push($to_delete_categories,$_GET['delete']); |
---|
48 | delete_categories($to_delete_categories); |
---|
49 | array_push($infos, $lang['cat_virtual_deleted']); |
---|
50 | } |
---|
51 | // request to add a virtual category |
---|
52 | else if (isset($_POST['submit'])) |
---|
53 | { |
---|
54 | // is the given category name only containing blank spaces ? |
---|
55 | if (preg_match('/^\s*$/', $_POST['virtual_name'])) |
---|
56 | { |
---|
57 | array_push($errors, $lang['cat_error_name']); |
---|
58 | } |
---|
59 | |
---|
60 | if (!count($errors)) |
---|
61 | { |
---|
62 | $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; |
---|
63 | // As we don't create a virtual category every day, let's do (far) too |
---|
64 | // much queries |
---|
65 | |
---|
66 | // we have then to add the virtual category |
---|
67 | $query = ' |
---|
68 | INSERT INTO '.CATEGORIES_TABLE.' |
---|
69 | (name,id_uppercat,rank,site_id) |
---|
70 | VALUES |
---|
71 | (\''.$_POST['virtual_name'].'\','.$parent_id.','.$_POST['rank'].',NULL) |
---|
72 | ;'; |
---|
73 | pwg_query($query); |
---|
74 | |
---|
75 | // And last we update the uppercats |
---|
76 | $query = ' |
---|
77 | SELECT MAX(id) |
---|
78 | FROM '.CATEGORIES_TABLE.' |
---|
79 | ;'; |
---|
80 | $my_id = array_pop(mysql_fetch_array(pwg_query($query))); |
---|
81 | |
---|
82 | if ($parent_id != 'NULL') |
---|
83 | { |
---|
84 | $query = ' |
---|
85 | SELECT uppercats, global_rank |
---|
86 | FROM '.CATEGORIES_TABLE.' |
---|
87 | WHERE id = '.$parent_id.' |
---|
88 | ;'; |
---|
89 | $result = pwg_query($query); |
---|
90 | $row = mysql_fetch_array($result); |
---|
91 | |
---|
92 | $parent_uppercats = $row['uppercats']; |
---|
93 | $parent_global_rank = $row['global_rank']; |
---|
94 | } |
---|
95 | |
---|
96 | $query = ' |
---|
97 | UPDATE '.CATEGORIES_TABLE.' |
---|
98 | '; |
---|
99 | if (!empty($parent_uppercats)) |
---|
100 | { |
---|
101 | $query.= " SET uppercats = CONCAT('".$parent_uppercats."',',',id)"; |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | $query.= ' SET uppercats = id'; |
---|
106 | } |
---|
107 | if (!empty($parent_global_rank)) |
---|
108 | { |
---|
109 | $query.= " , global_rank = CONCAT('".$parent_global_rank."','.',rank)"; |
---|
110 | } |
---|
111 | else |
---|
112 | { |
---|
113 | $query.= ' , uppercats = id'; |
---|
114 | } |
---|
115 | $query.= ' |
---|
116 | WHERE id = '.$my_id.' |
---|
117 | ;'; |
---|
118 | pwg_query($query); |
---|
119 | array_push($infos, $lang['cat_virtual_added']); |
---|
120 | } |
---|
121 | } |
---|
122 | // +-----------------------------------------------------------------------+ |
---|
123 | // | Cache management | |
---|
124 | // +-----------------------------------------------------------------------+ |
---|
125 | $query = ' |
---|
126 | SELECT * |
---|
127 | FROM '.CATEGORIES_TABLE; |
---|
128 | if (!isset($_GET['parent_id'])) |
---|
129 | { |
---|
130 | $query.= ' |
---|
131 | WHERE id_uppercat IS NULL'; |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | $query.= ' |
---|
136 | WHERE id_uppercat = '.$_GET['parent_id']; |
---|
137 | } |
---|
138 | $query.= ' |
---|
139 | ORDER BY rank ASC |
---|
140 | ;'; |
---|
141 | $result = pwg_query($query); |
---|
142 | while ($row = mysql_fetch_assoc($result)) |
---|
143 | { |
---|
144 | $categories[$row['rank']] = $row; |
---|
145 | } |
---|
146 | // +-----------------------------------------------------------------------+ |
---|
147 | // | Navigation path | |
---|
148 | // +-----------------------------------------------------------------------+ |
---|
149 | if (isset($_GET['parent_id'])) |
---|
150 | { |
---|
151 | $separator = ' <span style="font-size:15px">→</span> '; |
---|
152 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list'; |
---|
153 | |
---|
154 | $navigation = '<a class="" href="'.add_session_id($base_url).'">'; |
---|
155 | $navigation.= $lang['home']; |
---|
156 | $navigation.= '</a>'; |
---|
157 | $navigation.= $separator; |
---|
158 | |
---|
159 | $current_category = get_cat_info($_GET['parent_id']); |
---|
160 | $navigation.= get_cat_display_name($current_category['name'], |
---|
161 | $separator, |
---|
162 | $base_url.'&parent_id=', |
---|
163 | false); |
---|
164 | } |
---|
165 | // +-----------------------------------------------------------------------+ |
---|
166 | // | rank updates | |
---|
167 | // +-----------------------------------------------------------------------+ |
---|
168 | $current_rank = 0; |
---|
169 | if (isset($_GET['up']) and is_numeric($_GET['up'])) |
---|
170 | { |
---|
171 | // 1. searching the id of the category just above at the same level |
---|
172 | while (list ($id,$current) = each($categories)) |
---|
173 | { |
---|
174 | if ($current['id'] == $_GET['up']) |
---|
175 | { |
---|
176 | $current_rank = $current['rank']; |
---|
177 | break; |
---|
178 | } |
---|
179 | } |
---|
180 | if ($current_rank > 1) |
---|
181 | { |
---|
182 | // 2. Exchanging ranks between the two categories |
---|
183 | $query = ' |
---|
184 | UPDATE '.CATEGORIES_TABLE.' |
---|
185 | SET rank = '.($current_rank-1).' |
---|
186 | WHERE id = '.$_GET['up'].' |
---|
187 | ;'; |
---|
188 | pwg_query($query); |
---|
189 | $query = ' |
---|
190 | UPDATE '.CATEGORIES_TABLE.' |
---|
191 | SET rank = '.$current_rank.' |
---|
192 | WHERE id = '.$categories[($current_rank-1)]['id'].' |
---|
193 | ;'; |
---|
194 | pwg_query($query); |
---|
195 | // 3. Updating the cache array |
---|
196 | $categories[$current_rank] = $categories[($current_rank-1)]; |
---|
197 | $categories[($current_rank-1)] = $current; |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | // 2. Updating the rank of our category to be after the previous max rank |
---|
202 | $query = ' |
---|
203 | UPDATE '.CATEGORIES_TABLE.' |
---|
204 | SET rank = '.(count($categories) + 1).' |
---|
205 | WHERE id = '.$_GET['up'].' |
---|
206 | ;'; |
---|
207 | pwg_query($query); |
---|
208 | $query = ' |
---|
209 | UPDATE '.CATEGORIES_TABLE.' |
---|
210 | SET rank = rank-1 |
---|
211 | WHERE id_uppercat '; |
---|
212 | if (empty($_GET['parent_id'])) |
---|
213 | { |
---|
214 | $query.= 'IS NULL'; |
---|
215 | } |
---|
216 | else |
---|
217 | { |
---|
218 | $query.= '= '.$_GET['parent_id']; |
---|
219 | } |
---|
220 | $query.= ' |
---|
221 | ;'; |
---|
222 | pwg_query($query); |
---|
223 | // 3. Updating the cache array |
---|
224 | array_push($categories, $current); |
---|
225 | array_shift($categories); |
---|
226 | } |
---|
227 | update_global_rank(@$_GET['parent_id']); |
---|
228 | } |
---|
229 | else if (isset($_GET['down']) and is_numeric($_GET['down'])) |
---|
230 | { |
---|
231 | // 1. searching the id of the category just above at the same level |
---|
232 | while (list ($id,$current) = each($categories)) |
---|
233 | { |
---|
234 | if ($current['id'] == $_GET['down']) |
---|
235 | { |
---|
236 | $current_rank = $current['rank']; |
---|
237 | break; |
---|
238 | } |
---|
239 | } |
---|
240 | if ($current_rank < count($categories)) |
---|
241 | { |
---|
242 | // 2. Exchanging ranks between the two categories |
---|
243 | $query = ' |
---|
244 | UPDATE '.CATEGORIES_TABLE.' |
---|
245 | SET rank = '.($current_rank+1).' |
---|
246 | WHERE id = '.$_GET['down'].' |
---|
247 | ;'; |
---|
248 | pwg_query($query); |
---|
249 | $query = ' |
---|
250 | UPDATE '.CATEGORIES_TABLE.' |
---|
251 | SET rank = '.$current_rank.' |
---|
252 | WHERE id = '.$categories[($current_rank+1)]['id'].' |
---|
253 | ;'; |
---|
254 | pwg_query($query); |
---|
255 | // 3. Updating the cache array |
---|
256 | $categories[$current_rank]=$categories[($current_rank+1)]; |
---|
257 | $categories[($current_rank+1)] = $current; |
---|
258 | } |
---|
259 | else |
---|
260 | { |
---|
261 | // 2. updating the rank of our category to be the first one |
---|
262 | $query = ' |
---|
263 | UPDATE '.CATEGORIES_TABLE.' |
---|
264 | SET rank = 0 |
---|
265 | WHERE id = '.$_GET['down'].' |
---|
266 | ;'; |
---|
267 | pwg_query($query); |
---|
268 | $query = ' |
---|
269 | UPDATE '.CATEGORIES_TABLE.' |
---|
270 | SET rank = rank+1 |
---|
271 | WHERE id_uppercat '; |
---|
272 | if (empty($_GET['parent_id'])) |
---|
273 | { |
---|
274 | $query.= 'IS NULL'; |
---|
275 | } |
---|
276 | else |
---|
277 | { |
---|
278 | $query.= '= '.$_GET['parent_id']; |
---|
279 | } |
---|
280 | $query.= ' |
---|
281 | ;'; |
---|
282 | pwg_query($query); |
---|
283 | // 3. Updating the cache array |
---|
284 | array_unshift($categories, $current); |
---|
285 | array_pop($categories); |
---|
286 | } |
---|
287 | update_global_rank(@$_GET['parent_id']); |
---|
288 | } |
---|
289 | reset($categories); |
---|
290 | // +-----------------------------------------------------------------------+ |
---|
291 | // | template initialization | |
---|
292 | // +-----------------------------------------------------------------------+ |
---|
293 | $template->set_filenames(array('categories'=>'admin/cat_list.tpl')); |
---|
294 | |
---|
295 | $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list'; |
---|
296 | if (isset($_GET['parent_id'])) |
---|
297 | { |
---|
298 | $form_action.= '&parent_id='.$_GET['parent_id']; |
---|
299 | } |
---|
300 | |
---|
301 | $template->assign_vars(array( |
---|
302 | 'CATEGORIES_NAV'=>$navigation, |
---|
303 | 'NEXT_RANK'=>max(array_keys($categories))+1, |
---|
304 | 'F_ACTION'=>$form_action, |
---|
305 | |
---|
306 | 'L_ADD_VIRTUAL'=>$lang['cat_add'], |
---|
307 | 'L_SUBMIT'=>$lang['submit'], |
---|
308 | 'L_STORAGE'=>$lang['storage'], |
---|
309 | 'L_NB_IMG'=>$lang['pictures'], |
---|
310 | 'L_MOVE_UP'=>$lang['up'], |
---|
311 | 'L_MOVE_DOWN'=>$lang['down'], |
---|
312 | 'L_EDIT'=>$lang['edit'], |
---|
313 | 'L_INFO_IMG'=>$lang['cat_image_info'], |
---|
314 | 'L_DELETE'=>$lang['delete'], |
---|
315 | )); |
---|
316 | |
---|
317 | $tpl = array('cat_first','cat_last'); |
---|
318 | // +-----------------------------------------------------------------------+ |
---|
319 | // | errors & infos | |
---|
320 | // +-----------------------------------------------------------------------+ |
---|
321 | if (count($errors) != 0) |
---|
322 | { |
---|
323 | $template->assign_block_vars('errors',array()); |
---|
324 | foreach ($errors as $error) |
---|
325 | { |
---|
326 | $template->assign_block_vars('errors.error',array('ERROR'=>$error)); |
---|
327 | } |
---|
328 | } |
---|
329 | if (count($infos) != 0) |
---|
330 | { |
---|
331 | $template->assign_block_vars('infos',array()); |
---|
332 | foreach ($infos as $info) |
---|
333 | { |
---|
334 | $template->assign_block_vars('infos.info',array('INFO'=>$info)); |
---|
335 | } |
---|
336 | } |
---|
337 | // +-----------------------------------------------------------------------+ |
---|
338 | // | Categories display | |
---|
339 | // +-----------------------------------------------------------------------+ |
---|
340 | while (list($id,$category) = each($categories)) |
---|
341 | { |
---|
342 | $images_folder = PHPWG_ROOT_PATH.'template/'; |
---|
343 | $images_folder.= $user['template'].'/admin/images'; |
---|
344 | |
---|
345 | if ($category['visible'] == 'false') |
---|
346 | { |
---|
347 | $image_src = $images_folder.'/icon_folder_lock.gif'; |
---|
348 | $image_alt = $lang['cat_private']; |
---|
349 | $image_title = $lang['cat_private']; |
---|
350 | } |
---|
351 | else if (empty($category['dir'])) |
---|
352 | { |
---|
353 | $image_src = $images_folder.'/icon_folder_link.gif'; |
---|
354 | $image_alt = $lang['cat_virtual']; |
---|
355 | $image_title = $lang['cat_virtual']; |
---|
356 | } |
---|
357 | else |
---|
358 | { |
---|
359 | // (Gweltas) May be should we have to introduce a computed field in the |
---|
360 | // table to avoid this query -> (z0rglub) no because the number of |
---|
361 | // sub-categories depends on permissions |
---|
362 | $query = ' |
---|
363 | SELECT COUNT(id) AS nb_sub_cats |
---|
364 | FROM '. CATEGORIES_TABLE.' |
---|
365 | WHERE id_uppercat = '.$category['id'].' |
---|
366 | ;'; |
---|
367 | $row = mysql_fetch_array(pwg_query($query)); |
---|
368 | |
---|
369 | if ($row['nb_sub_cats'] > 0) |
---|
370 | { |
---|
371 | $image_src = $images_folder.'/icon_subfolder.gif'; |
---|
372 | } |
---|
373 | else |
---|
374 | { |
---|
375 | $image_src = $images_folder.'/icon_folder.gif'; |
---|
376 | } |
---|
377 | $image_alt = ''; |
---|
378 | $image_title = ''; |
---|
379 | } |
---|
380 | |
---|
381 | $base_url = PHPWG_ROOT_PATH.'admin.php?page='; |
---|
382 | $cat_list_url = $base_url.'cat_list'; |
---|
383 | |
---|
384 | $self_url = $cat_list_url; |
---|
385 | if (isset($_GET['parent_id'])) |
---|
386 | { |
---|
387 | $self_url.= '&parent_id='.$_GET['parent_id']; |
---|
388 | } |
---|
389 | |
---|
390 | $template->assign_block_vars( |
---|
391 | 'category', |
---|
392 | array( |
---|
393 | 'CATEGORY_IMG_SRC'=>$image_src, |
---|
394 | 'CATEGORY_IMG_ALT'=>$image_alt, |
---|
395 | 'CATEGORY_IMG_TITLE'=>$image_title, |
---|
396 | 'CATEGORY_NAME'=>$category['name'], |
---|
397 | 'CATEGORY_DIR'=>@$category['dir'], |
---|
398 | 'CATEGORY_NB_IMG'=>$category['nb_images'], |
---|
399 | |
---|
400 | 'U_CATEGORY'=> |
---|
401 | add_session_id($cat_list_url.'&parent_id='.$category['id']), |
---|
402 | |
---|
403 | 'U_MOVE_UP'=>add_session_id($self_url.'&up='.$category['id']), |
---|
404 | |
---|
405 | 'U_MOVE_DOWN'=>add_session_id($self_url.'&down='.$category['id']), |
---|
406 | |
---|
407 | 'U_CAT_EDIT'=> |
---|
408 | add_session_id($base_url.'cat_modify&cat_id='.$category['id']), |
---|
409 | |
---|
410 | 'U_CAT_DELETE'=>add_session_id($self_url.'&delete='.$category['id']), |
---|
411 | |
---|
412 | 'U_INFO_IMG' |
---|
413 | => add_session_id($base_url.'infos_images&cat_id='.$category['id']) |
---|
414 | )); |
---|
415 | |
---|
416 | if (!empty($category['dir'])) |
---|
417 | { |
---|
418 | $template->assign_block_vars('category.storage' ,array()); |
---|
419 | } |
---|
420 | else |
---|
421 | { |
---|
422 | $template->assign_block_vars('category.virtual' ,array()); |
---|
423 | } |
---|
424 | |
---|
425 | if ($category['nb_images'] > 0) |
---|
426 | { |
---|
427 | $template->assign_block_vars('category.image_info' ,array()); |
---|
428 | } |
---|
429 | else |
---|
430 | { |
---|
431 | $template->assign_block_vars('category.no_image_info' ,array()); |
---|
432 | } |
---|
433 | } |
---|
434 | // +-----------------------------------------------------------------------+ |
---|
435 | // | sending html code | |
---|
436 | // +-----------------------------------------------------------------------+ |
---|
437 | $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); |
---|
438 | ?> |
---|