Open( '../template/'.$user['template'].'/admin/cat.vtp' ); // language $vtp->setGlobalVar( $sub, 'cat_edit', $lang['cat_edit'] ); $vtp->setGlobalVar( $sub, 'cat_up', $lang['cat_up'] ); $vtp->setGlobalVar( $sub, 'cat_down', $lang['cat_down'] ); $vtp->setGlobalVar( $sub, 'cat_image_info', $lang['cat_image_info'] ); $vtp->setGlobalVar( $sub, 'cat_permission', $lang['cat_permission'] ); $vtp->setGlobalVar( $sub, 'cat_update', $lang['cat_update'] ); //--------------------------------------------------------------- rank updates if ( isset( $_GET['up'] ) && is_numeric( $_GET['up'] ) ) { // 1. searching level (id_uppercat) // and rank of the category to move $query = 'select id_uppercat,rank'; $query.= ' from '.$prefixeTable.'categories'; $query.= ' where id = '.$_GET['up']; $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); $level = $row['id_uppercat']; $rank = $row['rank']; // 2. searching the id and the rank of the category // just above at the same level $query = 'select id,rank'; $query.= ' from '.$prefixeTable.'categories'; $query.= ' where rank < '.$rank; if ( $level == '' ) { $query.= ' and id_uppercat is null'; } else { $query.= ' and id_uppercat = '.$level; } $query.= ' order by rank desc'; $query.= ' limit 0,1'; $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); $new_rank = $row['rank']; $replaced_cat = $row['id']; // 3. exchanging ranks between the two categories $query = 'update '.$prefixeTable.'categories'; $query.= ' set rank = '.$new_rank; $query.= ' where id = '.$_GET['up']; $query.= ';'; mysql_query( $query ); $query = 'update '.$prefixeTable.'categories'; $query.= ' set rank = '.$rank; $query.= ' where id = '.$replaced_cat; $query.= ';'; mysql_query( $query ); } if ( isset( $_GET['down'] ) && is_numeric( $_GET['down'] ) ) { // 1. searching level (id_uppercat) // and rank of the category to move $query = 'select id_uppercat,rank'; $query.= ' from '.$prefixeTable.'categories'; $query.= ' where id = '.$_GET['down']; $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); $level = $row['id_uppercat']; $rank = $row['rank']; // 2. searching the id and the rank of the category // just below at the same level $query = 'select id,rank'; $query.= ' from '.$prefixeTable.'categories'; $query.= ' where rank > '.$rank; if ( $level == '' ) { $query.= ' and id_uppercat is null'; } else { $query.= ' and id_uppercat = '.$level; } $query.= ' order by rank asc'; $query.= ' limit 0,1'; $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); $new_rank = $row['rank']; $replaced_cat = $row['id']; // 3. exchanging ranks between the two categories $query = 'update '.$prefixeTable.'categories'; $query.= ' set rank = '.$new_rank; $query.= ' where id = '.$_GET['down']; $query.= ';'; mysql_query( $query ); $query = 'update '.$prefixeTable.'categories'; $query.= ' set rank = '.$rank; $query.= ' where id = '.$replaced_cat; $query.= ';'; mysql_query( $query ); } //------------------------------------------------------------------ reordering function ordering( $id_uppercat ) { global $prefixeTable; $rank = 1; $query = 'select id'; $query.= ' from '.$prefixeTable.'categories'; if ( !is_numeric( $id_uppercat ) ) { $query.= ' where id_uppercat is NULL'; } else { $query.= ' where id_uppercat = '.$id_uppercat; } $query.= ' order by rank asc, dir asc'; $query.= ';'; $result = mysql_query( $query ); while ( $row = mysql_fetch_array( $result ) ) { $query = 'update '.$prefixeTable.'categories'; $query.= ' set rank = '.$rank; $query.= ' where id = '.$row['id']; $query.= ';'; mysql_query( $query ); $rank++; ordering( $row['id'] ); } } ordering( 'NULL' ); //----------------------------------------------------affichage de la page function display_cat_manager( $id_uppercat, $indent, $uppercat_visible, $level ) { global $prefixeTable,$lang,$conf,$sub,$vtp; // searching the min_rank and the max_rank of the category $query = 'select min(rank) as min, max(rank) as max'; $query.= ' from '.$prefixeTable.'categories'; if ( !is_numeric( $id_uppercat ) ) { $query.= ' where id_uppercat is NULL'; } else { $query.= ' where id_uppercat = '.$id_uppercat; } $query.= ';'; $result = mysql_query( $query ); $row = mysql_fetch_array( $result ); $min_rank = $row['min']; $max_rank = $row['max']; // will we use