{template "header.html"}
<div class="note note-danger">
    <p>{dr_lang('使用官方接口时需要到官方网站用户中心申请短信Key')}</p>
</div>
<form action="" class="form-horizontal" method="post" name="myform" id="myform">
    {dr_form_hidden()}
    <div class="portlet bordered light myfbody">
        <div class="portlet-title tabbable-line">
            <ul class="nav nav-tabs" style="float:left;">
                <li class="{if $page==0}active{/if}">
                    <a href="#tab_0" data-toggle="tab" onclick="$('#dr_page').val('0')"> <i class="fa fa-cog"></i> {dr_lang('短信参数')} </a>
                </li>
            </ul>
        </div>
        <div class="portlet-body">
            <div class="tab-content">

                <div class="tab-pane {if $page==0}active{/if}" id="tab_0">
                    <div class="form-body">

                        <div class="form-group">
                            <label class="col-md-2 control-label" style="padding-top: 10px;">{dr_lang('接口类型')}</label>
                            <div class="col-md-9">
                                <div class="mt-radio-inline">
                                    <label class="mt-radio mt-radio-outline"><input name="aa" type="radio" value="0" onclick="$('.dr_0').show();$('.dr_1').hide();" {if !$data.third}checked="checked"{/if} /> {dr_lang('官方接口')} <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input name="aa" type="radio" value="1" onclick="$('.dr_1').show();$('.dr_0').hide();" {if $data.third}checked="checked"{/if} /> {dr_lang('第三方接口')} <span></span></label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group dr_0">
                            <label class="col-md-2 control-label">官方SMS Uid</label>
                            <div class="col-md-9">
                                <label><input class="form-control" type="text" name="data[uid]" value="{$data.uid}" ></label>
                            </div>
                        </div>
                        <div class="form-group dr_0">
                            <label class="col-md-2 control-label">官方SMS Key</label>
                            <div class="col-md-9">
                                <input class="form-control" type="text" name="data[key]" value="{$data.key}" >
                            </div>
                        </div>
                        {if $data.uid && !$data.third}
                        <div class="form-group dr_0">
                            <label class="col-md-2 control-label">{dr_lang('剩余短信')}</label>
                            <div class="col-md-9">
                                <div class="form-control-static" id="dr_sms">....</div>
                            </div>
                        </div>
                        {/if}


                        <div class="form-group dr_1">
                            <label class="col-md-2 control-label">{dr_lang('自定义参数')}</label>
                            <div class="col-md-9">
                                <textarea class="form-control" style="height:120px" name="data[third]" />{$data.third}</textarea>
                            </div>
                        </div>
                        <div class="form-group dr_1">
                            <label class="col-md-2 control-label">{dr_lang('测试手机号')}</label>
                            <div class="col-md-9">
                                <label><input class="form-control" type="text" name="data[mobile]" value="{$data.mobile}" ></label>
                                <span class="help-block">{dr_lang('单击测试按钮会将验证码发送到此手机')}</span>
                            </div>
                        </div>
                        <div class="form-group dr_0">
                            <label class="col-md-2 control-label">{dr_lang('短信签名')}</label>
                            <div class="col-md-9">
                                <label><input class="form-control" type="text" name="data[note]" value="{$data.note}" ></label>
                                <span class="help-block">{dr_lang('保持在10个字符以内')}</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('验证码有效期')}</label>
                            <div class="col-md-9">
                                <div class="input-inline input-medium">
                                    <div class="input-group">
                                        <input type="text" name="SYS_CACHE_SMS" value="{php echo max(60, intval($cache['SYS_CACHE_SMS']));}" class="form-control">
                                        <span class="input-group-addon">
                                            <i class="fa fa-clock-o"></i>
                                        </span>
                                    </div>
                                </div>
                                <span class="help-inline"> {dr_lang('单位秒，最低60秒，发送验证码后的有效期时间')} </span>
                            </div>
                        </div>


                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="portlet-body form myfooter">
        <div class="form-actions text-center">
            <button type="button" onclick="dr_ajax_submit('{dr_now_url()}&page='+$('#dr_page').val(), 'myform', '2000')" class="btn green"> <i class="fa fa-save"></i> {dr_lang('保存')}</button>
            <button type="button" onclick="dr_test_mobile()" class="btn red dr_1"> <i class="fa fa-cloud"></i> {dr_lang('测试')}</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    $(function() {
        {if $data.uid && !$data.third}
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "{dr_url('api/sms_info')}&uid={$data.uid}&key={$data.key}",
            success: function(json) {
                eval(json.msg);
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError);
            }
        });
        {/if}
        {if $data.third}
        $('.dr_1').show();$('.dr_0').hide();
        {else}
        $('.dr_0').show();$('.dr_1').hide();
        {/if}
    });
    function dr_test_mobile() {
        var loading = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 10000
        });
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{dr_url('api/test_mobile')}",
            data: $("#myform").serialize(),
            success: function(json) {
                layer.close(loading);
                dr_tips(json.code, json.msg, -1);
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError);
            }
        });
    }
</script>
{template "footer.html"}