Ignore:
Timestamp:
Jan 3, 2004, 10:29:13 PM (21 years ago)
Author:
z0rglub
Message:
  • if there is more than $confmax_LOV_categories categories, there is no list of values of parent for adding virtual category
  • synchronize_all_users if adding or deleting a virtual category
  • in the url link to up,first,down,last #id is not shown anymore
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/release-1_3/admin/cat_list.php

    r198 r254  
    1919 ***************************************************************************/
    2020include_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 ) );
     32if ( $row['nb_total_categories'] < $conf['max_LOV_categories']
     33     or $_GET['expand'] == 'all' )
     34{
     35  $page['tab_expand'] = array();
     36  $page['expand'] = 'all';
     37}
     38else
     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}
    2151//----------------------------------------------------- template initialization
    2252$sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_list.vtp' );
    2353$tpl = array( 'cat_edit','cat_up','cat_down','cat_image_info',
    2454              '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' );
    2656templatize_array( $tpl, 'lang', $sub );
    2757$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
     
    3060if ( isset( $_POST['submit'] ) )
    3161{
    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 )
    3385  {
    3486    // we have then to add the virtual category
     
    4294    $query.= ';';
    4395    mysql_query( $query );
    44   }
    45   else
    46   {
    47     array_push( $errors, $lang['cat_error_name'] );
     96    synchronize_all_users();
    4897  }
    4998}
     
    172221{
    173222  delete_category( $_GET['delete'] );
     223  synchronize_all_users();
    174224}
    175225//------------------------------------------------------------------ reordering
     
    261311
    262312    $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&amp;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&amp;expand='.$expand;
     334      $vtp->setVar( $sub, 'bullet_collapsed.link', add_session_id( $url ) );
     335      $vtp->closeSession( $sub, 'bullet_collapsed' );
     336    }
     337   
    263338    $vtp->setVar( $sub, 'cat.td', $td );
    264339    $vtp->setVar( $sub, 'cat.class', $class );
    265340    $vtp->setVar( $sub, 'cat.indent', $indent );
    266341    $vtp->setVar( $sub, 'cat.name', $row['name'] );
    267     $vtp->setVar( $sub, 'cat.id', $row['id'] );
     342
    268343    if ( $row['dir'] != '' )
    269344    {
     
    281356      // category can be deleted
    282357      $vtp->addSession( $sub, 'delete' );
    283       $url = './admin.php?page=cat_list&amp;delete='.$row['id'];
     358      $url = './admin.php?page=cat_list&amp;expand='.$page['expand'];
     359      $url.= '&amp;delete='.$row['id'];
    284360      $vtp->setVar( $sub, 'delete.delete_url', add_session_id( $url ) );
    285361      $vtp->closeSession( $sub, 'delete' );
     
    300376    {
    301377      $vtp->addSession( $sub, 'up' );
    302       $vtp->setVar( $sub, 'up.id', $row['id'] );
    303       $url = add_session_id( './admin.php?page=cat_list&amp;up='.$row['id'] );
    304       $vtp->setVar( $sub, 'up.up_url', $url );
     378      $url = './admin.php?page=cat_list&amp;expand='.$page['expand'];
     379      $url.= '&amp;up='.$row['id'];
     380      $vtp->setVar( $sub, 'up.up_url', add_session_id( $url ) );
    305381      $vtp->closeSession( $sub, 'up' );
    306382    }
     
    308384    {
    309385      $vtp->addSession( $sub, 'no_up' );
    310       $vtp->setVar( $sub, 'no_up.id', $row['id'] );
    311       $url = add_session_id( './admin.php?page=cat_list&amp;last='.$row['id']);
    312       $vtp->setVar( $sub, 'no_up.last_url', $url );
     386      $url = './admin.php?page=cat_list&amp;expand='.$page['expand'];
     387      $url.= '&amp;last='.$row['id'];
     388      $vtp->setVar( $sub, 'no_up.last_url', add_session_id( $url ) );
    313389      $vtp->closeSession( $sub, 'no_up' );
    314390    }
     
    316392    {
    317393      $vtp->addSession( $sub, 'down' );
    318       $vtp->setVar( $sub, 'down.id', $row['id'] );
    319       $url = add_session_id( './admin.php?page=cat_list&amp;down='.$row['id']);
    320       $vtp->setVar( $sub, 'down.down_url', $url );
     394      $url = './admin.php?page=cat_list&amp;expand='.$page['expand'];
     395      $url.= '&amp;down='.$row['id'];
     396      $vtp->setVar( $sub, 'down.down_url', add_session_id( $url ) );
    321397      $vtp->closeSession( $sub, 'down' );
    322398    }
     
    324400    {
    325401      $vtp->addSession( $sub, 'no_down' );
    326       $vtp->setVar( $sub, 'no_down.id', $row['id'] );
    327       $url = add_session_id('./admin.php?page=cat_list&amp;first='.$row['id']);
    328       $vtp->setVar( $sub, 'no_down.first_url', $url );
     402      $url = './admin.php?page=cat_list&amp;expand='.$page['expand'];
     403      $url.= '&amp;first='.$row['id'];
     404      $vtp->setVar( $sub, 'no_down.first_url', add_session_id( $url ) );
    329405      $vtp->closeSession( $sub, 'no_down' );
    330406    }
     
    332408    {
    333409      $vtp->addSession( $sub, 'image_info' );
    334       $url = add_session_id( './admin.php?page=infos_images&amp;cat_id='
    335                              .$row['id'] );
    336       $vtp->setVar( $sub, 'image_info.image_info_url', $url );
     410      $url = './admin.php?page=infos_images&amp;cat_id='.$row['id'];
     411      $vtp->setVar( $sub, 'image_info.image_info_url', add_session_id($url) );
    337412      $vtp->closeSession( $sub, 'image_info' );
    338413    }
     
    372447    $vtp->closeSession( $sub, 'cat' );
    373448
    374     display_cat_manager( $row['id'], $indent.str_repeat( '&nbsp', 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( '&nbsp', 4 ),
     452                           $subcat_visible, $level + 1 );
    376453  }
    377454}
    378455display_cat_manager( 'NULL', str_repeat( '&nbsp', 4 ), true, 0 );
    379456// 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, '&nbsp;' );
     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 ) );
     463if ( $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, '&nbsp;' );
     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
     477else
     478{
     479  $vtp->addSession( $sub, 'associate_text' );
     480  $vtp->closeSession( $sub, 'associate_text' );
     481}
    387482//----------------------------------------------------------- sending html code
    388483$vtp->Parse( $handle , 'sub', $sub );
Note: See TracChangeset for help on using the changeset viewer.