<?php
/*
 * @Team : 孜然云
 * @Author : 孜然
 * @Url : zrv7.com
 * @Date : 2021-12-24 23:07
 * @Project : 孜然授权系统
 * @Description : 基于ZR框架开发的授权系统
 * @Qq : 2937978586
 * @Wx : hhr2937978586 
 * @Email : 2937978586@qq.com
 * @Read me : 孜然授权系统，是一款多模板/多用途/多权限的授权系统
 * @Remind : 孜然授权系统受《劳动知识产权》和《计算机软件著作法》的法律保护，使用破解即违法法律
 * @Dbfk : 如果您已经使用了盗版，孜然可以通过上述两法告你，不过我是不会这么做的，如果是传播盗版那么就必定告上法院
 */
require_once 'head.php';
$id=isset($_GET['id'])?$_GET['id']:null;
?>
<?php 
if($id=='add'){
$title='添加名单';
require_once 'head.php';
?>
 <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" id="formBasForm" lay-filter="formBasForm">
            
            <blockquote class="layui-elem-quote">
		    温馨提示：白名单不被系统拦截，黑名单会被拦截并且限制功能
		    <br />
		    可以在运行日志内获取不喜欢的人的IP，或者异常IP                        
            </blockquote> 
                                                                                                                                                                                                                                                                                                                                              
                    <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">名单类型</label>
                    <div class="layui-input-block">
                    <select class="layui-input" name="type">
                    <option value="1">黑名单</option>
                    <option value="0">白名单</option>                    
                    </select>
                    </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label" style="padding-left: 0;padding-right: 0;">IP地址</label>
                    <div class="layui-input-block">
                    <input type="text" placeholder="请查清楚IP地址[勿添管理员IP，否则系统错误]" name="ip" class="layui-input">
                    </div>
                    </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">名单描述</label>
                    <div class="layui-input-block">
                    <textarea class="layui-textarea" name="content" placeholder="对此IP的描述"></textarea>
                    </div>
                </div>  
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                    <div class="layui-form-item layui-row layui-col-space10 ">
                    <div class="layui-col-md2">
                    <button type="button" class="layui-btn layui-btn-fluid" lay-submit lay-filter="noticeBtn">&emsp;添加名单&emsp;</button>
                    </div>
                    <div class="layui-col-md2">
                    <button type="reset" id="formreset" class="layui-btn layui-btn-primary layui-btn-fluid">&emsp;重置表单&emsp;</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
layui.use(['form', 'element','jquery', 'admin', 'tagsInput', 'notice'], function () {
    var form = layui.form;
    var $ = layui.jquery;
    var tagsInput = layui.tagsInput;
    var admin = layui.admin;
    var notice = layui.notice;
    $('#formreset').click(function () {
        document.getElementById("formBasForm").reset();
        notice.destroy();
        notice.msg('重置表单成功！', {animateInside: true, icon: 1});
    });
    form.on('submit(noticeBtn)', function (data) {
        var type = $("select[name='type']").val();        
        var ip = $("input[name='ip']").val();            
        var content = $("textarea[name='content']").val(); 
        admin.btnLoading('[lay-filter="noticeBtn"]',' 添加中');
        var ii = layer.load(2, {shade:[0.1,'#fff']});
        notice.destroy();
        $.ajax({
            type: "POST",
            url: "ajax/user_ajax.php?act=md_add",
            data : {type:type,ip:ip,content:content},
            dataType: "json",
            success: function(data) {
                layer.close(ii);
                admin.btnLoading('[lay-filter="noticeBtn"]', false);
                if (data.code == 0) {
                    notice.msg(data.msg, {animateInside: true, icon: 1});
                } else {
                    notice.msg(data.msg, {animateInside: true, icon: 2});
                }
            },
            error:function(data){
                notice.msg('代码错误！作者QQ2937978586', {animateInside: true, icon: 2});
                return false;
            }
        });
        return false;
    });
});
</script>
<?php
} else {
if (isset($_GET['kw'])) {
    $kw = daddslashes($_GET['kw']);
    $sql = " ip like '%" . $kw . "%' or content like '%" . $kw. "%'";
    $numrows = $DB->count("SELECT count(*) from zrauth_mingdan WHERE{$sql}");
    $con = "包含 <b>" . $kw . "</b> 的共有 <b>" . $numrows . "</b> 个名单";
    $link = "&kw=" . $kw;
} else {
    $sql = " 1";
    $numrows = $DB->count("SELECT count(*) from zrauth_mingdan");
    $con = "共有 <b>" . $numrows . "</b> 个名单";
}
$pagesize=10;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize) {
    $pages++;
}
if (isset($_GET['page'])) {
    $page=intval($_GET['page']);
} else {
    $page=1;
}
$offset=$pagesize*($page - 1);
?>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">名单列表</div>
        <div class="layui-card-body layui-form">
            <!-- 表格工具栏 -->
            <blockquote class="layui-elem-quote"><b><?php echo $conf['name'];?></b><?php echo $con?></blockquote>
            <form class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" class="layui-input" name="kw" placeholder="请输入IP地址" >
                    </div>
                    <div class="layui-inline">
                        <button type="button" class="layui-btn icon-btn" lay-submit lay-filter="search"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <a onclick="add()" class="layui-btn icon-btn"><i class="layui-icon layui-icon-addition"></i>添加名单</a>                        
                        <?php echo (isset($_GET['kw']))?'<a href="md_list.php" class="layui-btn layui-btn-primary">查看全部</a>':'';?>
                    </div>
                </div>
            </form>            
            <form name="form1" id="form1">
            <div style="white-space:nowrap;overflow-x: auto;">
                <table class="layui-table layuiadmin-page-table">
                    <thead>
                        <tr>
							<th>ID</th>
							<th>IP</th>
							<th>描述</th>
							<th>类型</th>
							<th>时间</th>															
							<th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    $rs=$DB->query("SELECT * FROM zrauth_mingdan WHERE 1 order by id desc limit $offset,$pagesize");
                    while($row = $DB->fetch($rs)) {
                    if ($row['type']==1) {//黑名单
                       $type = '<span lay-direction="1" lay-bg="#4facfe" class="layui-badge layui-badge-red">黑名单</span>';                        
                    } else if ($row['type']==0){ //不是黑名单就是白名单 0
                       $type = '<span lay-direction="1" lay-bg="#4facfe" class="layui-badge layui-badge-green">白名单</span>';                                            
                    }
                    ?>
                        <tr>
							<td><?php echo $row['id'];?></td>
							<td><?php echo $row['ip'];?></td>
							<td><?php echo $row['content'];?></td>
							<td><?php echo $type;?></td>
							<td><?php echo $row['time'];?></td>
                            <td>
                            <a class="layui-btn layui-btn-sm layui-btn-normal" onclick="editcx(<?php echo $row['id']?>)"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                            <a class="layui-btn layui-btn-sm layui-btn-danger" href="javascript:del(<?php echo $row['id']?>)" lay-filter="del<?php echo $row['id']?>"><i class="layui-icon layui-icon-delete"></i>删除</a>                            
                            </td>
                        </tr>
                    <?php } ?>
                    </tbody>
                </table> 
            </div>
            <br>
            </form>
            <?php
            echo '<div class="layui-laypage layui-laypage-default">';
            $prev = $page - 1;
            $next = $page + 1;
            if ($page > 1) {
                echo '<a href="md_list.php?page='.$prev.$link.'" class="layui-laypage-prev" data-page="'.$prev.$link.'">上一页</a>';
            } else {
                echo '<a class="layui-laypage-prev layui-disabled"  lay-tips="<img src=\'../assets/img/logo.png\' style=\'width:24px;height:24px;border-radius: 50%;\'/>&nbsp;&nbsp;没有更多页面了哦" lay-bg="#803ed9" lay-bgImg="linear-gradient(to right,#8510FF,#D025C2,#FF8B2D,#F64E2C)" data-page="'.$prev.$link.'">上一页</a>';
            }
            for ($i=1;$i<$page;$i++) {
                echo '<a href="md_list.php?page='.$i.$link.'" data-page="'.$i .'">'.$i .'</a>';
            }
            echo '<span class="layui-laypage-curr" lay-tips="<img src=\'../assets/img/logo.png\' style=\'width:24px;height:24px;border-radius: 50%;\'/>&nbsp;&nbsp;已是第'.$page.'页" lay-bg="#803ed9" lay-bgImg="linear-gradient(to right,#8510FF,#D025C2,#FF8B2D,#F64E2C)"><em class="layui-laypage-em"></em><em>'.$page.'</em></span>';
            if ($pages >= 10) {
                $s = 10;
            } else {
                $s = $pages;
            }
            for ($i=$page+1;$i<=$s;$i++) {
                echo '<a href="md_list.php?page='.$i.$link.'" data-page="'.$i .'">'.$i .'</a>';
            }
            echo '';
            if ($page < $pages) {
                echo '<a href="md_list.php?page='.$next.$link.'" class="layui-laypage-next" data-page="'.$next.$link.'">下一页</a>';
            } else {
                echo '<a class="layui-laypage-next layui-disabled" lay-tips="<img src=\'../assets/img/logo.png\' style=\'width:24px;height:24px;border-radius: 50%;\'/>&nbsp;&nbsp;没有更多页面了哦" lay-bg="#803ed9" lay-bgImg="linear-gradient(to right,#8510FF,#D025C2,#FF8B2D,#F64E2C)" data-page="'.$last.$link.'">下一页</a>';
            }
            echo '</div>';
            ?>
        </div>
    </div>
