<?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]=='超级管理员' or $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 fenlei");
$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;" >分类ID</th>
<th style="text-align:center;" >分类名称</th>
<th  style="text-align:center;">显示/隐藏</th>
<th style="text-align:center;">操作</th>
</tr>
</thead>
<tbody>
<?php 
$sql = "WHERE 1=1";
$resul= mysql_query("select id from fenlei   ".$sql."  ");
$count = mysql_num_rows($resul); 
if($count == 0){echo '<tr><td colspan=18 style="text-align:center;">没有记录</td></tr>';}
$query = mysql_query("select * from  fenlei  ".$sql." order by id desc");
while ($a=mysql_fetch_array($query)) { 
?> 	
<tr>
<td align="center"><?php echo $a[id]?></td>
<td align="center"><input type="text" name="ms[]" class="ms layui-input" data-id="<?php echo $a['id']?>" value="<?php echo $a[name]?>"  style=" height: 30px;text-align:center;"></td>
<td style="text-align:center;" ><div class="layui-form"><input type="checkbox"  name="open"  data-id="<?php echo $a[id]?>"  lay-skin="switch" lay-filter="sz" lay-text="显示|隐藏" <?php if($a[yc]=="1"){?> checked<?php }?>></div></td>
<td align="center">
<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 } ?> 
</tbody>
</table>
</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: 'flsc'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading'); 
layer.msg('删除成功');
location.reload();
} 
},
error:function(){
}
});
});
}
</script>
<script type="text/javascript">
$('.pub_btn').on('click', function () {
})
$(function () {
$("#pub_btn").click(function () {
var name = $("#name").val();
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: {name:name, lx: 'fladd'},
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(){
}
});
});
})
$(document).on('change', '.ms', function(event) {
event.preventDefault();
var id  = $(this).attr('data-id'),
name = $(this).val();
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,name:name,lx:'flname'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.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="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>
</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;
form.on('switch(sz)', function (data) {
var zt = this.checked ? '1' : '0',
id = $(this).attr('data-id');
if(zt=='1'){
tip='显示吗？';
}else{
tip='隐藏吗？';
}
layer.confirm("确认要" +tip , { 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:'flsz',zt:zt},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('设置成功');
location.reload();
} 
},
error:function(){
}
});
}); 
});
});
</script>
</body>
</html>