Changeset 254 for branches/release-1_3/admin/cat_list.php
- Timestamp:
- Jan 3, 2004, 10:29:13 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/release-1_3/admin/cat_list.php
r198 r254 19 19 ***************************************************************************/ 20 20 include_once( './include/isadmin.inc.php' ); 21 //------------------------------------------------ expand categories management 22 // creation of the array containing the cat ids to expand 23 // $page['tab_expand'] contains an array with the category ids 24 // $page['expand'] contains the string to display in URL with comma 25 26 // if there is less than $conf['max_LOV_categories'] categories, they are 27 // all expande 28 $query = 'SELECT COUNT(id) AS nb_total_categories'; 29 $query.= ' FROM '.PREFIX_TABLE.'categories'; 30 $query.= ';'; 31 $row = mysql_fetch_array( mysql_query( $query ) ); 32 if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] 33 or $_GET['expand'] == 'all' ) 34 { 35 $page['tab_expand'] = array(); 36 $page['expand'] = 'all'; 37 } 38 else 39 { 40 $page['tab_expand'] = array(); 41 if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' ) 42 { 43 $tab_expand = explode( ',', $_GET['expand'] ); 44 foreach ( $tab_expand as $id ) { 45 if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id ); 46 } 47 } 48 $page['tab_expand'] = array_unique( $page['tab_expand'] ); 49 $page['expand'] = implode( ',', $page['tab_expand'] ); 50 } 21 51 //----------------------------------------------------- template initialization 22 52 $sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_list.vtp' ); 23 53 $tpl = array( 'cat_edit','cat_up','cat_down','cat_image_info', 24 54 'cat_permission','cat_update','cat_add','cat_parent','submit', 25 'cat_virtual','delete','cat_first','cat_last' );55 'cat_virtual','delete','cat_first','cat_last','errors_title' ); 26 56 templatize_array( $tpl, 'lang', $sub ); 27 57 $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); … … 30 60 if ( isset( $_POST['submit'] ) ) 31 61 { 32 if ( !preg_match( '/^\s*$/', $_POST['virtual_name'] ) ) 62 // is the given category name only containing blank spaces ? 63 if ( preg_match( '/^\s*$/', $_POST['virtual_name'] ) ) 64 array_push( $errors, $lang['cat_error_name'] ); 65 // does the uppercat id exists in the database ? 66 if ( $_POST['associate'] == '' ) 67 { 68 $_POST['associate'] = -1; 69 } 70 else if ( !is_numeric( $_POST['associate'] ) ) 71 { 72 array_push( $errors, $lang['cat_unknown_id'] ); 73 } 74 else 75 { 76 $query = 'SELECT id'; 77 $query.= ' FROM '.PREFIX_TABLE.'categories'; 78 $query.= ' WHERE id = '.$_POST['associate']; 79 $query.= ';'; 80 if ( mysql_num_rows( mysql_query( $query ) ) == 0 ) 81 array_push( $errors, $lang['cat_unknown_id'] ); 82 } 83 84 if ( count( $errors ) == 0 ) 33 85 { 34 86 // we have then to add the virtual category … … 42 94 $query.= ';'; 43 95 mysql_query( $query ); 44 } 45 else 46 { 47 array_push( $errors, $lang['cat_error_name'] ); 96 synchronize_all_users(); 48 97 } 49 98 } … … 172 221 { 173 222 delete_category( $_GET['delete'] ); 223 synchronize_all_users(); 174 224 } 175 225 //------------------------------------------------------------------ reordering … … 261 311 262 312 $vtp->addSession( $sub, 'cat' ); 313 // is the category expanded or not ? 314 if ( $page['expand'] == 'all' ) 315 { 316 $vtp->addSession( $sub, 'bullet_wo_link' ); 317 $vtp->closeSession( $sub, 'bullet_wo_link' ); 318 } 319 else if ( in_array( $row['id'], $page['tab_expand'] ) ) 320 { 321 $vtp->addSession( $sub, 'bullet_expanded' ); 322 $tab_expand = array_diff( $page['tab_expand'], array( $row['id'] ) ); 323 $expand = implode( ',', $tab_expand ); 324 $url = './admin.php?page=cat_list&expand='.$expand; 325 $vtp->setVar( $sub, 'bullet_expanded.link', add_session_id( $url ) ); 326 $vtp->closeSession( $sub, 'bullet_expanded' ); 327 } 328 else 329 { 330 $vtp->addSession( $sub, 'bullet_collapsed' ); 331 $tab_expand = array_merge( $page['tab_expand'], array( $row['id'] ) ); 332 $expand = implode( ',', $tab_expand ); 333 $url = './admin.php?page=cat_list&expand='.$expand; 334 $vtp->setVar( $sub, 'bullet_collapsed.link', add_session_id( $url ) ); 335 $vtp->closeSession( $sub, 'bullet_collapsed' ); 336 } 337 263 338 $vtp->setVar( $sub, 'cat.td', $td ); 264 339 $vtp->setVar( $sub, 'cat.class', $class ); 265 340 $vtp->setVar( $sub, 'cat.indent', $indent ); 266 341 $vtp->setVar( $sub, 'cat.name', $row['name'] ); 267 $vtp->setVar( $sub, 'cat.id', $row['id'] ); 342 268 343 if ( $row['dir'] != '' ) 269 344 { … … 281 356 // category can be deleted 282 357 $vtp->addSession( $sub, 'delete' ); 283 $url = './admin.php?page=cat_list&delete='.$row['id']; 358 $url = './admin.php?page=cat_list&expand='.$page['expand']; 359 $url.= '&delete='.$row['id']; 284 360 $vtp->setVar( $sub, 'delete.delete_url', add_session_id( $url ) ); 285 361 $vtp->closeSession( $sub, 'delete' ); … … 300 376 { 301 377 $vtp->addSession( $sub, 'up' ); 302 $ vtp->setVar( $sub, 'up.id', $row['id'] );303 $url = add_session_id( './admin.php?page=cat_list&up='.$row['id'] );304 $vtp->setVar( $sub, 'up.up_url', $url);378 $url = './admin.php?page=cat_list&expand='.$page['expand']; 379 $url.= '&up='.$row['id']; 380 $vtp->setVar( $sub, 'up.up_url', add_session_id( $url ) ); 305 381 $vtp->closeSession( $sub, 'up' ); 306 382 } … … 308 384 { 309 385 $vtp->addSession( $sub, 'no_up' ); 310 $ vtp->setVar( $sub, 'no_up.id', $row['id'] );311 $url = add_session_id( './admin.php?page=cat_list&last='.$row['id']);312 $vtp->setVar( $sub, 'no_up.last_url', $url);386 $url = './admin.php?page=cat_list&expand='.$page['expand']; 387 $url.= '&last='.$row['id']; 388 $vtp->setVar( $sub, 'no_up.last_url', add_session_id( $url ) ); 313 389 $vtp->closeSession( $sub, 'no_up' ); 314 390 } … … 316 392 { 317 393 $vtp->addSession( $sub, 'down' ); 318 $ vtp->setVar( $sub, 'down.id', $row['id'] );319 $url = add_session_id( './admin.php?page=cat_list&down='.$row['id']);320 $vtp->setVar( $sub, 'down.down_url', $url);394 $url = './admin.php?page=cat_list&expand='.$page['expand']; 395 $url.= '&down='.$row['id']; 396 $vtp->setVar( $sub, 'down.down_url', add_session_id( $url ) ); 321 397 $vtp->closeSession( $sub, 'down' ); 322 398 } … … 324 400 { 325 401 $vtp->addSession( $sub, 'no_down' ); 326 $ vtp->setVar( $sub, 'no_down.id', $row['id'] );327 $url = add_session_id('./admin.php?page=cat_list&first='.$row['id']);328 $vtp->setVar( $sub, 'no_down.first_url', $url);402 $url = './admin.php?page=cat_list&expand='.$page['expand']; 403 $url.= '&first='.$row['id']; 404 $vtp->setVar( $sub, 'no_down.first_url', add_session_id( $url ) ); 329 405 $vtp->closeSession( $sub, 'no_down' ); 330 406 } … … 332 408 { 333 409 $vtp->addSession( $sub, 'image_info' ); 334 $url = add_session_id( './admin.php?page=infos_images&cat_id=' 335 .$row['id'] ); 336 $vtp->setVar( $sub, 'image_info.image_info_url', $url ); 410 $url = './admin.php?page=infos_images&cat_id='.$row['id']; 411 $vtp->setVar( $sub, 'image_info.image_info_url', add_session_id($url) ); 337 412 $vtp->closeSession( $sub, 'image_info' ); 338 413 } … … 372 447 $vtp->closeSession( $sub, 'cat' ); 373 448 374 display_cat_manager( $row['id'], $indent.str_repeat( ' ', 4 ), 375 $subcat_visible, $level + 1 ); 449 if ( in_array( $row['id'], $page['tab_expand'] ) 450 or $page['expand'] == 'all') 451 display_cat_manager( $row['id'], $indent.str_repeat( ' ', 4 ), 452 $subcat_visible, $level + 1 ); 376 453 } 377 454 } 378 455 display_cat_manager( 'NULL', str_repeat( ' ', 4 ), true, 0 ); 379 456 // add a virtual category ? 380 $vtp->addSession( $sub, 'associate_cat' ); 381 $vtp->setVar( $sub, 'associate_cat.value', '-1' ); 382 $vtp->setVar( $sub, 'associate_cat.content', '' ); 383 $vtp->closeSession( $sub, 'associate_cat' ); 384 $page['plain_structure'] = get_plain_structure(); 385 $structure = create_structure( '', array() ); 386 display_categories( $structure, ' ' ); 457 // We only show a List Of Values if the number of categories is less than 458 // $conf['max_LOV_categories'] 459 $query = 'SELECT COUNT(id) AS nb_total_categories'; 460 $query.= ' FROM '.PREFIX_TABLE.'categories'; 461 $query.= ';'; 462 $row = mysql_fetch_array( mysql_query( $query ) ); 463 if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] ) 464 { 465 $vtp->addSession( $sub, 'associate_LOV' ); 466 $vtp->addSession( $sub, 'associate_cat' ); 467 $vtp->setVar( $sub, 'associate_cat.value', '-1' ); 468 $vtp->setVar( $sub, 'associate_cat.content', '' ); 469 $vtp->closeSession( $sub, 'associate_cat' ); 470 $page['plain_structure'] = get_plain_structure( true ); 471 $structure = create_structure( '', array() ); 472 display_categories( $structure, ' ' ); 473 $vtp->closeSession( $sub, 'associate_LOV' ); 474 } 475 // else, we only display a small text field, we suppose the administrator 476 // knows the id of its category 477 else 478 { 479 $vtp->addSession( $sub, 'associate_text' ); 480 $vtp->closeSession( $sub, 'associate_text' ); 481 } 387 482 //----------------------------------------------------------- sending html code 388 483 $vtp->Parse( $handle , 'sub', $sub );
Note: See TracChangeset
for help on using the changeset viewer.