</div>
<script type="text/javascript">
layui.use(['form', 'element','layer','dropdown','jquery', 'admin', 'tagsInput', 'notice'], function () {
    var form = layui.form;
    var $ = layui.jquery;
    var tagsInput = layui.tagsInput;
    var admin = layui.admin;
    var notice = layui.notice;
    form.on('submit(search)', function (data) {
        var kw=$("input[name='kw']").val();
        window.location.href = './md_list.php?kw='+kw;
    });
    form.on('checkbox(allcheckbox)', function(that){
        var isbool = $(this).is(':checked') ? true : false ;
        console.log(isbool);
        $("input[name='checkbox[]']").each(function(){
            $(this).prop("checked",  isbool );
        })
        form.render();
    });
});
//删除单条
function del(id) {
    layui.use(['form', 'element','layer','dropdown','jquery', 'admin', 'tagsInput', 'notice'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var tagsInput = layui.tagsInput;
        var admin = layui.admin;
        var notice = layui.notice;
        var confirmobj = parent.layui.admin.confirm('你确实要删除这个名单吗？', {
            icon: 3, btn: ['确定','取消']
        }, function(){
            parent.layer.close(confirmobj);
            admin.btnLoading('[lay-filter="del'+id+'"]', ' 删除中');
            var ii = layer.load(2, {shade:[0.1,'#fff']});
            notice.destroy();
            $.ajax({
                type : 'GET',
                url : 'ajax/user_ajax.php?act=md_del&id='+id,
                dataType : 'json',
                success : function(data) {
                    layer.close(ii);
                    admin.btnLoading('[lay-filter="del'+id+'"]', false);
                    if (data.code == 0) {
                        notice.msg(data.msg, {animateInside: true, icon: 1});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);
                    } else {
                        notice.msg(data.msg, {animateInside: true, icon: 2});
                    }
                },
                error:function(data){
                    notice.msg('代码错误，作者QQ2937978586', {animateInside: true, icon: 2});
                    return false;
                }
            });
        }, function(){
            parent.layer.close(confirmobj);
        });
    });
}
//编辑弹窗
window.editcx = function(id){
layer.open({
  type: 2, 
  anim: 0,
  maxmin: true,
  title:'编辑名单 - ID:'+id,
  area:['95%','95%'],
  content: 'edi_zrauth.php?edi=mingdan&id='+id
}); 
}
//添加弹窗
window.add = function(id){
layer.open({
  type: 2, 
  anim: 0,
  maxmin: true,
  title:'添加名单',
  area:['95%','95%'],
  content: 'md_list.php?id=add'
}); 
}
</script>
<?php } ?>