<?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=$_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;}
$name=ubo($_GET["name"]);
$flid=ubo($_GET["flid"]);
?>
<!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>
</head>
<body>
<div class="x-body">
<?php
$sql = mysql_query("SELECT * FROM shipin");
$bs = mysql_num_rows($sql);
?>
<blockquote class="layui-elem-quote">
<dl class="apps-filter-tr">
<dt><?php if($name or $flid or $page){?><a href="javascript:;"  onclick="window.history.back(-1);" class="aui-navBar-item"><i class="icon layui-icon" style="font-size: 30px;">&#xF060;</i></a>    <?php }?><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 x-center" action="" style="width:700px">
<div class="layui-form-pane" style="margin-top: 15px;">
<div class="layui-form-item">
<label class="layui-form-label" style="width:60px">按分类</label>
<div class="layui-input-inline" style="width:220px;text-align: left">
<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>
<label class="layui-form-label" style="width:60px">按名称</label>
<div class="layui-input-inline" style="width:220px">
<input type="text"  name="name"  id="name"  autocomplete="off" class="layui-input" value="<?php if($name){echo $name;}?>" placeholder="请输入视频名称" onkeyup="cq(this.value)">
</div>
</div>
</div> 
</div>
</div> 
<table class="layui-table" id="data-row">
<thead>
<tr>
<?php if($name or $flid){?><?php }else{?><th style="text-align:center;width: 34px;" ><label class="demo--label2"><input class="demo--radio" type="checkbox"><span class="demo--checkbox demo--radioInput"></span></label></th><?php }?>
<!--<th style="text-align:center;" >影片ID</th>-->
<?php if($pic==1){?><th style="text-align:center;width: 120px;" >影片缩略图</th><?php }?>
<th style="text-align:center;" >影片名称<?php if($yulan=='1'){?>（点击预览）<?php }?></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=10; 
$sql = "WHERE 1=1";
if($name){
$sql .=" and name like '%$name%' ";
}
if($flid){
$sql .=" and flid='$flid' ";
}
$resul= mysql_query("select * from  shipin   ".$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); 
if($name){
$query = mysql_query("select * from  shipin  ".$sql."  order by id desc");
}elseif($flid){
$query = mysql_query("select * from  shipin  ".$sql."  order by id desc");
}else{
$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>
<?php if($name or $flid){?>
<?php }else{?>
<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>
<?php }?>
<!--<td align="center"><?php echo $a[id]?></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  style="text-align:center;" ><?php if($yulan=='1'){?><a   onClick="play('<?php echo $a['id']?>','gl')"  ><?php echo $a['name']?></a ><?php }else{?><?php echo $a['name']?><?php }?></td>
<td align="center"><?php echo $flname?></td>
<td  style="text-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 style="text-align:center;" ><?php echo $a['shijian']?></td>
<td  style="text-align:center;" >
<?php 
$type="where spid='$a[id]' and userid='$userid'";
$shiping=queryall(daili,$type);
?>
<?php if($shiping){?>
<span class="label label-tt">您已添加</span>
<?php }else{?>
<?php 
$type="where url='$a[url]' and userid='$userid'";
$shiping2=queryall(daili,$type);
?>
<?php if($shiping2){?>
<span class="label label-ttt">您共享的视频</span>
<?php }else{?>
<button   class="layui-btn layui-btn-small layui-btn-normal publish_btn" data-id="<?php echo $a['id']?>" data-name="<?php echo $a['name']?>"  data-toggle="modal" data-target="#myPublic">点击添加</button >
<?php }?>
<?php }?>
</td>
</tr>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
if($name or $flid){
}else{
$keyt.="<a href=\""."/xtpage/1/\">首页</a>"; //首页 
$keyt.="<a href=\""."/xtpage/".($page-1)."/\">上一页 </a>"; //上一页 
}
}else { 
if($name or $flid){
}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){ 
if($name or $flid){
}else{
$keyt.='<a class="cur">'.$i.'</a>'; 
}
} else { 
if($name or $flid){
}else{
$keyt.="<a href=\""."/xtpage/".$i."/\">".$i."</a>";
} 
} 
} 
if($page!=$pages){ 
if($name or $flid){
}else{
$keyt.="<a href=\""."/xtpage/".($page+1)."/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/xtpage/{$pages}/\">尾页</a> "; //最后一页 
}
}else { 
if($name or $flid){
}else{
$keyt.="<p>下一页 </p>";//下一页 
$keyt.="<p>尾页</p>"; //最后一页 
}
} 
if($name or $flid){
}else{
$keyt.="<p class='pageRemark' >当前第 <b> $page </b> 页/共 <b> $pages </b> 页  共 <b>$count</b> 条数据 </p>"; //第几页,共几页 
}
?>   	    	
<?php if($count =="0"){?>
<?php }else{?>
<?php if($name or $flid){?>
<?php }else{?>
<tr>
<td  colspan="8" 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-xs btn-jiage pltj"  role="button">批量添加</a>
<a class="btn  btn-xs btn-jiage yiji"  onclick="yiji()" role="button">一键添加</a>
</td>
</tr>
<?php }?>
<?php }?>
</tbody>
</table>
<div class="pagination">
<?php if($count =="0"){?><?php }else{?><?php echo $keyt?><?php }?>
</div>
</div>
</div>
<br><br><br><br>
<br>
<br>
<br>
<?php if($count =="0"){?>
<?php }else{?>
<?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>
$(function(){
var cks = $(":checkbox:gt(0)"); 
var fk = $(":checkbox:first").click(function(){
cks.prop("checked", $(this).prop("checked"));
changeContent();
});
cks.click(function(){
if(!$(this).prop("checked")){
fk.prop("checked",false);
changeContent();
}else{
if(cks.filter(":not(:checked)").length == 0){
fk.prop("checked",true);
changeContent();
}
}
});
});
$(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('click', '.pltj', 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 : "/post<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id: _ids, lx: 'pltj'},
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(){
}
});
});

