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