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