<?php
if ( !defined( "SAXUE_CORE_INCLUDE" ) ) {
		include "../../core.php";
} 
//检测权限
if ( empty( $_SESSION['saxueAdminId'] ) && empty( $_SESSION['saxueUserId'] ) ) {
		saxue_printfail( LANG_NO_PERMISSION );
}
include SAXUE_ROOT_PATH . "/model/tag.php";
$tag_handler = &saxuetaghandler :: getinstance( "saxuetaghandler" );
saxue_getconfigs( "cate", "article" );
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) ) $GLOBALS['_REQUEST']['page'] = 1;
$pagesize = 70; //每页显示
$criteria = new criteriacompo();
if ( !empty( $_REQUEST['cid'] ) ) {
		$criteria -> add( new criteria( 'cid', '(' . $saxueCate['article'][$_REQUEST['cid']]['arrchild'] . ')', 'IN' ) );
} elseif ( isset( $_REQUEST['cid'] ) && $_REQUEST['cid'] == '0' ) {
		$criteria -> add( new criteria( 'cid', 0 ) );
}
if ( !empty( $_REQUEST['isgood'] ) ) {
		$criteria -> add( new criteria( 'isgood', 1 ) );
} 
if ( !empty( $_REQUEST['tagname'] ) ) {
		$criteria -> add( new criteria( 'tagname', $_REQUEST['tagname'], 'REGEXP' ) );
} 
if ( empty( $_REQUEST['orderby'] ) ) {
		$_REQUEST['orderby'] = 0;
}
switch ( $_REQUEST['orderby'] ) {
		case 0:
				$criteria -> setsort( "tagid" );
				$criteria -> setorder( "DESC" );
				break;
		case 1:
				$criteria -> setsort( "tagid" );
				$criteria -> setorder( "ASC" );
				break;
		case 2:
				$criteria -> setsort( "counts" );
				$criteria -> setorder( "DESC" );
				break;
		case 3:
				$criteria -> setsort( "counts" );
				$criteria -> setorder( "ASC" );
				break;
		case 4:
				$criteria -> setsort( "views" );
				$criteria -> setorder( "DESC" );
				break;
		case 5:
				$criteria -> setsort( "views" );
				$criteria -> setorder( "ASC" );
				break;
}
$criteria -> setlimit( $pagesize );
$criteria -> setstart( ( $_REQUEST['page'] - 1 ) * $pagesize );
$tag_handler -> queryobjects( $criteria );
$rows = array();
$k = 0;
while ( $v = $tag_handler -> getobject() ) {
		$rows[$k] = $v -> getvars( 'n' );
		++$k;
} 
include SAXUE_ROOT_PATH . "/lib/util/tree.php";
$tree = new tree;
$tree -> icon = array( '&nbsp;<span class="f_tree">│</span>&nbsp;', '&nbsp;<span class="f_tree">├─</span> ', '&nbsp;<span class="f_tree">└─</span> ' );
$tree -> nbsp = '&nbsp;';
$tree -> mid = 'cid';
$tree -> pid = 'pid';
$tree -> init( $saxueCate['article'] );
$str = "<option value=\$cid \$selected>\$spacer\$cname</option>";
$cates = $tree -> get_tree( 0, $str, intval( $_REQUEST['cid'] ) );
include_once( SAXUE_ADMIN_PATH . "/header.php" );
$saxueTpl -> assign_by_ref( "rows", $rows );
$saxueTpl -> assign_by_ref("cates", $cates);
include_once( SAXUE_ROOT_PATH . "/lib/util/page.php" );
$jumppage = new saxuepage( $tag_handler -> getcount( $criteria ), $pagesize, $_REQUEST['page'], 5 );
$jumppage -> setlink( "", true, true );
$saxueTpl -> assign( "url_jumppage", $jumppage -> whole_bar() );
$saxueTset['saxue_contents_template'] = SAXUE_WEB_PATH . "/tag/templates/changetag.html";
include_once( SAXUE_ADMIN_PATH . "/footer.php" );