#include("layout.html")
#@layout()
#define content()
<form class="form-horizontal form-setting"
      action="#(CPATH)/install/initdb" method="post" id="form">
    <div class="form-group">
        <div class="col-sm-12">
            请填写数据库的相关信息。
        </div>
    </div>
    <h4 class="page-header" style="margin-top: 20px"></h4>
    <div class="form-group">
        <label class="col-sm-2 control-label">数据库名</label>
        <div class="col-sm-9">
            <input type="input" class="form-control" placeholder="您要将JPress安装到哪个数据库？"
                   name="dbName" value="#(JPRESS_DB_NAME ??)">
            <p class="help-block"> 注意：目前暂时只支持 mysql 5.6 或 5.7 版本。 </p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">用户名</label>

        <div class="col-sm-9">
            <input type="input" class="form-control" placeholder="数据库用户名"
                   name="dbUser" value="#(JPRESS_DB_USER ??)">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">密码</label>

        <div class="col-sm-9">
            <input type="input" class="form-control" placeholder="... 及密码"
                   name="dbPwd" value="#(JPRESS_DB_PASSWORD ??)">
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="dbAutoCreate" value="true"> 当数据库不存在时，自动为我创建（需要以上用户拥有相关权限）。
                </label>
            </div>
        </div>
    </div>



    <h4 class="page-header">主机信息</h4>

    <div class="form-group">
        <label class="col-sm-2 control-label">主机</label>
        <div class="col-sm-9">
            <input type="input" class="form-control" placeholder="主机或IP地址"
                   name="dbHost"  value="#(JPRESS_DB_HOST ?? '127.0.0.1')">
            <p class="help-block">如果 127.0.0.1 不能用，您通常可以从网站服务商得到正确的信息。</p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">端口号</label>
        <div class="col-sm-9">
            <input type="text" class="form-control" placeholder="数据库端口号"
                   name="dbPort" value="#(JPRESS_DB_PORT ?? '3306')">
            <p class="help-block">MySQL 的默认端口号是 3306 。</p>
        </div>
    </div>

    <div class="row">
        <div class=" col-xs-3 " style="padding-top: 15px">
            <a href="#(CPATH)/install" class="btn btn-default btn-block btn-flat"> 上一步 </a>
        </div>

        <div class="col-xs-offset-6 col-xs-3 " style="padding-top: 15px">
            <button type="button" id="submit" class="btn btn-primary btn-block btn-flat"> 下一步</button>
        </div>
    </div>
</form>
#end

#define script()
<script src="#(CPATH)/static/components/jquery/jquery.min.js"></script>
<script src="#(CPATH)/static/components/jquery/jquery.form.min.js"></script>
<script src="#(CPATH)/static/components/bootstrap/js/bootstrap.min.js"></script>
<script>

    $("#submit").on("click", function () {
        $("#form").ajaxSubmit({
            type: "post",
            success: function (data) {
                if (data.state == "ok") {
                    location.href = "#(CPATH)/install/step3";
                } else if (data.errorCode) {
                    alert(data.message + ",错误码：" + data.errorCode)
                } else {
                    location.href = "#(CPATH)/install/error";
                }

            },
            error: function () {
                alert("系统错误，请联系管理员。");
            }
        });
    })
</script>
#end
