<?php
/***************************************************************************
 *                               bank.php
 *                            -------------------
 *   Version              : 1.1.0
 *   began                : Tuesday, December 17th, 2002
 *   released             : Wednesday, December 18th, 2002
 *   source form          : ice_rain_@hotmail.com
 *   modify               : goldwing_chien@acer.com.tw
 *   modify date          : 2003/05/23
 ***************************************************************************/

define('IN_PHPBB', 1);

if( !empty($setmodules) )
{
	$file = basename(__FILE__);
	$module['RPG']['Bank_Configuration'] = $file;
	return;
}

//
// Let's set the root dir for phpBB
//
$phpbb_root_path = '../';
require($phpbb_root_path . 'extension.inc');
require('pagestart.' . $phpEx);
//
//check for userlevel
//
if( !$userdata['session_logged_in'] )
{
	header('Location: ' . append_sid("login.$phpEx?redirect=admin/admin_bank.$phpEx", true));
}

if( $userdata['user_level'] != ADMIN )
{
	message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
}
//end check

//bank pages

$template->set_filenames(array(
	'body' => 'admin/rpg_bank_body.tpl')
);

if (!empty($HTTP_POST_VARS['act']) || !empty($HTTP_GET_VARS['act']))
{
	$action = (!empty($HTTP_POST_VARS['act'])) ? $HTTP_POST_VARS['act'] : $HTTP_GET_VARS['act'];
}
else
{
	$action = '';
}

switch ($action)
{
	case '':
		bank_info();
	break;
	case 'updatebank':
		updatebank();
	break;
	default:
		message_die(GENERAL_MESSAGE, '不正常操作!');
	break;
}
//########## bank_info begin #############
function bank_info()
{
	global $db,$template,$phpEx;
	$sql = array();
	$bankinfo = array();
	$sql[] = "select config_value from " . CONFIG_TABLE . " where config_name='bank_fees'";
	$sql[] = "select config_value from " . CONFIG_TABLE . " where config_name='bank_loanfees'";
	$sql[] = "select config_value from " . CONFIG_TABLE . " where config_name='bank_procedure_deposit'";
	$sql[] = "select config_value from " . CONFIG_TABLE . " where config_name='bank_procedure_loan'";
	$sql[] = "select config_value from " . CONFIG_TABLE . " where config_name='bank_procedure_remit'";
	$sql[] = "select config_value from " . CONFIG_TABLE . " where config_name='bank_loanmax'";
	$sql_count = count($sql);
	for($i = 0; $i < $sql_count; $i++)
	{
		if ( !($result = $db->sql_query($sql[$i])) ) { message_die(GENERAL_MESSAGE, 'Fatal Error Getting Bank Information!'); }
		$row = mysql_fetch_array($result);
		$bankinfo[] = $row['config_value'];
	}
	$banksettings = '<input type="hidden" name="act" value="updatebank">
	<tr><td class="row2"><span class="gensmall">存款利率 </span></td><td class="row2"><input type="text" name="fees" size="5" value="'.$bankinfo[0].'" maxlength="6"></td></tr>
	<tr><td class="row2"><span class="gensmall">貸款利率 </span></td><td class="row2"><input type="text" name="fees_loan" size="5" value="'.$bankinfo[1].'" maxlength="6"></td></tr>
	<tr><td class="row2"><span class="gensmall">存款手續費 </span></td><td class="row2"><input type="text" name="procedure_deposit" size="5" value="'.$bankinfo[2].'" maxlength="6"></td></tr>
	<tr><td class="row2"><span class="gensmall">貸款手續費 </span></td><td class="row2"><input type="text" name="procedure_loan" size="5" value="'.$bankinfo[3].'" maxlength="6"></td></tr>
	<tr><td class="row2"><span class="gensmall">匯款手續費 </span></td><td class="row2"><input type="text" name="procedure_remit" size="5" value="'.$bankinfo[4].'" maxlength="6"></td></tr>
	<tr><td class="row2"><span class="gensmall">貸款最高上限 </span></td><td class="row2"><input type="text" name="loanmax" size="8" value="'.$bankinfo[5].'"></td></tr>
	<tr><td class="row2" colspan="2" align="center"><input type="submit" value="更新" name="Update"></td></tr></form>';
	
	$template->assign_vars(array(
		'BANKCONFIGINFO' => "$banksettings",
		'BANKTABLETITLE' => "設定銀行參數",
		'S_CONFIG_ACTION' => append_sid('admin_bank.' . $phpEx),
		'BANKTITLE' => "銀行設定",
		'BANKEXPLAIN' => "這是讓您設定銀行的參數")
	);
	
}
//########## updatebank begin #############
function updatebank()
{
	global $db,$template,$phpEx,$HTTP_POST_VARS;
	$usql = array();
	if (isset($HTTP_POST_VARS['fees'])) { $usql[] = "update ". CONFIG_TABLE . " set config_value='".$HTTP_POST_VARS['fees']."' where config_name='bank_fees'"; }
	if (isset($HTTP_POST_VARS['fees_loan'])) { $usql[] = "update ". CONFIG_TABLE . " set config_value='".$HTTP_POST_VARS['fees_loan']."' where config_name='bank_loanfees'"; }
	if (isset($HTTP_POST_VARS['procedure_deposit'])) { $usql[] = "update ". CONFIG_TABLE . " set config_value='".$HTTP_POST_VARS['procedure_deposit']."' where config_name='bank_procedure_deposit'"; }
	if (isset($HTTP_POST_VARS['procedure_loan'])) { $usql[] = "update ". CONFIG_TABLE . " set config_value='".$HTTP_POST_VARS['procedure_loan']."' where config_name='bank_procedure_loan'"; }
	if (isset($HTTP_POST_VARS['procedure_remit'])) { $usql[] = "update ". CONFIG_TABLE . " set config_value='".$HTTP_POST_VARS['procedure_remit']."' where config_name='bank_procedure_remit'"; }
	if (isset($HTTP_POST_VARS['loanmax'])) { $usql[] = "update ". CONFIG_TABLE . " set config_value='".$HTTP_POST_VARS['loanmax']."' where config_name='bank_loanmax'"; }
	$sql_count = count($usql);
	for($i = 0; $i < $sql_count; $i++) { if ( !($db->sql_query($usql[$i])) ) { message_die(GENERAL_MESSAGE, 'Fatal Error Updating Bank Information!'); } }
	message_die(GENERAL_MESSAGE, '銀行設定已經完成更新!<br /><br />點選 <a href="'.append_sid("admin_bank.".$phpEx).'">這裡</a> 返回銀行設定<br /><br />點選 <a href="'.append_sid("index.".$phpEx."?pane=right").'">這裡</a> 回到控制台首頁<br /><br />');
}


//
// Generate the page
//
$template->pparse('body');

include('page_footer_admin.' . $phpEx);


?>
