<?php 
if ( !defined( "SAXUE_CORE_INCLUDE" ) ) {
		include "../../core.php";
} 
saxue_checkpower( 'oauthlogin' );
saxue_getconfigs( 'oauth', 'member' );
if ( !isset( $_REQUEST['action'] ) ) $_REQUEST['action'] = 'oauth';
switch ( $_REQUEST['action'] ) {
		case 'setting':
				if ( isset( $_POST['dosubmit'] ) ) {
						saxue_setconfigs( "oauth", $_POST['oauth_cfg'], "member" );
						saxue_jumppage( 'oauth.php?action=setting', LANG_DO_SUCCESS );
				} 
				include SAXUE_ADMIN_PATH . "/header.php";
				$saxueTpl -> assign( "oauth_cfg", $saxueOauth );
				$saxueTpl -> setcaching( 0 );
				$saxueTset['saxue_contents_template'] = SAXUE_WEB_PATH . "/member/templates/oauth_setting.html";
				include SAXUE_ADMIN_PATH . "/footer.php";
				break;
		default:
				// 导入oauth接口类
				include SAXUE_ROOT_PATH . "/model/member_oauth.php";
				$oauth_handler = &saxuememberoauthhandler :: getinstance( "saxuememberoauthhandler" );
				// 解除绑定
				if ( isset( $_REQUEST['oid'] ) && is_numeric( $_REQUEST['oid'] ) ) {
						$oauth_handler -> unbind( $_REQUEST['oid'] );
						if ( empty( $_REQUEST['jumpurl'] ) ) {
								saxue_jumppage( 'oauth.php', LANG_DO_SUCCESS );
						} else {
								saxue_jumppage( $_REQUEST['jumpurl'], LANG_DO_SUCCESS );
						}
				} 
				if ( empty( $_REQUEST['pagesize'] ) || !is_numeric( $_REQUEST['pagesize'] ) || !in_array( $_REQUEST['pagesize'], array( '10', '30', '50', '100' ) ) ) $_REQUEST['pagesize'] = 30;
				if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) ) $GLOBALS['_REQUEST']['page'] = 1;
				$criteria = new criteriacompo();
				if ( !empty( $_REQUEST['uid'] ) ) {
						$criteria -> add( new criteria( "uid", $_REQUEST['uid'] ) );
				} 
				if ( !empty( $_REQUEST['site'] ) ) {
						$criteria -> add( new criteria( "site", $_REQUEST['site'] ) );
				} 
				if ( !empty( $_REQUEST['sort'] ) ) {
						$criteria -> setsort( $_REQUEST['sort'] );
				} else {
						$criteria -> setsort( 'addtime' );
				} 
				if ( !empty( $_REQUEST['order'] ) ) {
						$criteria -> setorder( $_REQUEST['order'] );
				} else {
						$criteria -> setorder( 'DESC' );
				} 
				$criteria -> setlimit( $_REQUEST['pagesize'] );
				$criteria -> setstart( ( $_REQUEST['page'] - 1 ) * $_REQUEST['pagesize'] );
				$oauth_handler -> queryobjects( $criteria );
				$rows = array();
				$k = 0;
				while ( $v = $oauth_handler -> getobject() ) {
						$rows[$k] = $v -> getvars( "n" );
						++$k;
				} 
				include SAXUE_ADMIN_PATH . "/header.php";
				$saxueTpl -> assign_by_ref( "rows", $rows );
				$saxueTpl -> assign_by_ref( "oauth_cfg", $saxueOauth );
				include_once( SAXUE_ROOT_PATH . "/lib/util/page.php" );
				$jumppage = new saxuepage( $oauth_handler -> getcount( $criteria ), $_REQUEST['pagesize'], $_REQUEST['page'] );
				$jumppage -> setlink( "", true, true );
				$saxueTpl -> assign( "url_jumppage", $jumppage -> whole_bar() );
				$saxueTpl -> setcaching( 0 );
				$saxueTset['saxue_contents_template'] = SAXUE_WEB_PATH . "/member/templates/oauth.html";
				include SAXUE_ADMIN_PATH . "/footer.php";
				break;
}
