<?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;}
$name=ubo($_GET["name"]);
$flid=ubo($_GET["flid"]);
?>
<!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' type="text/javascript"></script>
<script src="/layui/layui.js"></script>
<script src="/2019newui/js/bootstrap.min.js"></script>
</head>
<body style="padding:10px;">
<div class="tplay-body-div">
<?php
$sql = mysql_query("SELECT * FROM shipin");
$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 layui-form">
<div class="layui-form-item">
<label class="layui-form-label">按视频名称</label>
<div class="layui-input-inline">
<input type="text"  name="name"  id="name"  autocomplete="off" class="layui-input" value="<?php if($name){echo $name;}?>" placeholder="请输入视频名称">
</div>
<div class="layui-form-mid layui-word-aux"><button class="layui-btn"  onclick="so()" style="margin-top:-10px;"><i class="layui-icon" style="">&#xe615;</i> 查询</button></div>
<div class="layui-inline">
<label class="layui-form-label">按视频分类</label>
<div class="layui-input-inline">
<select name="paylx"    lay-filter="paylx">
<option value='请选择'>请选择分类</option>
<option value=''>全部数据</option>
<?php 
$result = mysql_query("SELECT * FROM  fenlei");
$count = mysql_num_rows($result);
?>
<?php if($count == 0){?><option value='0'>暂无分类</option><?php }?>
<?php
$query = mysql_query("SELECT * FROM fenlei");
while($a = mysql_fetch_array($query)) {
?>  
<option value='<?php echo $a[id]?>'><?php echo $a[name]?></option>
<?php }?>
</select>
</div>
</div>
</div>
</div>
<table class="layui-table" id="data-row">
<thead>
<tr>
<th style="text-align:center;width:34px;" >勾选</th>
<th style="text-align:center;">视频名称</th>
<?php if($pic==1){?><th style="text-align:center;width: 120px;" >影片缩略图</th><?php }?>
<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;">操作</th>
</tr>
</thead>
<tbody>
<?php 
$page_size=18; 
$sql = "WHERE 1=1";
if($name){
$sql .=" and name like '%$name%' ";
}
if($flid){
$sql .=" and flid='$flid' ";
}
$resu = mysql_query("select id from shipin   ".$sql."  ");
$count = mysql_num_rows($resu); 
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  shipin   ".$sql." order by id desc   limit $offset, $page_size");
while ($a=mysql_fetch_array($query)) { 
$type="where id='$a[flid]'";
$fl=queryall(fenlei,$type);
if($fl[name]){
$flname=$fl[name];
}else{
$flname='暂无分类';
}
?> 	
<tr>
<td style="text-align:center;" ><label class="demo--label2"><input class="demo--radio" type="checkbox"   name="ids[]" id="ck-<?php echo $a['id']?>" value="<?php echo $a['id']?>"><span class="demo--checkbox demo--radioInput"></span>   </label></td>
<td align="center"><?php echo $a[name]?></td>
<?php if($pic==1){?><td style="text-align: center;"><img style="width: 120px; height: 80px; cursor: -webkit-zoom-in;" src="<?php echo $a[pic]?>"  onerror="this.src = '/2019newui/images/nopic.jpg'" ></td><?php }?>
<td align="center"><?php echo $flname?></td>
<td align="center"><?php if($a[sj]==$a[money]){?><?php echo $a[money]?><?php }else{?><?php echo $a[sj]?>-<?php echo $a[money]?><?php }?></td>
<td align="center"><?php echo $a[cs]?></td>
<td align="center"><a   onClick="play('<?php echo $a[id]?>','gl')"  ><?php if (strpos($a[url], 'http://') !== false or strpos($a[url], 'https://') !== false) {?><?php echo $a[url]?><?php }else{?>../<?php echo $a[url]?><?php }?></a></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-name="<?php echo $a[name]?>"  data-sj="<?php echo $a[sj]?>"   data-money="<?php echo $a[money]?>"   data-cs="<?php echo $a[cs]?>"     style="margin-right: 0;font-size:12px;"><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){ 
if($name){
$keyt.="<a href=\""."/htgllistpageso/1/$name/\">首页</a>"; //首页 
$keyt.="<a href=\""."/htgllistpageso/".($page-1)."/$name/\">上一页 </a>"; //上一页 
}elseif($flid){
$keyt.="<a href=\""."/htgllistpagefl/1/$flid/\">首页</a>"; //首页 
$keyt.="<a href=\""."/htgllistpagefl/".($page-1)."/$flid/\">上一页 </a>"; //上一页 
}else{
$keyt.="<a href=\""."/htgllistpage/1/\">首页</a>"; //首页 
$keyt.="<a href=\""."/htgllistpage/".($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 { 
if($name){
$keyt.="<a href=\""."/htgllistpageso/".$i."/$name/\">".$i."</a>"; 
}elseif($flid){
$keyt.="<a href=\""."/htgllistpagefl/".$i."/$flid/\">".$i."</a>"; 
}else{
$keyt.="<a href=\""."/htgllistpage/".$i."/\">".$i."</a>"; 
}
} 
} 
if($page!=$pages){ 
if($name){
$keyt.="<a href=\""."/htgllistpageso/".($page+1)."/$name/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/htgllistpageso/{$pages}/$name/\">尾页</a> "; //最后一页 
}elseif($flid){
$keyt.="<a href=\""."/htgllistpagefl/".($page+1)."/$flid/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/htgllistpagefl/{$pages}/$flid/\">尾页</a> "; //最后一页 
}else{
$keyt.="<a href=\""."/htgllistpage/".($page+1)."/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/htgllistpage/{$pages}/\">尾页</a> "; //最后一页 
}
}else { 
$keyt.="<p>下一页 </p>";//下一页 
$keyt.="<p>尾页</p>"; //最后一页 
} 
$keyt.="<p class='pageRemark' >当前第 <b>$page</b> 页/共 <b>$pages</b> 页  共 <b>$count</b> 条数据 </p>"; //第几页,共几页 
?> 
<?php if($count =="0"){?><?php }else{?>
<tr>
<td  colspan="18" style="text-align:left;padding-left:20px;" >
<a class="btn btn-success btn-xs chk-all" href="#" role="button">全选</a>  
<a class="btn btn-danger btn-xs unchk-all" href="#" role="button">全不选</a>
<a class="btn btn-danger btn-xs multipleDelete" href="#" role="button">批量删除</a>
<!--<a class="btn btn-success btn-xs sclj" href="#" role="button">批量生成链接</a>-->
<a class="btn  btn-success  btn-xs btn-jiage gg"  role="button">批量更改价格</a>
<a class="btn  btn-success  btn-xs btn-up rs"  role="button">批量更改打赏人数</a>
<a class="btn  btn-success  btn-xs btn-up"  role="button" onClick="tj()">更新所有视频地址，防止被盗链</a>
</td>
</tr>
<?php }?>
</tbody>
</table>
<!--分页-->
<div style="padding:0 20px;">
<div class="pagination">
<?php if($count =="0"){?><?php }else{?><?php echo $keyt?><?php }?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php if($pic==1){?>
<div id="img-div" style="position: fixed; left: 0; right: 0; bottom: 0; top: 0; z-index: 999999; text-align: center; display: none; ">
<img id="big-img" style="position:relative;z-index:99999;cursor:-webkit-zoom-out;" src="">
<div style="position:fixed;left:0;right:0;bottom:0;top:0;background:#000000;opacity:0.4; z-index:111;">
</div>
</div>
<?php }?>
<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('select(paylx)', function(data){
if (data.value=='请选择') {
layer.msg('请选择分类');
return false;
}else{
window.location.href='/htgllist<?php echo $dshz?>?flid='+data.value; 
}
});
});
</script>
<?php if($count =="0"){?>
<?php }else{?>
<script type="text/javascript">
function play(id,lx) {
var url='/play_'+id+'_'+lx+'<?php echo $dshz?>';
layer.open({
type: 2,
title: '视频预览(预览前<?php echo $shipinsj?>秒视频)',
shadeClose: true,
shade: 0.8,
area: ['500px', '350px'],
content:url
}); 
}
</script>
<script type="text/javascript">
$(function () {
$("#publish_btn").click(function () {
var id = $("#recipient-id").val();
var name = $("#recipient-name").val();
var cs = $("#recipient-cs").val();
var sj = $("#recipient-sj").val();
var money = $("#recipient-money").val();
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,cs:cs,sj:sj,money:money,lx:'glspxg'},
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(){
}
});
});
})
$('.publish_btn').on('click', function () {
$('#recipient-id').val($(this).data('id'));
$('#recipient-name').val($(this).data('name'));
$('#recipient-cs').val($(this).data('cs'));
$('#recipient-sj').val($(this).data('sj'));
$('#recipient-money').val($(this).data('money'));
})
</script>
<script type="text/javascript">
$(function() {
$(document).on('click', '.chk-all', function(event) {
event.preventDefault();
$('input[name="ids[]"]').prop('checked', 'checked');
});
$(document).on('click', '.unchk-all', function(event) {
event.preventDefault();
$('input[name="ids[]"]').prop('checked', false);
});
$(document).on('change', 'input[name="ids[]"]', function(event) {
event.preventDefault();
});
});
$(document).on('click', '.multipleDelete', function(event) {
event.preventDefault();
var _ids = '';
$.each($('input[name="ids[]"]:checked'), function(index, val) {
_ids += $(val).val()+',';
});
if (_ids == '') {
layer.msg('请选择要操作的ID');
return false;
}
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: _ids,lx:'glspsc'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('删除成功');
location.reload();
} 
},
error:function(){
}
});
});
});
$(document).on('click', '.sclj', function(event) {
event.preventDefault();
var _ids = '';
$.each($('input[name="ids[]"]:checked'), function(index, val) {
_ids += $(val).val()+',';
});
if (_ids == '') {
layer.msg('请选择要操作的ID');
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: _ids,lx:'gllink'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('批量生成成功');
location.reload();
} 
},
error:function(){
}
});
});
$(document).on('click', '.gg', function(event) {
event.preventDefault();
var _ids = '';
$.each($('input[name="ids[]"]:checked'), function(index, val) {
_ids += $(val).val()+',';
});
if (_ids == '') {
layer.msg('请选择要操作的ID');
return false;
}
layer.open({
title: '批量更新价格',
area: '300px',
shade: 0.8,
content: '<div class="mark"><div style="margin: 5px 0;">打赏 :<span><input type="text" value="2"  id="sjmoney">元 到</span><input type="text" value="5"  id="gdmoney">元</div><div>(如固定价格则填相同的价格)</div></div>',
btn: ['确认'],
shadeClose: false,
yes: function(){
var sjmoney = $("#sjmoney").val();
var gdmoney = $("#gdmoney").val();
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/htpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id: _ids,sjmoney:sjmoney,gdmoney:gdmoney, lx : 'glgg'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('批量更新价格成功');
location.reload();
} 
},
error:function(){
}
});
},
});
});
$(document).on('click', '.rs', function(event) {
event.preventDefault();
var _ids = '';
$.each($('input[name="ids[]"]:checked'), function(index, val) {
_ids += $(val).val()+',';
});
if (_ids == '') {
layer.msg('请选择要操作的ID编号');
return false;
}
layer.open({
title: '批量更新打赏人数',
area: '80px',
shade: 0.8,
content: '<div class="mark"><div style="margin: 0px 0px 10px 1px;"><span><input type="text" value=""  id="cs" style="width: 120px;height:30px;" placeholder="请输入数值" ></div></div>',
btn: ['确认'],
shadeClose: false,
yes: function(){
var cs = $("#cs").val();
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/htpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id: _ids,cs:cs, lx : 'glrs'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('批量更新打赏人数成功');
location.reload();
} 
},
error:function(){
}
});
},
});
});
function tj() {
layer.open({
title: '请输入安全码',
area: '220px',
shade: 0.8,
content: '<div class="mark"><div style="margin: 0px 0px 10px 1px;"><span><input type="text" value=""  id="aqm" style="width: 88%;height:30px;" placeholder="安全码" ><br><br><div>请输入安全码，以保证数据安全</div></div></div>',
btn: ['确认'],
shadeClose: false,
yes: function(){
var aqm = $("#aqm").val();
if (aqm == '') {
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: {aqm:aqm, lx: 'glsp'},
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" 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="name" class="layui-input" id="recipient-name">
</div>
<div class="form-group">
<label  class="control-label">打赏人数</label>
<input type="text" name="cs" class="layui-input" id="recipient-cs">
</div>
<div class="form-group">
<div class="layui-form-mid">打赏金额</div>
<div class="layui-inline">
<div class="layui-input-inline" style="width: 260px;">
<input type="text"    id="recipient-sj" class="layui-input">
</div>
元-
<div class="layui-input-inline" style="width: 260px;">
<input type="text" id="recipient-money"  class="layui-input">
</div>
元
</div>
</div>
</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>
<?php }?>
<script type="text/javascript">
function so() {
var name = $('#name').val();
if (name== '') {
layer.msg('请输入视频名称');
return false;
}
window.location.href='/xitong/houtai/gllist.php?page=1&name='+name; 
}
<?php if($pic==1){?>
$(function () {
$("body").on('click', '#data-row img', function () {
$("#big-img").attr("src", this.src);
var tWidth = document.body.offsetWidth;
var tHeight = window.screen.availHeight;
var sw = this.width;
var sh = this.height;
var tRate = tWidth * 1.0 / tHeight;
var rate = sw * 1.0 / sh;
var rh;
if (tRate > rate) {
$("#big-img").css("height", (tHeight - 280) + 'px');
$("#big-img").css('width', 'auto');
rh = tHeight - 80;
} else {
$("#big-img").css("width", '80%');
$("#big-img").css('height', '60%');
rh = sh / sw * (tWidth * 0.8);
}
if (rh < tHeight - 100) {
$("#big-img").css('margin-top', (tHeight - rh) / 2 + 'px');
} else {
$("#big-img").css('margin-top', '6px');
}
$("#img-div").show();
});
$("#img-div").click(function () {
$("#img-div").hide();
});
});
<?php }?>
</script>
</body>
</html>