<?php
$id = intval( $_GET['id'] );
if ( empty( $id ) ) {
		exit;
}
include "../core.php";
$page = trim( $_GET['page'] );
switch ( $page ) {
		case 'topic':
				$showviews = saxue_htmlstr( trim( $_GET['showviews'] ) );
				if ( !empty( $showviews ) ) {
						include SAXUE_ROOT_PATH . "/model/topic.php";
						$topic_handler = &saxuetopichandler :: getinstance( "saxuetopichandler" );
						$topic = $topic_handler -> get( $id );
						if ( !$topic ) {
								exit;
						} 
						echo 'document.getElementById("' . $showviews . '").innerHTML="' . $topic -> getvar( 'views' ) . '";';
				}
				if ( !empty( $_GET['doviews'] ) ) {
						include SAXUE_ROOT_PATH . "/common/funstat.php";
						saxue_visit_stat( $id, 'topic', 'views', 'topicid' );
				}
				break;
		case 'article':
		default:
				$fields = array();
				if ( !empty( $_GET['showviews'] ) ) {
						$fields['views'] = saxue_htmlstr( trim( $_GET['showviews'] ) );
				}
				if ( !empty( $_GET['showdowns'] ) ) {
						$fields['downs'] = saxue_htmlstr( trim( $_GET['showdowns'] ) );
				}
				if ( !empty( $_GET['showfavs'] ) ) {
						$fields['favs'] = saxue_htmlstr( trim( $_GET['showfavs'] ) );
				}
				if ( !empty( $_GET['showtops'] ) ) {
						$fields['tops'] = saxue_htmlstr( trim( $_GET['showtops'] ) );
				}
				if ( count( $fields ) > 0 ) {
						include SAXUE_ROOT_PATH . "/model/article.php";
						$article_handler = &saxuearticlehandler :: getinstance( "saxuearticlehandler" );
						$article = $article_handler -> get( $id );
						if ( !$article ) {
								exit;
						} 
						foreach ( $fields as $key => $val ) {
								echo 'document.getElementById("' . $val . '").innerHTML="' . $article -> getvar( $key ) . '";';
						}
				}
				if ( !empty( $_GET['doviews'] ) ) {
						include SAXUE_ROOT_PATH . "/common/funstat.php";
						saxue_visit_stat( $id, 'article', 'views', 'aid' );
				}
				break;
}