function yiji() {
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: {lx: 'yjtj'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('添加成功');
location.reload();
}else{
layer.msg(data.msg);
location.reload();
} 
},
error:function(){
}
});
});
}
</script>
<script>
function dochange(){
if(document.getElementById("checkbox1").checked){
$('#issuiji').val('0');
$('#gd').css('display',"none");
$('#jg').css('display',"block");
}else{
$('#issuiji').val('1');
$('#jg').css('display',"none");
$('#gd').css('display',"block");
}
}
function gais(){
var zuidi="<?php echo $zxm?>";
var s=$('#s').val();
if(s<zuidi && s!=''){
layer.msg('最低价格不能小于'+zuidi+'元');
return;
}
$('#start').html(s);
}
function gaie(){
var s=$('#s').val();
var e=$('#e').val();
var zuigao="<?php echo $zdm?>";
if(e>zuigao && e!=""){
layer.msg('最高价格不能大于'+zuigao+'元');
return;
}
$('#end').html(e);
}
function gaiguding(){
var zuidi= <?php echo $zxm?>;
var zuigao= <?php echo $zdm?>;
var val=$('#g').val();
var g = parseInt(val);
if(g!="" && g<zuidi){
layer.msg('固定价格不能小于'+zuidi+'元');
$('#g').val(zuidi);
return;
}
if(g!="" && g>zuigao){
layer.msg('固定价格不能大于'+zuigao+'元');
$('#g').val(zuigao);
return;
}
$('#gudingmoney').html(g+"元");
}
$(function () {
$("#publish_btn").click(function () {
var id = $("#recipient-id").val();
var guding = $("#g").val();
var title = $("#recipient-name").val();
var start = $("#s").val();
var end = $("#e").val();
var issuiji = $("#issuiji").val();
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$('#myPublic').css('display',"none");
$.ajax({
type:'POST',
url : "/post<?php echo $dshz?>",
data: {id:id,guding:guding,title:title,start:start,end:end,issuiji:issuiji,lx:'fb'},
dataType:'json',
success:function(result){
if(result.status == '1'){
layer.closeAll('loading');
layer.msg('发布成功');
location.reload();
}else if(result.status == '2'){
layer.closeAll('loading');
layer.msg('标题不能为空');
}
}	
});
});
})
$('.publish_btn').on('click', function () {
$('#recipient-id').val($(this).data('id'));
$('#recipient-name').val($(this).data('name'));
})
</script>
<?php if($sjsz==1){?>
<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 for="recipient-name" class="control-label">标题</label>
<input type="text" name="title" class="layui-input" id="recipient-name">
</div>
<div class="form-group">
<div class="layui-form-item" id='jg'>
<div class="layui-inline">
<label class="layui-form-label">打赏</label>
<div class="layui-input-inline" style="width: 100px;">
<input type="text"  name="start"  oninput="gais()" id="s" class="layui-input" value="3" >
</div>
<div class="layui-form-mid">元 -</div>
<div class="layui-input-inline" style="width: 100px;">
<input type="text" id="e" name="end"  oninput="gaie()"  class="layui-input" value="5" >
</div>
<div class="layui-form-mid">元</div>
</div>
</div>
<div class="layui-form-item" id='gd' style="display:none;">
<label class="layui-form-label">固定</label>
<div class="layui-input-inline">
<input type="text"  name="guding123" oninput="gaiguding()"  id="g" value="3"  class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">元</div>
</div>
<input type="hidden" name="issuiji" value="0" id="issuiji"/>
</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>
<?php }else{?>
<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 for="recipient-name" class="control-label">标题</label>
<input type="text" name="title" class="layui-input" id="recipient-name">
</div>
<div class="form-group">
<div class="layui-form-item" id='gd'>
<label class="layui-form-label">固定</label>
<div class="layui-input-inline">
<input type="text"  name="guding123" oninput="gaiguding()"  id="g" value="3"  class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">元</div>
</div>
<input type="hidden" name="issuiji" value="0" id="issuiji"/>
</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 }?>
<?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;
form.on('select(paylx)', function(data){
if (data.value=='请选择') {
layer.msg('请选择分类');
return false;
}else{
window.location.href='/xitong<?php echo $dshz?>?flid='+data.value; 
}
});
});
</script>
<?php if($count =="0"){?>
<?php }else{?>
<?php if($yulan=='1'){?>
<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', '390px'],
content:url
}); 
}
</script>
<?php }?>
<?php }?>
<script>
function cq(name) {
window.location.href='/xitong<?php echo $dshz?>?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>