<?php
error_reporting(0); 
include("../../config/qiantai.php");
session_start();
if(!isset($_SESSION['username'])){echo "<script>alert('请重新登录!')</script><script>top.location.href='/index$dshz'</script>";exit;}
$username=ubo($_SESSION['username']);
$type="where name='$username'";
$user=queryall(user,$type);
$userid=$user['userid'];
if(!$user){echo "<script>alert('请重新登录!')</script><script>top.location.href='/index$dshz'</script>";exit;}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312">
<title>我的分类</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/2019newui/qiantai/css/x-admin.css" media="all">
<script src="/2019newui/js/jquery1.9.min.js"></script>
<script src="/2019newui/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/layui/css/houtai.css" media="all" />
</head>
<body>
<div class="x-body">
<?php
$sql = mysql_query("SELECT * FROM dlfl where userid='$userid'");
$bs = mysql_num_rows($sql);
?>
<blockquote class="layui-elem-quote">
<dl class="apps-filter-tr">
<dt><span  class="xb">我的分类</span></dt>
</dl>
<span class="x-right" style="margin-top:-24px;line-height:10px">共有分类：<?php echo $bs?> 个 <a class="layui-btn-small" style="line-height:10px;margin-top:-2px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="fa fa-refresh"></i></a></span>
</blockquote>
<div class="layui-form-item" style="text-align:center;">
<div class="layui-inline">
<div class="layui-input-inline">
<input autocomplete="off" class="layui-input" placeholder="请在此添加分类" type="text"  name="name"  id="name">
</div>
</div>
<div class="layui-inline" style="text-align:left;">
<div class="layui-input-inline">
<button class="layui-btn" onclick="add()" >添加分类</button>
</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>
<th style="text-align:center;" >操作</th>
</tr>
</thead>
<tbody>
<?php 
$page_size=12; 
$sql = "WHERE 1=1";
$sql.=" and userid='$userid' ";
$resul= mysql_query("select * from  dlfl   ".$sql."");
$count= mysql_num_rows($resul);
if($count =='0'){echo '<tr><td colspan="6" 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  dlfl  ".$sql."  order by id desc     limit $offset, $page_size");
while ($a=mysql_fetch_array($query)) { 
$sql2 = mysql_query("SELECT * FROM daili where flid='$a[id]'");
$spbs = mysql_num_rows($sql2);
?> 	
<tr>
<td style="text-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 align="center">共<?php echo $spbs?>部</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>
</td>
</tr>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
$keyt.="<a href=\""."/dlflpage/1/\">首页</a>"; //首页 
$keyt.="<a href=\""."/dlflpage/".($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=\""."/dlflpage/".$i."/\">".$i."</a>";
} 
} 
if($page!=$pages){ 
$keyt.="<a href=\""."/dlflpage/".($page+1)."/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/dlflpage/{$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>
<?php if($count =="0"){?>
<?php }else{?>
<script>
function sc(id) {
layer.confirm("确定要删除吗？", { title: "确认" }, function (index) {
layer.close(index);
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/post<?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(){
}
});
});
}
$(document).on('change', '.ms', function(event) {
event.preventDefault();
var id  = $(this).attr('data-id');
var name = $(this).val();
layer.close(index);
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/post<?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();
}else{
layer.closeAll('loading');
layer.msg(data.msg);
} 
},
error:function(){
}
});
});
</script>
<?php }?>
<script src="/layui/layui.js"></script>
<script>
layui.use(['form', 'layedit', 'laydate', 'element', 'jquery', 'layer'], function(){
var form = layui.form
,layer = layui.layer
,layedit = layui.layedit
,element = layui.element
,laydate = layui.laydate
,$ = layui.jquery;
<?php if($count =="0"){?>
<?php }else{?>
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 : "/post<?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(){
}
});
}); 
});
<?php }?>
});
function add() {
var name = $('#name').val();
if (name== '') {
layer.msg('分类名称不能为空');
return false;
}
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/post<?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);
} 
},
error:function(){
}
});
}
</script>
</body>
</html>