<%--
  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="java.sql.Connection" %>
<%@ page import="java.util.*" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="com.censoft.db.DBUtil" %>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    String action = pub.trimNull(request.getParameter("action"));
    String b_time = pub.trimNull(request.getParameter("b_time"));
    String e_time = pub.trimNull(request.getParameter("e_time"));
    String status = pub.trimNull(request.getParameter("status"));
    String id = pub.trimNull(request.getParameter("id"));
    Hashtable ht = new Hashtable();
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        if ("update".equals(action)) {
            String update_time = pub.getCurrentServerTime();
            String update_user = (String) session.getAttribute("session_login_id");
            boolean is_up = cf.executeUpdate(conn, "update t_book_conf_data set b_time=?,e_time=?,status=?,update_time=?,update_user=?", new Object[]{b_time,e_time,status,update_time,update_user});
            System.out.println(is_up);
            if (!is_up) {
                out.println("error" + cf.getMsg());
                return;
            } else {
                out.println("success");
            }
            return;
        }else if("tb".equals(action)){
			boolean is_up = cf.executeUpdate(conn, "delete from t_user_phone_temp");
            if (!is_up) {
                out.println("error" + cf.getMsg());
                return;
            }
			is_up = cf.executeUpdate(conn, "insert into t_user_phone_temp select * from t_user_phone");
			if (!is_up) {
                out.println("error" + cf.getMsg());
                return;
            }
			is_up = cf.executeUpdate(conn, "delete from t_dept_phone_temp");
            if (!is_up) {
                out.println("error" + cf.getMsg());
                return;
            }
			is_up = cf.executeUpdate(conn, "insert into t_dept_phone_temp select * from t_dept_phone");
			if (!is_up) {
                out.println("error" + cf.getMsg());
                return;
            }
		}
        v_list = cf.doQuery(conn, "select * from t_book_conf_data ", null, new Object[]{});
        if (v_list != null && v_list.size() > 0) {
            ht = (Hashtable) v_list.get(0);
        }
        action = "update";
    } 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="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">
                <input type="text"  class="input-text Wdate"  autocomplete="off" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="<%=pub.trimNull((String)ht.get("b_time"))%>"
                       name="b_time" style="width:120px;">
            </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-5">
                <input type="text"  class="input-text Wdate"  autocomplete="off"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="<%=pub.trimNull((String)ht.get("e_time"))%>"
                       name="e_time" style="width:120px;">
            </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-4 col-sm-3 skin-minimal">
                <div class="radio-box">
                    <input name="status" type="radio" id="sex-1" value="00"
                           <%if("00".equals(pub.trimNull((String)ht.get("status")))||"".equals(status)){%>checked<%}%>>
                    <label for="sex-1">启用</label>
                </div>
                <div class="radio-box">
                    <input name="status" type="radio" id="sex-2" name="sex" value="01"
                           <%if("01".equals(pub.trimNull((String)ht.get("status")))){%>checked<%}%>>
                    <label for="sex-2">禁用</label>
                </div>
            </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;">

				<input class="btn btn-success  radius" type="button" onclick="javascript:tbForm();"
                       value="&nbsp;&nbsp;数据下发&nbsp;&nbsp;">
				            </div>
			 <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3" style="color:red;margin-top:50px;line-height:30px;">
				
       
					  保存策略：控制各单位更新进入入口，能够在策略范围内维护各自信息内容；<br >
					  数据下发：将通讯录信息同步下发给各单位，以保证初始数据一致。
            </div>
        </div>
    </form>
</article>
<script>
    function tbForm() {
		layer.confirm('确认要将数据下发给各单位吗？', function (index) {
			$.ajax({
				type: "POST",
				url: "./config_data-t.jsp?action=tb",
				success: function (msg) {
					if (msg.indexOf("success") >= 0) {
						layer.msg('操作成功!', {icon: 1, time: 1000},
							function () {
							});
					} else {
						layer.msg('操作失败', {
							icon: 5,
							time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function () {
							// console.log("********************8")
						});
					}
				}
			});
		});
    }
	function saveForm() {
        $.ajax({
            type: "POST",
            url: "./config_data-t.jsp",
            data: $('#form-admin-add').serialize(),
            success: function (msg) {
                if (msg.indexOf("success") >= 0) {
                    layer.msg('操作成功!', {icon: 1, time: 1000},
                        function () {
                        });
                } else {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // console.log("********************8")
                    });
                }
            }
        });
    }
</script>