<?php
include "../core.php";
saxue_checklogin();
include SAXUE_ROOT_PATH . "/model/member_account.php";
$account_handler = &saxuememberaccounthandler :: getinstance( "saxuememberaccounthandler" );
$account = $account_handler -> get( $_SESSION['saxueUserId'] );
$row = array();
$_isnew = true;
if ( $account ) {
		$row = $account -> getvars( 'n' );
		$_isnew = false;
}
if ( isset( $_POST['dosubmit'] ) ) {
		$_POST['uid'] = $_SESSION['saxueUserId'];
		$_POST['bank'] = trim( $_POST['bank'] );
		$_POST['payee'] = trim( $_POST['payee'] );
		$_POST['account'] = trim( $_POST['account'] );
		$_POST['updatetime'] = SAXUE_NOW_TIME;
		if ( $_isnew ) {
				$newaccount = $account_handler -> create();
		} else {
				$newaccount = $account_handler -> create( false );
		} 
		if ( !$account_handler -> insert( $newaccount ) ) {
				exit( json_encode( array( 'flag' => 0, 'msg' => LANG_ERROR_DATABASE ) ) );
		} 
		exit( json_encode( array( 'flag' => 1 ) ) );
}
$bill = 0;
if ( !$_isnew ) {
		include SAXUE_ROOT_PATH . "/model/member_bill.php";
		$bill_handler = &saxuememberbillhandler :: getinstance( "saxuememberbillhandler" );
		$criteria = new criteriacompo( new criteria( "uid", $_SESSION['saxueUserId'] ) );
		$criteria -> add( new criteria( 'status', 0 ) );
		$bill = $bill_handler -> getcount( $criteria );
}
include SAXUE_WEB_PATH . "/member/header.php";
$saxueTpl -> assign( "bill", $bill );
$saxueTpl -> assign_by_ref( "row", $row );
$saxueTpl -> setcaching( 0 );
$saxueTset['saxue_contents_template'] = SAXUE_THEME_PATH . "/member/account.html";
include SAXUE_WEB_PATH . "/member/footer.php";
