{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="body" class="container" data-page="admin">
    {{template "admin/nav" .}}
    <div id="admin-container" class="col-md-9">
        <div class="panel panel-default">
            <div class="panel-heading">
                Edit Authentication
            </div>

            <div class="panel-body">
                <br/>
                <form action="/admin/auths/{{.Source.Id}}" method="post" class="form-horizontal">
                    {{.CsrfTokenHtml}}
                    {{template "base/alert" .}}
                    <input type="hidden" value="{{.Source.Id}}" name="id"/>
                    {{$type := .Source.Type}}
                    <div class="form-group">
                        <label class="col-md-3 control-label">Auth Type: </label>
                        <input type="hidden" name="type" value="{{.Source.Type}}"/>
                        <label class="control-label">
                            {{range $key, $val := .LoginTypes}}
                                {{if eq $key $type}}{{$val}}{{end}}
                            {{end}}
                        </label>
                    </div>
                    <div class="form-group {{if .Err_AuthName}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Name: </label>
                        <div class="col-md-7">
                            <input name="name" class="form-control" placeholder="Type authentication's name" value="{{.Source.Name}}" required="required">
                        </div>
                    </div>

                    {{if eq $type 2}}
                    <div class="form-group {{if .Err_Domain}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Domain: </label>
                        <div class="col-md-7">
                            <input name="domain" class="form-control" placeholder="Type domain name" value="{{.Source.LDAP.Name}}" required="required">
                        </div>
                    </div>

                    <div class="form-group {{if .Err_Host}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Host: </label>
                        <div class="col-md-7">
                            <input name="host" class="form-control" placeholder="Type host address" value="{{.Source.LDAP.Host}}" required="required">
                        </div>
                    </div>

                    <div class="form-group {{if .Err_Port}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Port: </label>
                        <div class="col-md-7">
                            <input name="port" class="form-control" placeholder="Type port number" value="{{.Source.LDAP.Port}}" required="required">
                        </div>
                    </div>

                    <div class="form-group {{if .Err_UseSSL}}has-error has-feedback{{end}}">
                         <label class="col-md-3 control-label">Use SSL: </label>
                         <div class="col-md-7">
                              <input name="usessl" class="form-control" type="checkbox" {{if .Source.LDAP.UseSSL}}checked{{end}}>
                         </div>
                    </div>


                    <div class="form-group {{if .Err_BaseDN}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Base DN: </label>
                        <div class="col-md-7">
                            <input name="base_dn" class="form-control" placeholder="Type base DN" value="{{.Source.LDAP.BaseDN}}" required="required">
                        </div>
                    </div>

                    <div class="form-group {{if .Err_Attributes}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Search Attributes: </label>
                        <div class="col-md-7">
                            <input name="attributes" class="form-control" placeholder="Type search attributes" value="{{.Source.LDAP.Attributes}}">
                        </div>
                    </div>

                    <div class="form-group {{if .Err_Filter}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Search Filter: </label>
                        <div class="col-md-7">
                            <input name="filter" class="form-control" placeholder="Type search filter" value="{{.Source.LDAP.Filter}}">
                        </div>
                    </div>

                    <div class="form-group {{if .Err_MsAdSA}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Ms Ad SA: </label>
                        <div class="col-md-7">
                            <input name="ms_ad_sa" class="form-control" placeholder="Type Ms Ad SA" value="{{.Source.LDAP.MsAdSAFormat}}">
                        </div>
                    </div>
                    {{else if eq $type 3}}
                    <div class="form-group {{if .Err_TLS}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">SMTP Auth: </label>
                        <div class="col-md-7">
                            <select name="smtpauth" class="form-control">
                                {{$auth := .Source.SMTP.Auth}}
                                {{range .SMTPAuths}}
                                <option value="{{.}}"
                                {{if eq . $auth}} selected{{end}}>{{.}}</option>
                                {{end}}
                            </select>
                        </div>
                    </div>

                    <div class="form-group {{if .Err_SmtpHost}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Host: </label>
                        <div class="col-md-7">
                            <input name="smtphost" class="form-control" placeholder="Type host address" value="{{.Source.SMTP.Host}}">
                        </div>
                    </div>

                    <div class="form-group {{if .Err_SmtpPort}}has-error has-feedback{{end}}">
                        <label class="col-md-3 control-label">Port: </label>
                        <div class="col-md-7">
                            <input name="smtpport" class="form-control" placeholder="Type port number" value="{{.Source.SMTP.Port}}">
                        </div>
                    </div>
                    {{end}}

                    <div class="form-group">
                        {{if eq $type 3}}
                        <div class="col-md-offset-3 col-md-7">
                            <div class="checkbox">
                                <label>
                                <input name="tls" type="checkbox" class="form-control" {{if .Source.SMTP.TLS}}checked{{end}}>
                                    <strong>Enable TLS Encryption</strong>
                                </label>
                            </div>
                        </div>
                        {{end}}

                        <div class="col-md-offset-3 col-md-7">
                            <div class="checkbox">
                                <label>
                                    <input name="allowautoregister" type="checkbox" {{if .Source.AllowAutoRegister}}checked{{end}}>
                                    <strong>Enable Auto Registration</strong>
                                </label>
                            </div>
                        </div>

                        <div class="col-md-7 col-md-offset-3">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="is_actived" {{if .Source.IsActived}}checked{{end}}>
                                    <strong>This authentication has activated.</strong>
                                </label>
                            </div>
                        </div>
                    </div>

                    <hr/>

                    <div class="form-group">
                        <div class="col-md-offset-3 col-md-6">
                            <button type="submit" class="btn btn-lg btn-primary btn-block">Update authentication config</button>
                            <a type="button" href="/admin/auths/{{.Source.Id}}/delete" class="btn btn-lg btn-danger btn-block">Delete this authentication</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>
</div>
{{template "base/footer" .}}