<?php
include "../../core.php";
saxue_checklogin();
include SAXUE_ROOT_PATH . "/model/article.php";
$article_handler = saxuearticlehandler :: getinstance( "saxuearticlehandler" );
if ( !empty( $_REQUEST['checkaction'] ) ) {
		switch ( $_REQUEST['checkaction'] ) {
				case 1:
						if ( !empty( $_REQUEST['ids'] ) && is_array( $_REQUEST['ids'] ) && count( $_REQUEST['ids'] ) > 0 ) {
								$article_handler -> db -> query( "DELETE FROM " . saxue_dbprefix( "member_doing" ) . " WHERE doid IN(" . implode( ',', $_REQUEST['ids'] ) . ") AND uid=" . $_SESSION['saxueUserId'] );
						}
						break;
				case 2:
						$article_handler -> db -> query( "DELETE FROM " . saxue_dbprefix( "member_doing" ) . " WHERE uid=" . $_SESSION['saxueUserId'] . " AND doing=2" );
						break;
		}
		saxue_jumppage( 'fav.php?menuid=' . $_REQUEST['menuid'] . '&page=' . $_REQUEST['page'] );
}
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) ) $GLOBALS['_REQUEST']['page'] = 1; 
saxue_getconfigs( "configs", "article" );
saxue_getconfigs( "cate", 'article' );
$where = saxue_dbprefix( 'member_doing' ) . " a LEFT JOIN " . saxue_dbprefix( 'article' ) . " b ON a.aid=b.aid WHERE a.uid=" . $_SESSION['saxueUserId'] . " AND a.doing=2";
$_res = $article_handler -> db -> query( "SELECT COUNT(*) FROM " . $where );
if ( !$_res ) {
		$listrows = 0;
} else {
		list( $listrows ) = $article_handler -> db -> fetchrow( $_res );
} 
$sql = "SELECT a.dotime,a.doid,a.chapterid,b.* FROM " . $where . " ORDER BY a.dotime DESC LIMIT " . ( ( $_REQUEST['page'] - 1 ) * $saxueConfigs['article']['userpnum'] ) . ", " . $saxueConfigs['article']['userpnum'];
$res = $article_handler -> db -> query( $sql );
$rows = $tables = array();
while ( $v = $article_handler -> getobject( $res ) ) {
		$k = $v -> getvar( 'aid' );
		$rows[$k] = $v -> getvars( 'n' );
		$rows[$k]['cname'] = $saxueCate['article'][$rows[$k]['cid']]['cname'];
		$rows[$k]['curl'] = $saxueCate['article'][$rows[$k]['cid']]['curl'];
		if ( $rows[$k]['uid'] > 0 ) $rows[$k]['uhome'] = saxue_geturl( "user_home", $rows[$k]['uid'] );
		$tables[$rows[$k]['tbnum']][] = $k;
} 
if ( count( $tables ) > 0 ) {
		foreach ( $tables as $tbnum => $ids  ) {
				$_res = $article_handler -> db -> query( "SELECT * FROM " . saxue_dbprefix( 'article_data_' . $tbnum ) . " WHERE aid IN (" . implode( ',', $ids ) . ")" );
				while ( $v = $article_handler -> getobject( $_res ) ) {
						$k = $v -> getvar( 'aid' );
						$rows[$k] = $rows[$k] + ( $v -> getvars( 'n' ) );
						if ( $rows[$k]['chapterid'] ) {
								if ( !$saxueConfigs['article']['url_detail'] ) $rows[$k]['chapterurl'] = $rows[$k]['url'] . '&chapterid=' . $rows[$k]['chapterid'];
								else $rows[$k]['chapterurl'] = $rows[$k]['url'] . saxue_geturl( 'article_chapter', $rows[$k]['chapterid'] );
						}
				} 
		} 
}
include SAXUE_WEB_PATH . "/member/header.php";
$saxueTpl -> assign_by_ref( "rows", $rows );
include SAXUE_ROOT_PATH . "/lib/util/page.php";
$jumppage = new saxuepage( $listrows, $saxueConfigs['article']['userfav'], $_REQUEST['page'] );
$jumppage -> setlink( "", true, true );
$saxueTpl -> assign( "url_jumppage", $jumppage -> whole_bar() );
$saxueTpl -> assign( "totalpage", $jumppage -> total_page );
$saxueTpl -> setcaching( 0 );
$saxueTset['saxue_contents_template'] = SAXUE_THEME_PATH . '/article/member/fav.html';
include SAXUE_WEB_PATH . "/member/footer.php";
