<?php
error_reporting(0); 
include("../../config/ht.php");
session_start();
if(!isset($_SESSION['adminname'])){echo "<script>alert('请重新登录!')</script><script>top.location.href='/$htlj/'</script>";exit;}
$adminname=$_SESSION['adminname'];
$type="where name='$adminname'";
$adminpd=queryall(admin,$type);
if(!$adminpd){echo "<script>alert('请重新登录!')</script><script>top.location.href='/$htlj/'</script>";exit;}
if($adminpd[qx]=='超级管理员'){}else{echo "<script>alert('无权限')</script><script>top.location.href='/$htlj/'</script>";exit;}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="gb2312">
<title>管理员列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/layui/css/houtai.css" media="all" />
<link rel="stylesheet" href="/2019newui/houtai/css/font-awesome.min.css" media="all" />
<link rel="stylesheet" href="/2019newui/houtai/css/admin.css" media="all">
<link rel="stylesheet" href="/2019newui/houtai/css/peizhi.css" media="all">
<script src="/2019newui/js/jquery.min.js"></script>
<script src="/layui/layui.js"></script>
<script src="/2019newui/js/bootstrap.min.js"></script>
</head>
<body>
<body style="padding:10px;">
<div class="tplay-body-div">
<?php
$sql = mysql_query("SELECT * FROM admin");
$bs = mysql_num_rows($sql);
?>
<fieldset class="layui-elem-field layui-field-title" style="margin-top:20px;"><legend>管理员列表(<?php if($bs==null){?>0<?php }else{?><?php echo $bs?><?php }?>个)</legend></fieldset>
<div class="layui-tab layui-tab-brief">
<div class="layui-tab-content">
<div class="layui-form-item">
<div class="layui-inline">
<a class="layui-btn layui-btn-normal addNews_btn pub_btn" data-toggle="modal" data-target="#myPublic2">添加管理员</a>
</div>
</div>
</div> 
<table class="layui-table">
<thead>
<tr>
<th style="text-align:center;" >管理员名称</th>
<th style="text-align:center;" >管理员密码</th>
<th style="text-align:center;">管理员权限</th>
<th style="text-align:center;">登陆次数</th>
<th style="text-align:center;">上次登陆IP</th>
<th style="text-align:center;">上次登陆时间</th>
<th style="text-align:center;">管理员操作</th>
</tr>
</thead>
<tbody>
<?php 
$page_size=18; 
$sql = "WHERE 1=1";
$resul= mysql_query("select id from admin   ".$sql."  ");
$count = mysql_num_rows($resul); 
if($count == 0){echo '<tr><td colspan=18 style="text-align:center;">没有记录</td></tr>';}
$page_count = ceil($count/$page_size); 
$init=1; 
$page_len=7; 
$max_p=$page_count; 
$pages=$page_count; 
if(empty($_GET['page'])||$_GET['page']<0){ 
$page=1; 
}else { 
$page=$_GET['page']; 
} 
$offset=$page_size*($page-1); 
$query = mysql_query("select * from  admin  ".$sql." order by id desc   limit $offset, $page_size");
while ($a=mysql_fetch_array($query)) { 
$sqlx = mysql_query("SELECT * FROM adminip   where name='$a[name]' ");
$cs = mysql_num_rows($sqlx);
$type = " where name='$a[name]' order by id DESC limit 1,1";
$dl=queryall(adminip,$type);
?> 	
<tr>
<td align="center"><?php echo $a[name]?></td>
<td align="center"><?php echo $a[ypass]?></td>
<td align="center"><?php echo $a[qx]?></td>
<td align="center"><?php if($cs == null){ ?> 0 <?php }else{  ?> <?php echo $cs?> <?php } ?> 次</td>
<td align="center"><?php if($dl[ip] == null){ ?> 第一次登陆<?php }else{?><?php echo $dl[ip]?><?php } ?> </td>
<td align="center"><?php if($dl[shijian] == null){ ?> 第一次登陆<?php }else{?><?php echo $dl[shijian]?><?php } ?></td>
<td align="center">
<a class="layui-btn layui-btn-xs a_menu layui-btn-primary publish_btn"  data-id="<?php echo $a[id]?>" data-toggle="modal" data-target="#myPublic"  data-pass="<?php echo $a[ypass]?>"   data-qx="<?php echo $a[qx]?>"   style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
<a class="layui-btn layui-btn-xs delete layui-btn-primary"  style="margin-right: 0;font-size:12px;"  onClick="sc('<?php echo $a[id]?>')"><i class="layui-icon"></i></a>
</td>
</tr>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
$keyt.="<a href=\""."/htadminpage/1/\">首页</a>"; //首页 
$keyt.="<a href=\""."/htadminpage/".($page-1)."/\">上一页 </a>"; //上一页 
}else { 
$keyt.="<p>首页</p>"; //首页 
$keyt.="<p>上一页 </p>"; //上一页  
} 
if($pages>$page_len){ 
//如果当前页小于等于左偏移 
if($page<=$pageoffset){ 
$init=1; 
$max_p = $page_len; 
}else{//如果当前页大于左偏移 
//如果当前页码右偏移超出最大分页数 
if($page+$pageoffset>=$pages+1){ 
$init = $pages-$page_len+1; 
}else{ 
//左右偏移都存在时的计算 
$init = $page-$pageoffset; 
$max_p = $page+$pageoffset; 
} 
} 
} 
for($i=$init;$i<=$max_p;$i++){ 
if($i==$page){ 
$keyt.='<a class="cur">'.$i.'</a>'; 
} else { 
$keyt.="<a href=\""."/htadminpage/".$i."/\">".$i."</a>"; 
} 
} 
if($page!=$pages){ 
$keyt.="<a href=\""."/htadminpage/".($page+1)."/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/htadminpage/{$pages}/\">尾页</a> "; //最后一页 
}else { 
$keyt.="<p>下一页 </p>";//下一页 
$keyt.="<p>尾页</p>"; //最后一页 
} 
$keyt.="<p class='pageRemark' >当前第 <b>$page</b> 页/共 <b>$pages</b> 页  共 <b>$count</b> 条数据 </p>"; //第几页,共几页 
?> 
</tbody>
</table>
<!--分页-->
<div style="padding:0 20px;">
<div class="pagination">
<?php if($count =="0"){?><?php }else{?><?php echo $keyt?><?php }?>
</div>
</div>
</div>
<script type="text/javascript">
function sc(id) {
layer.confirm("确定要删除吗？", { title: "确认" }, function (index) {
layer.close(index);
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/htpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id: id, lx: 'gllistsc'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading'); 
layer.msg('删除成功');
location.reload();
} 
},
error:function(){
}
});
});
}
$(function () {
$("#publish_btn").click(function () {
var id = $("#recipient-id").val();
var pass = $("#recipient-pass").val();
var qx = $("#recipient-qx").val();
if (pass == '') {
layer.msg('密码不能为空');
return false;
}
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/htpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id:id,pass:pass,qx:qx, lx: 'gllistxg'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading'); 
layer.msg('更新成功');
location.reload();
}else{
layer.closeAll('loading'); 
layer.msg(data.msg);
location.reload();
} 
},
error:function(){
}
});
});
})
$('.publish_btn').on('click', function () {
$('#recipient-id').val($(this).data('id'));
$('#recipient-pass').val($(this).data('pass'));
$('#recipient-qx').val($(this).data('qx'));
})
</script>
<script type="text/javascript">
$('.pub_btn').on('click', function () {
})
$(function () {
$("#pub_btn").click(function () {
var pass = $("#pass").val();
var name = $("#name").val();
var qx = $("#qx").val();
if (pass == '') {
layer.msg('密码不能为空');
return false;
}
if (name == '') {
layer.msg('名称不能为空');
return false;
}
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/htpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {pass:pass,name:name,qx:qx, lx: 'gllistadd'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading'); 
layer.msg('添加成功');
location.reload();
}else{
layer.closeAll('loading'); 
layer.msg(data.msg);
location.reload();
} 
},
error:function(){
}
});
});
})
</script>
<div class="modal fade layui-form" id="myPublic2" tabindex="-1" role="dialog" aria-labelledby="myPublicLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">添加管理员</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label  class="control-label">管理员用户名</label>
<input type="text"  class="layui-input" id="name" placeholder="输入管理员用户名" >
</div>
<div class="form-group">
<label  class="control-label">管理员密码</label>
<input type="text"  class="layui-input" id="pass" placeholder="请输入管理员密码" >
</div>
<div class="form-group">
<label  class="control-label">管理员权限</label>
<select id="qx"    class="layui-input">
<option value="超级管理员">超级管理员</option>
<option value="资源管理员">资源管理员</option>
<option value="财务管理员">财务管理员</option>
<option value="系统管理员">系统管理员</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" id="pub_btn" class="btn btn-primary">确认</button>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade layui-form" id="myPublic" tabindex="-1" role="dialog" aria-labelledby="myPublicLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">修改管理员</h4>
</div>
<div class="modal-body">
<input type="hidden" name="id" class="form-control" id="recipient-id">
<div class="form-group">
<label  class="control-label">管理员密码</label>
<input type="text" name="pass" class="layui-input" id="recipient-pass">
</div>
<div class="form-group">
<label  class="control-label">管理员权限</label>
<select id="recipient-qx"    class="layui-input">
<option value="超级管理员">超级管理员</option>
<option value="资源管理员">资源管理员</option>
<option value="财务管理员">财务管理员</option>
<option value="系统管理员">系统管理员</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" id="publish_btn" class="btn btn-primary">确认</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
layui.use(['form', 'layedit', 'laydate', 'element', 'jquery', 'layer'], function(){
var form = layui.form
,layer   = layui.layer
,layedit = layui.layedit
,element = layui.element
,$= layui.jquery
,laydate = layui.laydate;
});
</script>
</body>
</html>