<?php
if ( !defined( "SAXUE_CORE_INCLUDE" ) ) {
		include "../../core.php";
} 
saxue_checkpower( 'artreport' );
include SAXUE_ROOT_PATH . "/model/article_report.php";
$report_handler = &saxuearticlereporthandler :: getinstance( "saxuearticlereporthandler" );
if ( !empty( $_REQUEST['action'] ) ) {
		if ( empty( $_REQUEST['ids'] ) || !is_array( $_REQUEST['ids'] ) || count( $_REQUEST['ids'] ) == 0 ) {
				saxue_printfail( '请选择文章' );
		}
		@set_time_limit( 0 );
		switch ( $_REQUEST['action'] ) {
				case 'delete':
						$report_handler -> db -> query( "DELETE FROM " . saxue_dbprefix( "article_report" ) . " WHERE aid IN(" . implode( ',', $_REQUEST['ids'] ) . ")" );
						break;
				case 'sethandled':
						$handled = array();
						$handled['ishandle'] = 1;
						$handled['handletime'] = SAXUE_NOW_TIME;
						$report_handler -> updatefields( $handled, 'aid IN(' . implode( ',', $_REQUEST['ids'] ) . ') AND ishandle=0' );
						break;
				case 'delart':
						$criteria = new criteriacompo( new criteria( 'aid', '(' . implode( ',', $_REQUEST['ids'] ) . ')', 'IN' ) );
						$criteria -> add( new criteria( 'ishandle', 0 ) );
						$report_handler -> queryobjects( $criteria );
						$aids = array();
						while ( $v = $report_handler -> getobject() ) {
								$aids[] = $v -> getvar( 'aid' );
						} 
						include SAXUE_ROOT_PATH . "/model/article.php";
						$article_handler = &saxuearticlehandler :: getinstance( "saxuearticlehandler" );
						$article_handler -> queryobjects( new criteria( 'aid', '(' . implode( ',', $aids ) . ')', 'IN' ) );
						$tables = array();
						while ( $v = $article_handler -> getobject() ) {
								$aid = $v -> getvar( 'aid' );
								$tbnum = $v -> getvar( 'tbnum' );
								$tables[$tbnum][] = $aid;
						}  
						if ( count( $tables ) > 0 ) {
								include SAXUE_ROOT_PATH . "/common/funarticle.php";
								foreach ( $tables as $tbnum => $ids  ) {
										DelArticle( $ids, $tbnum );
								}
						}
						$handled = array();
						$handled['ishandle'] = 2;
						$handled['handletime'] = SAXUE_NOW_TIME;
						$report_handler -> updatefields( $handled, 'aid IN(' . implode( ',', $aids ) . ')' );
						break;
		}
		if ( empty( $_REQUEST['jumpurl'] ) ) {
				saxue_jumppage( 'report.php', LANG_DO_SUCCESS );
		} else {
				saxue_jumppage( $_REQUEST['jumpurl'], LANG_DO_SUCCESS );
		}
}
saxue_getconfigs( "reporttype", "article" );
if ( empty( $_REQUEST['pagesize'] ) || !is_numeric( $_REQUEST['pagesize'] ) || !in_array( $_REQUEST['pagesize'], array( '20', '30', '50', '100' ) ) ) $_REQUEST['pagesize'] = 30;
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) ) $GLOBALS['_REQUEST']['page'] = 1;
$criteria = new criteriacompo();
if ( !empty( $_REQUEST['aid'] ) ) {
		$criteria -> add( new criteria( 'aid', intval( $_REQUEST['aid'] ) ) );
}
if ( !empty( $_REQUEST['reporttype'] ) ) {
		$criteria -> add( new criteria( 'reporttype', $_REQUEST['reporttype'] ) );
}
if ( isset( $_REQUEST['ishandle'] ) && $_REQUEST['ishandle'] != '' ) {
		$criteria -> add( new criteria( 'ishandle', $_REQUEST['ishandle'] ) );
}
$criteria -> setsort( "reporttime" );
$criteria -> setorder( "DESC" );
$criteria -> setlimit( $_REQUEST['pagesize'] );
$criteria -> setstart( ( $_REQUEST['page'] - 1 ) * $_REQUEST['pagesize'] );
$report_handler -> queryobjects( $criteria );
$rows = array();
$k = 0;
while ( $v = $report_handler -> getobject() ) {
		$rows[$k] = $v -> getvars( 'n' );
		$rows[$k]['reporttypename'] = $saxueReporttype[$rows[$k]['reporttype']];
		++$k;
} 
include SAXUE_ADMIN_PATH . "/header.php";
$saxueTpl -> assign_by_ref( "rows", $rows );
$saxueTpl -> assign_by_ref( "reporttype", $saxueReporttype );
include SAXUE_ROOT_PATH . "/lib/util/page.php";
$jumppage = new saxuepage( $report_handler -> getcount( $criteria ), $_REQUEST['pagesize'], $_REQUEST['page'] );
$jumppage -> setlink( "", true, true );
$saxueTpl -> assign( "url_jumppage", $jumppage -> whole_bar() );
$saxueTset['saxue_contents_template'] = SAXUE_WEB_PATH . "/article/templates/report.html";
include SAXUE_ADMIN_PATH . "/footer.php";