<?php if (!defined('IN_CONTEXT')) die('access violation error!'); ?>

<script type="text/javascript" language="javascript">
<!--
function on_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("adminpayacctfrm_stat");
    if (o_result.result == "ERROR") {
        stat.innerHTML = o_result.errmsg;
        return false;
    } else if (o_result.result == "OK") {
	    stat.innerHTML = "Save Completed.";
//	    reloadPage();
    } else {
        return on_failure(response);
    }
}

function on_failure(response) {
    document.getElementById("adminpayacctfrm_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}

function choose_payments()
{
	var str;
	$('.form_table12').css('display','none');
	$('#adminpayacctfrm_stat').css('display','none');
	str = $('#choose_payment').val();
	str = 'payacctform_table_' + str;
	$('#'+str).css({display:""});
}
//-->
</script>
<div class="status_bar">
	<span id="adminpayacctfrm_stat" class="status" style="display:none;"></span>
</div>
<table width="100%" border="0" cellspacing="1" cellpadding="2" style="line-height:24px;">
	<tr>
		<td width="16%" bgcolor="#f6f6f4"><span class="label"><?php _e('Choose Payment Gateway'); ?></span></td>
		<td width="84%">
			<select onchange="choose_payments();" style="width: 130px;" id="choose_payment" name="choose_payment">
				<option value="noValue" selected="selected"><?php _e('Please Choose');?></option>
				<?php 
				foreach ($providers as $provider) {
					if($provider->id == '7')
					{
						echo "<option value='{$provider->name}'>$provider->disp_name</option>";
					}
					elseif($provider->id == '1')
					{
						echo "<option value='{$provider->name}'>支付宝双接口</option>";
					}
					elseif($provider->id == '4')
					{
						echo "<optgroup label='财付通接口'><option value='{$provider->name}'>$provider->disp_name</option>";
					}
					elseif($provider->id == '5')
					{
						echo "<option value='{$provider->name}'>$provider->disp_name</option></optgroup>";
					}
					else
					{
						echo "<option value='{$provider->name}'>$provider->disp_name</option>";
					}
				}
				?>
			</select>
		</td>
	</tr>
</table>
<?php
foreach ($providers as $provider) {
    $provider->loadRelatedObjects(REL_CHILDREN, array('PaymentAccount'));
    $curr_payacct = $provider->slaves['PaymentAccount'];
?>

    <?php
    $payacct_form = new Form('index.php', 'payacctform_'.$curr_payacct->id, 'check_acct_info_'.$curr_payacct->id);
    $payacct_form->p_open('mod_payaccount', 'admin_update', '_ajax');
    ?>
    <table id="payacctform_table_<?php echo $provider->name; ?>" class="form_table12" width="100%" border="0" cellspacing="1" cellpadding="2" style="line-height:24px;display:none;">
        <tfoot>
            <tr>
                <td bgcolor="#f6f6f4">&nbsp;</td>
                <td>
                <?php
				echo Html::input('submit', 'submit', __('Save'));
                echo Html::input('reset', 'reset', __('Reset'));
                echo Html::input('hidden', 'payacct[id]', $curr_payacct->id);
                if ($provider->name == '99bill') {
                    echo Html::input('hidden', 'payacct[seller_account]', '');
                    echo Html::input('hidden', 'payacct[seller_site_url]', '');
                }
                ?>
                </td>
            </tr>
        </tfoot>
        <tbody>
            <tr>
                <td width="16%" bgcolor="#f6f6f4"><span class="label"><?php _e('Payment Gateway'); ?></span></td>
                <td width="84%"><span class="entry"><?php _e($provider->disp_name); ?></span></td>
            </tr>
            <tr>
	           <td class="label">
	            	<?php 
	            		if($provider->name == 'alipay')
	            		{
	            			_e('Alipay Account');
	            		}
	            		elseif($provider->name == '99bill')
	            		{
	            			_e('99bill Account');
	            		}
	            		elseif($provider->name == 'paypal')
	            		{
	            			_e('Paypal Account');
	            		}
	            		elseif($provider->name == 'tencentmed')
	            		{
	            			_e('Tencent Medium Security Account');	
	            		}
	            		elseif($provider->name == 'tencentimd')
	            		{
	            			_e('Tencent Prompt Arrival Account');	
	            		}
						elseif($provider->name == 'alipaymed')
	            		{
	            			_e('Alipay Medium Security Account');	
	            		}
	            		elseif($provider->name == 'alipayimd')
	            		{
	            			_e('Alipay Prompt Arrival Account');	
	            		}
	            	?>
	            </td>   
                <td class="entry">
                <?php
                echo Html::input('text', 'payacct[seller_account]', $curr_payacct->seller_account, 
                    'size="48"', $payacct_form, 'RequiredTextbox', 
                    __('Please input account!'));
                    if ($provider->name == 'paypal')
                    {
                    	$str12 = __('You should apply a chinese paypal account.');
                    	$str13 = __('Paypal Address');
                    	echo "&nbsp;&nbsp;<span style='font-size:10px;'>$str12&nbsp;&nbsp;<a style='font-size:11px;' href='http://www.paypal.com' target='_blank'>$str13</a></span>";	
                    }
                ?>
                </td>
            </tr>
            <?php if ($provider->name != '99bill' && $provider->name != 'tencentmed' && $provider->name != 'tencentimd') { ?>
            <tr>
                <td class="label"><?php _e('Seller Site URL'); ?></td>
                <td class="entry">
                <?php
                echo Html::input('text', 'payacct[seller_site_url]', $curr_payacct->seller_site_url, 
                    'size="48"', $payacct_form, 'RequiredTextbox', 
                    __('Please input seller site URL!'));
                ?>
                <img id="answer" class="title" src="<?php echo P_TPL_WEB; ?>/images/answer1.gif" alt="help" title="向支付接口商（如支付宝）注册商家地址，一般填写当前域名。"/>
                </td>
            </tr>
            <?php } ?>
            <?php if($provider->name != 'paypal' && $provider->name != 'tencentmed' && $provider->name != 'tencentimd'){?>
            <tr>
                <td class="label"><?php _e('Partner ID'); ?></td>
                <td class="entry">
                <?php
                echo Html::input('text', 'payacct[partner_id]', $curr_payacct->partner_id, 
                    'size="48"', $payacct_form, 'RequiredTextbox', 
                    __('Please input partner ID!'));
                ?>
                </td>
            </tr>
            <?php }?>
            <?php if($provider->name != 'paypal'){?>
            <tr>
                <td class="label"><?php _e('Partner Key'); ?></td>
                <td class="entry">
                <?php
                echo Html::input('password', 'payacct[partner_key]', $curr_payacct->partner_key, 
                    'size="48"', $payacct_form, 'RequiredTextbox', 
                    __('Please input partner key!'));
                ?>
                </td>
            </tr>
            
            <tr>
                <td class="label"><?php _e('Confirm Key'); ?></td>
                <td class="entry">
                <?php
                echo Html::input('password', 'payacct[re_partner_key]', $curr_payacct->partner_key, 
                    'size="48"', $payacct_form, 'RequiredTextbox', 
                    __('Please retype your partner key for confirmation!'));
                ?>
                </td>
            </tr>
            <?php }?>
            <tr>
                <td class="label"></td>
                <td class="entry">
                <?php
                echo Html::input('checkbox', 'payacct[enabled]', '1', 
                    Toolkit::switchText($curr_payacct->enabled, 
                        array('0' => '', '1' => 'checked="checked"')));
                ?>
                &nbsp;<?php _e('Enable'); ?>
                </td>
            </tr>
        </tbody>
    </table>
    <?php
    $payacct_form->close();
    if($provider->name != 'paypal'){
	    $payacct_form->genCompareValidate('payacct[partner_key]', 'payacct[re_partner_key]', 
	        '=', __('Partner keys mismatch!'));
    }
    $running_msg = __('Saving account...');
    $custom_js = <<<JS
    $("#adminpayacctfrm_stat").css({"display":"block"});
    $("#adminpayacctfrm_stat").html("$running_msg");
    _ajax_submit(thisForm, on_success, on_failure);
    return false;
    
JS;
    $payacct_form->addCustValidationJs($custom_js);
    $payacct_form->writeValidateJs();
    ?>

<?php } ?>
