<?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;}
?>
<!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/layui.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>
</head>
<body style="padding:10px;">
<div class="tplay-body-div">
<?php
$sql = mysql_query("SELECT * FROM tglink");
$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">
<table class="layui-table" >
<thead>
<tr>
<th style="text-align:center;width:34px;" >勾选</th>
<th style="text-align:center;">影片名称</th>
<th style="text-align:center;">短链接</th>
</tr>
</thead>
<tbody>
<?php 
$page_size=6; 
$sql = "WHERE 1=1";
$resul = mysql_query("select id from tglink   ".$sql."  ");
$count = mysql_num_rows($resul); 
if($count == 0){echo '<tr><td colspan=15 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  tglink   ".$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 echo $a[name]?>" data-url="<?php echo $a[link]?>"><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: 95%;"></td>
<td align="center"><a href="<?php echo $a[link]?>"  target="_blank"><?php echo $a[link]?></a></td>
</tr>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
$keyt.="<a href=\""."/httgpage/1/\">首页</a>"; //首页 
$keyt.="<a href=\""."/httgpage/".($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=\""."/httgpage/".$i."/\">".$i."</a>"; 
} 
} 
if($page!=$pages){ 

$keyt.="<a href=\""."/httgpage/".($page+1)."/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/httgpage/{$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="7" 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 multipleDelete" href="#" role="button">批量删除链接</a>
</td>
</tr>
<?php }?>
</tbody>
</table>
</form>
<!--分页-->
<div style="padding:0 20px;">
<div class="pagination">
<?php if($count =="0"){?><?php }else{?><?php echo $keyt?><?php }?>
</div>
</div>
</div>
</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>
<?php if($count =="0"){?>
<?php }else{?>
<script type="text/javascript" src="/2019newui/js/clipboard.min.js"></script>
<script type="text/javascript">
$(function() {
var changeContent = function() {
var links = $('input[name="ids[]"]:checked');
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'),
name  = $(this).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,lx:'biaoti'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('修改成功');
location.reload();
} 
},
error:function(){
}
});
});
});
$(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:'shanchu'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('批量删除成功');
location.reload();
} 
},
error:function(){
}
});
});
});
</script>
<?php }?>
<?php if($count =="0"){?><?php }else{?>
<fieldset class="layui-elem-field layui-field-title" style="margin-top:20px;"><legend>操作说明</legend></fieldset>
<div class="div-c"><br>
<p  style="margin-left: 22px">1. 点击链接标题可以预览视频</p>
<br>
<p  style="margin-left: 22px">2. 价格直接修改, 鼠标光标离开即时保存</p>
<br>
<p  style="margin-left: 22px">3. 您可以直接修改右边内容, 然后再点击 <span class="btn btn-success btn-xs get-links">批量复制链接</span> 或 <b>手动复制</b></p>
</div> 
<div class="div-d"><textarea id="clip-content" style="height: 138px; padding: 10px; width: 600px;border:1px solid #ddd;resize:none;"  class="layui-textarea"></textarea></div> 
<?php }?> 
</div>
</div>
</div>
</div>
</body>
</html>