<?php
if ( !defined( "SAXUE_CORE_INCLUDE" ) ) {
		include "../../core.php";
} 
//检测权限
if ( empty( $_SESSION['saxueAdminId'] ) && empty( $_SESSION['saxueUserId'] ) ) {
		saxue_printfail( LANG_NO_PERMISSION );
}
$_pagesize = 20;
saxue_getconfigs( "configs", "article" );
saxue_getconfigs( "datatable", "article" );
if ( empty( $_REQUEST['tbnum'] ) || !array_key_exists( $_REQUEST['tbnum'], $saxueDatatable['article'] ) ) {
		$_REQUEST['tbnum'] = $saxueConfigs['article']['tbnum'];
}
include SAXUE_ROOT_PATH . "/model/article.php";
$article_handler = &saxuearticlehandler :: getinstance( "saxuearticlehandler" );
$datatable = $saxueDatatable['article'][$_REQUEST['tbnum']];
saxue_getconfigs( "cate", "article" );
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) ) $GLOBALS['_REQUEST']['page'] = 1;
$sql = saxue_dbprefix( "article" ) . " AS a,{$datatable} AS b WHERE a.status=1 AND a.isslide>0";
if ( !empty( $_REQUEST['cid'] ) ) {
		if ( $saxueCate['article'][$_REQUEST['cid']]['pid'] ) {
				$sql .= " AND a.cid=" . $_REQUEST['cid'];
		} else {
				$sql .= " AND a.pid=" . $_REQUEST['cid'];
		} 
}
if ( isset( $_REQUEST['isslide'] ) && $_REQUEST['isslide'] != '' ) {
		$sql .= " AND a.isslide=" . $_REQUEST['isslide'];
}
if ( !empty( $_REQUEST['keytype'] ) && !empty( $_REQUEST['keyword'] ) ) {
		if ( $_REQUEST['keytype'] == 'title' ) $sql .= " AND b.title REGEXP '" . trim( $_REQUEST['keyword'] ) . "'";
		else $sql .= " AND a." . $_REQUEST['keytype'] . "=" . intval( $_REQUEST['keyword'] );
}
$sql .= " AND b.aid=a.aid";
$_res = $article_handler -> db -> query( "SELECT COUNT(*) FROM " . $sql );
if ( !$_res ) {
		$listrows = 0;
} else {
		list( $listrows ) = $article_handler -> db -> fetchrow( $_res );
} 
$sql = "SELECT a.*,b.* FROM " . $sql . " ORDER BY a.aid DESC LIMIT " . ( ( $_REQUEST['page'] - 1 ) * $_pagesize ) . ", " . $_pagesize;
$res = $article_handler -> db -> query( $sql );
$rows = array();
$k = 0;
while ( $v = $article_handler -> getobject( $res ) ) {
		$rows[$k] = $v -> getvars( 'n' );
		$rows[$k]['cname'] = $saxueCate['article'][$rows[$k]['cid']]['cname'];
		$rows[$k]['curl'] = $saxueCate['article'][$rows[$k]['cid']]['curl'];
		$rows[$k]['pname'] = $saxueCate['article'][$rows[$k]['pid']]['cname'];
		$rows[$k]['purl'] = $saxueCate['article'][$rows[$k]['pid']]['curl'];
		++$k;
} 
include SAXUE_ADMIN_PATH . "/header.php";
$saxueTpl -> assign_by_ref( "rows", $rows );
$saxueTpl -> assign_by_ref( "tables", $saxueDatatable['article'] );
include SAXUE_ROOT_PATH . "/lib/util/page.php";
$jumppage = new saxuepage( $listrows, $_pagesize, $_REQUEST['page'] );
$jumppage -> setlink( "", true, true );
$saxueTpl -> assign( "url_jumppage", $jumppage -> whole_bar() );
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'] ) );
$saxueTpl -> assign( "cates", $cates );
$saxueTset['saxue_contents_template'] = SAXUE_WEB_PATH . "/article/templates/changegallery.html";
include SAXUE_ADMIN_PATH . "/footer.php";