<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/11
  Time: 12:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="com.censoft.db.DBUtil" %>
<%@ page import="com.censoft.db.Logger" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.Vector" %>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    String action = pub.trimNull(request.getParameter("action"));
    String login_name = pub.trimNull(request.getParameter("login_name"));
    String login_id = pub.trimNull(request.getParameter("login_id"));
    String bz = pub.trimNull(request.getParameter("bz"));
    String status = pub.trimNull(request.getParameter("status"));
    String passwd = pub.trimNull(request.getParameter("passwd"));
    String id = pub.trimNull(request.getParameter("id"));
    Hashtable ht = new Hashtable();
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        if ("update".equals(action)) {
            passwd = DBUtil.stringToMD5(passwd);
            String update_time = pub.getCurrentServerTime();
            String update_user = (String) session.getAttribute("session_login_id");
            boolean is_up = cf.executeUpdate(conn, "update t_book_admin set update_time=?,update_user=?,passwd=?  where id=?", new Object[]{ update_time, update_user,passwd, id});
            Logger.log("用户管理", "修改", id, "修改密码", request);
            if (!is_up) {
                out.println("error" + cf.getMsg());
                return;
            } else {
                out.println("success");
            }
            return;
        }
        if (!"".equals(id)) {
            v_list = cf.doQuery(conn, "select * from t_book_admin where id=?", null, new Object[]{id});
            ht = (Hashtable) v_list.get(0);
            action = "update";
        } else {
            action = "add";
        }
    } catch (Exception e) {
        out.println("查询用户信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>
<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add">
        <input type="hidden" name="id" value="<%=id%>"/>
        <input type="hidden" name="action" value="update"/>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>姓名：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <%=pub.trimNull((String)ht.get("login_name"))%>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>新密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off"
                       value="<%=pub.trimNull((String)ht.get("passwd"))%>" placeholder="密码" id="passwd" name="passwd">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off"
                       value="<%=pub.trimNull((String)ht.get("passwd"))%>" placeholder="确认新密码" id="password"
                       name="password">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="button" onclick="javascript:saveForm();"
                       value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
<script>
    function saveForm() {
        $.ajax({
            type: "POST",
            url: "./change_password-t.jsp",
            data: $('#form-admin-add').serialize(),
            success: function (msg) {
                if (msg.indexOf("success") >= 0) {
                    layer.msg('操作成功!', {icon: 1, time: 1000},
                        function () {
                            parent.searchModel();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                } else {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // console.log("********************8")
                    });
                }
            }
        });
    }
</script>