<?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">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>短链接</title>
<link href="/2019newui/m/css/common.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="/2019newui/js/jquery.min.js"></script>
<link href="/layui/css/m.css" rel="stylesheet"/>
<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>
<table class="layui-table" >
<thead>
<tr>
<th style="text-align:center;width: 28px;" >勾选</th>
<th style="text-align:center;" >名称</th>
<th style="text-align:center;" >短链接</th>
</tr>
</thead>
<tbody>
<?php 
$page_size=6; 
$sql= "WHERE 1=1";
$sql.=" and userid='$userid' ";
$resul = mysql_query("select * from  daili   ".$sql."");
$count = mysql_num_rows($resul);
if($count == 0){echo '<tr><td colspan="10" 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  daili  ".$sql."  order by id desc     limit $offset, $page_size");
while ($a=mysql_fetch_array($query)) { 
?> 	
<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']?>" data-title="<?php if($a['zt']=='待审核'){?>状态待审核<?php }else{?><?php echo $a['name']?><?php }?>" data-url="<?php if($a['zt']=='待审核'){?>状态待审核<?php }else{?><?php echo $a[link]?><?php }?>"><span class="demo--checkbox demo--radioInput"></span></label>
</td>
<td  style="text-align:center;" ><input type="text" name="title[]" class="title  layui-input" data-id="<?php echo $a['id']?>" value="<?php echo $a['name']?>" style="width: 100%;"></td>
<td  style="text-align:center;" ><?php if($a['zt']=='待审核'){echo "状态待审核";}else{echo "<a href='$a[link]'  target='_blank'>$a[link]</a>";}?></td>
</tr>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
$keyt.="<li><a href=\""."/mscpage/1/\">首页</a></li>"; //首页 
$keyt.="<li><a href=\""."/mscpage/".($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=\""."/mscpage/".$i."/\">".$i."</a></li>"; 
} 
} 
if($page!=$pages){ 
$keyt.="<li><a href=\""."/mscpage/".($page+1)."/\">下页 </a></li>";//下一页 
$keyt.="<li><a href=\""."/mscpage/{$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>条数据 "; 
?> 
<?php if($count =="0"){?>
<?php }else{?>
<tr>
<td  colspan="10" 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>
<button class="btn btn-success btn-xs get-links" role="button" data-clipboard-action="copy" data-clipboard-target="#clip-content">复制链接</button>
<a class="btn btn-danger btn-xs"  onclick="zonglian()" role="button">生成总链</a>
</td>
</tr>
<?php }?>
</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: 4rem;"></div>
</div>
<?php }?>
<div id="info" style = "display : none"></div>
<div class="link" >
<textarea id="clip-content" style="height: 258px;  width: 99.7%;border:1px solid #ddd;resize:none;text-align: center;font-size: 15px;"  data-clipboard-target="#clip-content" data-clipboard-action="copy"></textarea>
</div>
<div style="height: 4rem;"></div>
<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;
});
</script>
<?php if($count =="0"){?>
<?php }else{?>
<script type="text/javascript">
$(function() {
var changeContent = function() {
var links = $('input[name="ids[]"]:checked');
var myDate=new Date();
var contents = "<?php echo $tip?> \r\n 今日推荐视频更新于 <?php echo $day?>  \r\n------------------------ \r\n";
$.each(links, function(index, val) {
contents += $(val).attr('data-title') + "\r\n" + $(val).attr('data-url') + "\r\n\r\n";
});
contents += " \r\n------------------------ \r\n  <?php echo $tip1?> \r\n ++++ <?php echo $tip2?> ++++";
$('#clip-content').val(contents);
var clipboard = new Clipboard('.get-links');
clipboard.on('success', function(e) {
layer.msg('复制成功');
});
clipboard.on('error', function(e) {
layer.msg('复制失败');
});
}
$(document).on('click', '.chk-all', function(event) {
event.preventDefault();
$('input[name="ids[]"]').prop('checked', 'checked');
changeContent();
});
$(document).on('click', '.unchk-all', function(event) {
event.preventDefault();
$('input[name="ids[]"]').prop('checked', false);
changeContent();
});
$(document).on('change', 'input[name="ids[]"]', function(event) {
event.preventDefault();
changeContent();
});
// 修改标题
$(document).on('change', '.title', function(event) {
event.preventDefault();
var id  = $(this).attr('data-id'),
title  = $(this).val();
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
//更新标题
$.ajax({
type : "post",
url : "/mpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id: id, name : title, lx : 'name'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('影片名称更新成功');
location.reload();
} 
},
error:function(){
}
});
});
});
function zonglian() {
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/mpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {lx:'zonglian'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
var link = '';
var name = '';
var contents = "<br>&nbsp;&nbsp;&nbsp;<?php echo $tip?> <br><br> 今日推荐视频更新于 <?php echo $day?><br><br>";
for(i=0;i<data.lists.length;i++){
link = data.lists[i].url;
name = data.lists[i].name;
contents +="&nbsp;&nbsp;&nbsp;&nbsp;" + name + "<br><br>&nbsp;&nbsp;&nbsp;&nbsp;" + link + "<br><br>";
}
contents += "<br><br>&nbsp;&nbsp;&nbsp;<?php echo $tip1?> <br>&nbsp;&nbsp;&nbsp; ++++ <?php echo $tip2?> ++++";
$("#info").html(contents);
layer.open({
type: 1,
skin: 'layui-layer-rim', 
area: ['360px', '340px'], 
content: $("#info").html()
});
} 
},
error:function(){
}
});
}
function cq(page) {
if(page><?php echo $count?>){
layer.msg('当前共<?php echo $count?>页<br>请正确输入页码');
}else{
window.location.href='/mscpage/'+page+'/';
} 
}
</script>
<?php }?>
<script type="text/javascript" src="/2019newui/js/clipboard.min.js"></script>
<div style="height: 3rem;"></div>
<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>
</body>
</html>