[21] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1058] | 5 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[362] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[362] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2006-04-21 21:14:34 +0000 (Fri, 21 Apr 2006) $ |
---|
| 10 | // | last modifier : $Author: nikrou $ |
---|
| 11 | // | revision : $Revision: 1249 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[21] | 27 | |
---|
[632] | 28 | if (!defined('PHPWG_ROOT_PATH')) |
---|
[403] | 29 | { |
---|
[632] | 30 | die('Hacking attempt!'); |
---|
[403] | 31 | } |
---|
[1072] | 32 | |
---|
| 33 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 34 | |
---|
| 35 | // +-----------------------------------------------------------------------+ |
---|
| 36 | // | Check Access and exit when user status is not ok | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 39 | |
---|
[21] | 40 | //---------------------------------------------------------------- verification |
---|
[403] | 41 | if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) ) |
---|
[21] | 42 | { |
---|
[403] | 43 | $_GET['cat_id'] = '-1'; |
---|
[21] | 44 | } |
---|
[403] | 45 | |
---|
| 46 | $template->set_filenames( array('categories'=>'admin/cat_modify.tpl') ); |
---|
| 47 | |
---|
[21] | 48 | //--------------------------------------------------------- form criteria check |
---|
[825] | 49 | if (isset($_POST['submit'])) |
---|
[21] | 50 | { |
---|
[825] | 51 | $data = |
---|
| 52 | array( |
---|
| 53 | 'id' => $_GET['cat_id'], |
---|
| 54 | 'name' => @$_POST['name'], |
---|
| 55 | 'commentable' => $_POST['commentable'], |
---|
| 56 | 'uploadable' => |
---|
| 57 | isset($_POST['uploadable']) ? $_POST['uploadable'] : 'false', |
---|
| 58 | 'comment' => |
---|
| 59 | $conf['allow_html_descriptions'] ? |
---|
| 60 | @$_POST['comment'] : strip_tags(@$_POST['comment']) |
---|
| 61 | ); |
---|
[38] | 62 | |
---|
[825] | 63 | mass_updates( |
---|
| 64 | CATEGORIES_TABLE, |
---|
| 65 | array( |
---|
| 66 | 'primary' => array('id'), |
---|
| 67 | 'update' => array_diff(array_keys($data), array('id')) |
---|
| 68 | ), |
---|
| 69 | array($data) |
---|
| 70 | ); |
---|
[1131] | 71 | |
---|
[632] | 72 | set_cat_visible(array($_GET['cat_id']), $_POST['visible']); |
---|
| 73 | set_cat_status(array($_GET['cat_id']), $_POST['status']); |
---|
[345] | 74 | |
---|
[809] | 75 | if (isset($_POST['parent'])) |
---|
| 76 | { |
---|
[881] | 77 | move_categories( |
---|
| 78 | array($_GET['cat_id']), |
---|
| 79 | $_POST['parent'] |
---|
| 80 | ); |
---|
[809] | 81 | } |
---|
| 82 | |
---|
| 83 | array_push($page['infos'], $lang['editcat_confirm']); |
---|
[21] | 84 | } |
---|
[633] | 85 | else if (isset($_POST['set_random_representant'])) |
---|
| 86 | { |
---|
| 87 | set_random_representant(array($_GET['cat_id'])); |
---|
| 88 | } |
---|
[809] | 89 | else if (isset($_POST['delete_representant'])) |
---|
| 90 | { |
---|
| 91 | $query = ' |
---|
| 92 | UPDATE '.CATEGORIES_TABLE.' |
---|
| 93 | SET representative_picture_id = NULL |
---|
| 94 | WHERE id = '.$_GET['cat_id'].' |
---|
| 95 | ;'; |
---|
| 96 | pwg_query($query); |
---|
| 97 | } |
---|
[1064] | 98 | else if (isset($_POST['submitAdd'])) |
---|
| 99 | { |
---|
| 100 | $output_create = create_virtual_category( |
---|
| 101 | $_POST['virtual_name'], |
---|
| 102 | (0 == $_POST['parent'] ? null : $_POST['parent']) |
---|
| 103 | ); |
---|
[1131] | 104 | |
---|
[1064] | 105 | if (isset($output_create['error'])) |
---|
| 106 | { |
---|
| 107 | array_push($page['errors'], $output_create['error']); |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | // Virtual category creation succeeded |
---|
| 112 | // |
---|
| 113 | // Add the information in the information list |
---|
| 114 | array_push($page['infos'], $output_create['info']); |
---|
[1131] | 115 | |
---|
[1064] | 116 | // Link the new category to the current category |
---|
[1121] | 117 | associate_categories_to_categories( |
---|
| 118 | array($_GET['cat_id']), |
---|
| 119 | array($output_create['id']) |
---|
| 120 | ); |
---|
[21] | 121 | |
---|
[1121] | 122 | // information |
---|
[1064] | 123 | array_push( |
---|
[1121] | 124 | $page['infos'], |
---|
| 125 | sprintf( |
---|
| 126 | l10n('Category elements associated to the following categories: %s'), |
---|
| 127 | '<ul><li>' |
---|
| 128 | .get_cat_display_name_from_id($output_create['id']) |
---|
| 129 | .'</li></ul>' |
---|
[1064] | 130 | ) |
---|
| 131 | ); |
---|
| 132 | } |
---|
| 133 | } |
---|
[1121] | 134 | else if (isset($_POST['submitDestinations']) |
---|
| 135 | and isset($_POST['destinations']) |
---|
| 136 | and count($_POST['destinations']) > 0) |
---|
[1064] | 137 | { |
---|
[1121] | 138 | associate_categories_to_categories( |
---|
| 139 | array($_GET['cat_id']), |
---|
| 140 | $_POST['destinations'] |
---|
| 141 | ); |
---|
[1064] | 142 | |
---|
[1121] | 143 | $category_names = array(); |
---|
| 144 | foreach ($_POST['destinations'] as $category_id) |
---|
[1064] | 145 | { |
---|
| 146 | array_push( |
---|
[1121] | 147 | $category_names, |
---|
| 148 | get_cat_display_name_from_id($category_id) |
---|
[1064] | 149 | ); |
---|
| 150 | } |
---|
| 151 | |
---|
[1121] | 152 | array_push( |
---|
| 153 | $page['infos'], |
---|
| 154 | sprintf( |
---|
| 155 | l10n('Category elements associated to the following categories: %s'), |
---|
| 156 | '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>' |
---|
| 157 | ) |
---|
[1064] | 158 | ); |
---|
| 159 | } |
---|
| 160 | |
---|
[632] | 161 | $query = ' |
---|
| 162 | SELECT * |
---|
| 163 | FROM '.CATEGORIES_TABLE.' |
---|
| 164 | WHERE id = '.$_GET['cat_id'].' |
---|
| 165 | ;'; |
---|
[587] | 166 | $category = mysql_fetch_array( pwg_query( $query ) ); |
---|
[530] | 167 | // nullable fields |
---|
[809] | 168 | foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable) |
---|
[530] | 169 | { |
---|
| 170 | if (!isset($category[$nullable])) |
---|
| 171 | { |
---|
| 172 | $category[$nullable] = ''; |
---|
| 173 | } |
---|
| 174 | } |
---|
[345] | 175 | |
---|
[809] | 176 | $category['is_virtual'] = empty($category['dir']) ? true : false; |
---|
| 177 | |
---|
[403] | 178 | // Navigation path |
---|
[834] | 179 | $url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='; |
---|
[635] | 180 | |
---|
[834] | 181 | $navigation = get_cat_display_name_cache( |
---|
[635] | 182 | $category['uppercats'], |
---|
[834] | 183 | PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id=' |
---|
| 184 | ); |
---|
[345] | 185 | |
---|
[403] | 186 | $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='.$_GET['cat_id']; |
---|
[1131] | 187 | $status = ($category['status']=='public')?'STATUS_PUBLIC':'STATUS_PRIVATE'; |
---|
[403] | 188 | $lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED'; |
---|
| 189 | |
---|
[632] | 190 | if ($category['commentable'] == 'true') |
---|
| 191 | { |
---|
| 192 | $commentable = 'COMMENTABLE_TRUE'; |
---|
| 193 | } |
---|
| 194 | else |
---|
| 195 | { |
---|
| 196 | $commentable = 'COMMENTABLE_FALSE'; |
---|
| 197 | } |
---|
| 198 | if ($category['uploadable'] == 'true') |
---|
| 199 | { |
---|
| 200 | $uploadable = 'UPLOADABLE_TRUE'; |
---|
| 201 | } |
---|
| 202 | else |
---|
| 203 | { |
---|
| 204 | $uploadable = 'UPLOADABLE_FALSE'; |
---|
| 205 | } |
---|
| 206 | |
---|
[403] | 207 | //----------------------------------------------------- template initialization |
---|
[809] | 208 | |
---|
| 209 | $base_url = PHPWG_ROOT_PATH.'admin.php?page='; |
---|
| 210 | $cat_list_url = $base_url.'cat_list'; |
---|
[1131] | 211 | |
---|
[809] | 212 | $self_url = $cat_list_url; |
---|
| 213 | if (!empty($category['id_uppercat'])) |
---|
| 214 | { |
---|
| 215 | $self_url.= '&parent_id='.$category['id_uppercat']; |
---|
| 216 | } |
---|
| 217 | |
---|
[1082] | 218 | $template->assign_vars( |
---|
[1131] | 219 | array( |
---|
[1082] | 220 | 'CATEGORIES_NAV' => $navigation, |
---|
| 221 | 'CAT_NAME' => $category['name'], |
---|
| 222 | 'CAT_COMMENT' => $category['comment'], |
---|
[1131] | 223 | |
---|
[1082] | 224 | $status => 'checked="checked"', |
---|
| 225 | $lock => 'checked="checked"', |
---|
| 226 | $commentable => 'checked="checked"', |
---|
| 227 | $uploadable => 'checked="checked"', |
---|
[1131] | 228 | |
---|
[1082] | 229 | 'L_EDIT_NAME' => $lang['name'], |
---|
| 230 | 'L_STORAGE' => $lang['storage'], |
---|
| 231 | 'L_REMOTE_SITE' => $lang['remote_site'], |
---|
| 232 | 'L_EDIT_COMMENT' => $lang['description'], |
---|
| 233 | 'L_EDIT_STATUS' => $lang['conf_access'], |
---|
| 234 | 'L_STATUS_PUBLIC' => $lang['public'], |
---|
| 235 | 'L_STATUS_PRIVATE' => $lang['private'], |
---|
| 236 | 'L_EDIT_LOCK' => $lang['lock'], |
---|
| 237 | 'L_EDIT_UPLOADABLE' => $lang['editcat_uploadable'], |
---|
| 238 | 'L_EDIT_COMMENTABLE' => $lang['comments'], |
---|
| 239 | 'L_YES' => $lang['yes'], |
---|
| 240 | 'L_NO' => $lang['no'], |
---|
| 241 | 'L_SUBMIT' => $lang['submit'], |
---|
| 242 | 'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'], |
---|
[809] | 243 | |
---|
[1082] | 244 | 'U_JUMPTO' => make_index_url( |
---|
| 245 | array( |
---|
| 246 | 'category' => $category['id'], |
---|
[1131] | 247 | 'cat_name' => $category['name'], |
---|
[1082] | 248 | ) |
---|
| 249 | ), |
---|
[1131] | 250 | |
---|
[1082] | 251 | 'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'], |
---|
[1249] | 252 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=cat_modify', |
---|
[1131] | 253 | |
---|
[1082] | 254 | 'F_ACTION' => $form_action, |
---|
| 255 | ) |
---|
| 256 | ); |
---|
[633] | 257 | |
---|
[809] | 258 | |
---|
| 259 | if ('private' == $category['status']) |
---|
| 260 | { |
---|
| 261 | $template->assign_block_vars( |
---|
| 262 | 'permissions', |
---|
| 263 | array( |
---|
[1004] | 264 | 'URL'=>$base_url.'cat_perm&cat='.$category['id'] |
---|
[809] | 265 | ) |
---|
| 266 | ); |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | // manage category elements link |
---|
[633] | 270 | if ($category['nb_images'] > 0) |
---|
| 271 | { |
---|
[809] | 272 | $template->assign_block_vars( |
---|
| 273 | 'elements', |
---|
| 274 | array( |
---|
[1004] | 275 | 'URL'=>$base_url.'element_set&cat='.$category['id'] |
---|
[809] | 276 | ) |
---|
| 277 | ); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | // representant management |
---|
| 281 | if ($category['nb_images'] > 0 |
---|
| 282 | or !empty($category['representative_picture_id'])) |
---|
| 283 | { |
---|
| 284 | $template->assign_block_vars('representant', array()); |
---|
| 285 | |
---|
| 286 | // picture to display : the identified representant or the generic random |
---|
| 287 | // representant ? |
---|
| 288 | if (!empty($category['representative_picture_id'])) |
---|
| 289 | { |
---|
| 290 | $query = ' |
---|
[633] | 291 | SELECT tn_ext,path |
---|
| 292 | FROM '.IMAGES_TABLE.' |
---|
| 293 | WHERE id = '.$category['representative_picture_id'].' |
---|
| 294 | ;'; |
---|
[809] | 295 | $row = mysql_fetch_array(pwg_query($query)); |
---|
| 296 | $src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
| 297 | $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'; |
---|
| 298 | $url.= '&image_id='.$category['representative_picture_id']; |
---|
[1131] | 299 | |
---|
[809] | 300 | $template->assign_block_vars( |
---|
| 301 | 'representant.picture', |
---|
| 302 | array( |
---|
| 303 | 'SRC' => $src, |
---|
| 304 | 'URL' => $url |
---|
| 305 | ) |
---|
| 306 | ); |
---|
| 307 | } |
---|
| 308 | else // $category['nb_images'] > 0 |
---|
| 309 | { |
---|
| 310 | $template->assign_block_vars('representant.random', array()); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | // can the admin choose to set a new random representant ? |
---|
| 314 | if ($category['nb_images'] > 0) |
---|
| 315 | { |
---|
| 316 | $template->assign_block_vars('representant.set_random', array()); |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | // can the admin delete the current representant ? |
---|
| 320 | if ( |
---|
| 321 | ($category['nb_images'] > 0 |
---|
| 322 | and $conf['allow_random_representative']) |
---|
| 323 | or |
---|
| 324 | ($category['nb_images'] == 0 |
---|
| 325 | and !empty($category['representative_picture_id']))) |
---|
| 326 | { |
---|
| 327 | $template->assign_block_vars('representant.delete_representant', array()); |
---|
| 328 | } |
---|
[633] | 329 | } |
---|
| 330 | |
---|
[1121] | 331 | if (!$category['is_virtual']) |
---|
[68] | 332 | { |
---|
[635] | 333 | $template->assign_block_vars( |
---|
| 334 | 'storage', |
---|
| 335 | array('CATEGORY_DIR'=>preg_replace('/\/$/', |
---|
| 336 | '', |
---|
| 337 | get_complete_dir($category['id'])))); |
---|
[68] | 338 | } |
---|
[809] | 339 | else |
---|
| 340 | { |
---|
| 341 | $template->assign_block_vars( |
---|
| 342 | 'delete', |
---|
| 343 | array( |
---|
[1004] | 344 | 'URL'=>$self_url.'&delete='.$category['id'] |
---|
[809] | 345 | ) |
---|
| 346 | ); |
---|
[403] | 347 | |
---|
[809] | 348 | $template->assign_block_vars('move', array()); |
---|
| 349 | |
---|
| 350 | // the category can be moved in any category but in itself, in any |
---|
| 351 | // sub-category |
---|
| 352 | $unmovables = get_subcat_ids(array($category['id'])); |
---|
[1131] | 353 | |
---|
[809] | 354 | $blockname = 'move.parent_option'; |
---|
| 355 | |
---|
| 356 | $template->assign_block_vars( |
---|
| 357 | $blockname, |
---|
| 358 | array( |
---|
| 359 | 'SELECTED' |
---|
| 360 | => empty($category['id_uppercat']) ? 'selected="selected"' : '', |
---|
| 361 | 'VALUE'=> 0, |
---|
| 362 | 'OPTION' => '------------' |
---|
| 363 | ) |
---|
| 364 | ); |
---|
[1131] | 365 | |
---|
[809] | 366 | $query = ' |
---|
| 367 | SELECT id,name,uppercats,global_rank |
---|
| 368 | FROM '.CATEGORIES_TABLE.' |
---|
| 369 | WHERE id NOT IN ('.implode(',', $unmovables).') |
---|
| 370 | ;'; |
---|
[1131] | 371 | |
---|
[809] | 372 | display_select_cat_wrapper( |
---|
| 373 | $query, |
---|
| 374 | empty($category['id_uppercat']) ? array() : array($category['id_uppercat']), |
---|
| 375 | $blockname |
---|
| 376 | ); |
---|
| 377 | } |
---|
| 378 | |
---|
[1058] | 379 | $category['cat_dir'] = get_complete_dir($_GET['cat_id']); |
---|
| 380 | if (is_numeric($category['site_id']) and url_is_remote($category['cat_dir']) ) |
---|
[68] | 381 | { |
---|
[632] | 382 | $query = ' |
---|
| 383 | SELECT galleries_url |
---|
| 384 | FROM '.SITES_TABLE.' |
---|
| 385 | WHERE id = '.$category['site_id'].' |
---|
| 386 | ;'; |
---|
| 387 | list($galleries_url) = mysql_fetch_array(pwg_query($query)); |
---|
| 388 | $template->assign_block_vars('server', array('SITE_URL' => $galleries_url)); |
---|
[68] | 389 | } |
---|
[403] | 390 | |
---|
[1058] | 391 | if (!$category['is_virtual'] and !url_is_remote($category['cat_dir']) ) |
---|
| 392 | { |
---|
| 393 | $template->assign_block_vars('upload' ,array()); |
---|
| 394 | } |
---|
| 395 | |
---|
[1064] | 396 | $blockname = 'category_option_parent'; |
---|
| 397 | |
---|
| 398 | $template->assign_block_vars( |
---|
| 399 | $blockname, |
---|
| 400 | array( |
---|
| 401 | 'VALUE'=> 0, |
---|
| 402 | 'OPTION' => '------------' |
---|
| 403 | ) |
---|
| 404 | ); |
---|
| 405 | |
---|
| 406 | $query = ' |
---|
| 407 | SELECT id,name,uppercats,global_rank |
---|
| 408 | FROM '.CATEGORIES_TABLE.' |
---|
| 409 | ;'; |
---|
| 410 | |
---|
| 411 | display_select_cat_wrapper( |
---|
| 412 | $query, |
---|
| 413 | array(), |
---|
| 414 | $blockname |
---|
| 415 | ); |
---|
| 416 | |
---|
| 417 | // destination categories |
---|
| 418 | $query = ' |
---|
[1121] | 419 | SELECT id,name,uppercats,global_rank |
---|
[1064] | 420 | FROM '.CATEGORIES_TABLE.' |
---|
[1121] | 421 | WHERE id != '.$category['id'].' |
---|
[1064] | 422 | ;'; |
---|
| 423 | |
---|
[1121] | 424 | display_select_cat_wrapper( |
---|
| 425 | $query, |
---|
| 426 | array(), |
---|
| 427 | 'category_option_destination' |
---|
[1064] | 428 | ); |
---|
| 429 | |
---|
| 430 | |
---|
[21] | 431 | //----------------------------------------------------------- sending html code |
---|
[403] | 432 | $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); |
---|
[362] | 433 | ?> |
---|