* * * ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; * * * ***************************************************************************/ include_once( './include/isadmin.inc.php' ); //----------------------------------------------------- template initialization $sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_list.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 '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'categories'; $query.= ' SET rank = '.$new_rank; $query.= ' WHERE id = '.$_GET['up']; $query.= ';'; mysql_query( $query ); $query = 'UPDATE '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'categories'; $query.= ' SET rank = '.$new_rank; $query.= ' WHERE id = '.$_GET['down']; $query.= ';'; mysql_query( $query ); $query = 'UPDATE '.PREFIX_TABLE.'categories'; $query.= ' SET rank = '.$rank; $query.= ' WHERE id = '.$replaced_cat; $query.= ';'; mysql_query( $query ); } //------------------------------------------------------------------ reordering function ordering( $id_uppercat ) { $rank = 1; $query = 'SELECT id'; $query.= ' FROM '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'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 $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 '.PREFIX_TABLE.'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