<?php
error_reporting(0); 
include("../../config/wap.php");
session_start();
if(!isset($_SESSION['username'])){echo "<script>alert('请重新登录!')</script><script>top.location.href='/m$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='/m$dshz'</script>";exit;}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312">
<title>公共片库</title>
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
<meta content="yes" name="apple-mobile-web-app-capable"/>
<meta content="black" name="apple-mobile-web-app-status-bar-style"/>
<meta content="telephone=no" name="format-detection"/>
<link href="/2019newui/m/css/common.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="/2019newui/js/jquery.min.js"></script>
<script src="/2019newui/js/bootstrap.min.js"></script>
<link href="/layui/css/m.css" rel="stylesheet"/>
<script src="/layui/layui.js"></script>
<link href="/2019newui/page.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<header class="aui-navBar aui-navBar-fixed">
<a href="javascript:;"  onclick="window.history.back(-1);" class="aui-navBar-item"><i class="icon layui-icon" style="font-size: 20px;">&#xF060;</i></a>
<div class="aui-center"><span class="aui-center-title">公共片库</span></div>
</header>
<div class="divHeight"></div>
<div class="aui-list-theme">
<?php 
$page_size=10; 
$sql = "WHERE 1=1";
$resul= mysql_query("select * from  shipin  ".$sql."");
$count= mysql_num_rows($resul);
if($count=='0'){echo '<center>暂无记录</center>';}
$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)) { 
?> 	
<a   class="aui-list-theme-item">
<div class="aui-list-img" <?php if($yulan=='1'){?>onClick="play('<?php echo $a[id]?>','gl')"<?php }?>  ><img src="<?php if($a[pic]){?><?php echo $a[pic]?><?php }else{?>/2019newui/images/nopic.jpg<?php }?>" alt=""  style="width: 100%;height:100px"></div>
<?php 
$qgg="where spid='$a[id]' and userid='$userid'";
$shiping=queryall(daili,$qgg);
?>
<?php if($shiping){?>
<?php }else{?>
<div class="checkbox" style="position:absolute;top:0;z-index:1000">
<label class="demo--label"><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>
</div>
<?php }?>
<div class="aui-list-title">
<h3><?php echo $a['name']?></h3>
<?php 
$qgg="where spid='$a[id]' and userid='$userid'";
$shiping=queryall(daili,$qgg);
?>
<?php if($shiping){?>
<button   style="background:red;color:#fff" >已添加</button>
<?php }else{?>
<button   class="publish_btn" data-id="<?php echo $a['id']?>"  data-name="<?php echo $a['name']?>" data-toggle="modal" data-target="#myPublic">添加到私有片库</button >
<?php }?>
</div>
</a>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
$keyt.="<li><a href=\""."/mxtpage/1/\">首页</a></li>"; //首页 
$keyt.="<li><a href=\""."/mxtpage/".($page-1)."/\">上页 </a></li>"; //上一页 
}else { 
$keyt.="<li>首页</li>"; //首页 
$keyt.="<li>上页</li>"; //上一页  
} 
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.='<li class="active">'.$i.'</li>'; 
} else { 
$keyt.="<li><a href=\""."/mxtpage/".$i."/\">".$i."</a></li>"; 
} 
} 
if($page!=$pages){ 
$keyt.="<li><a href=\""."/mxtpage/".($page+1)."/\">下页 </a></li>";//下一页 
$keyt.="<li><a href=\""."/mxtpage/{$pages}/\">尾页</a></li>"; //最后一页 
}else { 
$keyt.="<li>下页</li>";//下一页 
$keyt.="<li>尾页</li>"; //最后一页 
} 
$keyt.='<li class="totalPage">跳转<input type="text" onkeyup="cq(this.value)" value="'.$page.'" ><span>页</span></li><br>';
$keyt.="<li class='totalPage'>当前第 <b>$page</b> 页/共 <b>$pages</b> 页</li>"; 
$keyt.="<li class='totalPage'>每页<b>$page_size</b>条数据</li>"; 
$keyt.="<li class='totalPage'>总共<b>$count</b>条数据 "; 
?> 
</div>
<table class="layui-table">
<thead>
<?php if($count=="0"){?>
<?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-danger pltj"  role="button">批量添加</a>
</td>
</tr>
<?php }?>
</thead>
<tbody>
</tbody>
</table>
<?php if($count=="0"){?>
<?php }else{?>
<div style="height:10px;"></div>
<div id="pagination" class="pagination">
<ul>
<?php if($count =="0"){?><?php }else{?><?php echo $keyt?><?php }?>
</ul>
</div>
<div style="height: 8rem;"></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>
<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>99 && e!=""){
layer.msg('最高价格不能大于<?php echo $zdm?>元');
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'] 
});
$.ajax({
type:'POST',
url : "/mpost<?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'){
$('#myPublic').css('display',"none");
layer.closeAll('loading');
layer.msg('添加成功');
location.reload();
}else{
layer.closeAll('loading');
layer.msg(result.msg);
}
}	
});
});
})
$('.publish_btn').on('click', function () {
$('#recipient-id').val($(this).data('id'));
$('#recipient-name').val($(this).data('name'));
})
function play(id,lx) {
var url='/sjplay_'+id+'_'+lx+'<?php echo $dshz?>';
layer.open({
type: 2,
title: '视频预览(预览前<?php echo $shipinsj?>秒视频)',
shadeClose: true,
shade: 0.8,
area: ['300px', '250px'],
content:url
}); 
}
</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>
<input type="hidden" name="id"  id="recipient-id">
<div class="modal-body">
<div class="form-group">
<label for="recipient-name" class="control-label">标题</label>
<div class="layui-input-inline"  style="width: 88%;">
<input type="text" name="title" class="layui-input" id="recipient-name"  >
</div>
</div>
<div class="form-group" id='jg'>
<label  class="control-label">随机</label>
<div class="layui-input-inline" style="width: 43%;">
<input type="text"  name="start"  oninput="gais()" id="s"  class="layui-input" value="3" >
</div>
<div class="layui-input-inline" style="width: 44%;">
<input type="text" id="e" name="end"  oninput="gaie()"  class="layui-input" value="5" >
</div>
</div>
<div class="form-group" id='gd' style="display:none;">
<label class="control-label">固定</label>
<div class="layui-input-inline"  style="width: 88%;">
<input type="text"  name="guding123" oninput="gaiguding()"  id="g" value="3"  class="layui-input">
</div>
</div>
<div class="foot4">
<input checked type="checkbox" onChange="dochange()" id="checkbox1" style="margin-right:5px;background:0;border:1px solid #333;" /><span id="suiji1">随机（<span id="start">3</span>到<span id="end">5</span>元)</span>
<span id="guding1" class="yincang">固定（<span id="gudingmoney">3元</span>)</span>
</div>
<input type="hidden" name="issuiji" value="0" id="issuiji"/>
</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 }?>
<footer class="aui-footer aui-footer-fixed">
<a href="/mmain<?php echo $dshz?>" class="aui-tabBar-item"><i class="icon layui-icon" style="font-size: 30px;">&#xF015;</i><span class="aui-tabBar-item-text">首页</span></a>
<a href="/mdingdan<?php echo $dshz?>" class="aui-tabBar-item"><i class="icon layui-icon" style="font-size: 30px;">&#xF123;</i><span class="aui-tabBar-item-text">订单</span></a>
<a href="/muser<?php echo $dshz?>" class="aui-tabBar-item"><i class="icon layui-icon" style="font-size: 30px;">&#xF007;</i><span class="aui-tabBar-item-text">我的</span></a>
</footer>
<?php if($count =="0"){?>
<?php }else{?>
<script>
$(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 : "/mpost<?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);
} 
},
error:function(){
}
});
});
</script>
<script type="text/javascript">
function cq(page) {
if(page><?php echo $count?>){
layer.msg('当前共<?php echo $count?>页<br>请正确输入页码');
}else{
window.location.href='/mxtpage/'+page+'/';
} 
}
</script>
<?php }?>
</body>
</html>