<?php
include "../core.php";
$aid = intval( $_REQUEST['aid'] );
if ( empty( $aid ) ) {
		include SAXUE_WEB_PATH . "/404.php";
}
if ( !empty( $_REQUEST['chapterid'] ) ) {
		$page = intval( $_REQUEST['chapterid'] );
		$temp = 'chapter';
} else {
		$page = intval( $_REQUEST['page'] );
		$temp = 'detail';
}
include SAXUE_WEB_PATH . "/header.php";
if ( $temp == 'chapter' ) {
		$saxueTset['saxue_page_template']['cache_file'] = SAXUE_THEME_PATH . '/article/chapter.tpl';
		$saxueTset['saxue_page_cacheid'] = $page;
} else {
		$saxueTset['saxue_page_template']['cache_file'] = SAXUE_THEME_PATH . '/article/detail.' . $page . '.tpl';
		$saxueTset['saxue_page_cacheid'] = $aid;
}
if ( SAXUE_USE_CACHE ) {
		$saxueTpl -> setcaching( 1 );
} else {
		$saxueTpl -> setcaching( 0 );
} 
if ( !SAXUE_USE_CACHE || !$saxueTpl -> is_cached( $saxueTset['saxue_page_template']['cache_file'], $saxueTset['saxue_page_cacheid'] ) ) {
		include SAXUE_ROOT_PATH . "/common/packarticle.php";
		$packarticle = new saxuepackarticle( $aid );
		if ( !$packarticle -> loadarticle() ) {
				include SAXUE_WEB_PATH . "/404.php";
		}
		$packarticle -> showarticle( $page );
		$saxueTset['saxue_page_template']['tpl_file'] = $packarticle -> gettemplate( $temp );
}
include SAXUE_ROOT_PATH . "/common/funstat.php";
saxue_visit_stat( $aid, 'article', 'views', 'aid' );
include SAXUE_WEB_PATH . "/footer.php";