<?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;}
$type="where userid='$userid'";
$wangzhan=queryall(wangzhan,$type);
?>
<!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>
<script src="/2019newui/js/jscolor.js"></script>
<script src="/layui/layui.js"></script>
<link rel="stylesheet" href="/layui/css/layui.css" media="all" />
</head>
<body>
<div class="x-body">
<blockquote class="layui-elem-quote">
<dl class="apps-filter-tr">
<dt><span  class="xb">站点信息</span></dt>
</dl>
<span class="x-right" style="margin-top:-24px;line-height:10px"> <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>
<?php if($wangzhan){?>
<table class="layui-table">
<thead>
<tr>
<th style="text-align:center;" >站点标题</th>
<th style="text-align:center; " >背景颜色</th>
<th style="text-align:center;;width:34px;" >操作</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><?php echo $wangzhan['name']?></td>
<td align="center" style="background:<?php echo $wangzhan['bjs']?>;" ><?php echo $wangzhan['bjs']?></td>
<td class="tpt-rap">
<a href="###"  class="layui-btn layui-btn-normal layui-btn-mini publish_btn" data-id="<?php echo $wangzhan['id']?>" data-toggle="modal" data-target="#myPublic"  data-name="<?php echo $wangzhan['name']?>"   data-bjs="<?php echo $wangzhan['bjs']?>" >修改</a>
</td>
</tr>
</tbody>
</table>
<fieldset class="layui-elem-field layui-field-title"><legend>推广信息</legend></fieldset>
<div class="layui-row">
<div class="layui-col-md3">&nbsp;
<a class="layui-btn layui-btn-normal layui-btn-sm pub_btn"   data-toggle="modal" data-target="#myPublic2"><i class="fa fa-plus"></i>  添加推广</a>
<a class="layui-btn layui-btn-normal layui-btn-sm" onClick="dr()"><i class="fa fa-retweet"></i> 一键导入链接</a>
</div>
</div>
<table class="layui-table layui-form" id="data-row">
<thead>
<tr>
<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;" >推广链接</th>
<th  style="text-align:center;" >广告词</th>
<th style="text-align:center;width:104px;" >操作</th>
</tr>
</thead>
<tbody>
<?php 
$page_size=20; 
$sql = "WHERE 1=1";
$sql .=" and userid='$userid' ";
$result = mysql_query("select id from  tlink   ".$sql."");
$count = mysql_num_rows($result);
if($count == 0){echo '<tr><td colspan="7" 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); 
$sgg = mysql_query("select * from  tlink  ".$sql."  order by id desc     limit $offset, $page_size");
while ($dgg=mysql_fetch_array($sgg)) { 
?> 
<tr>
<td style="text-align:center;" ><?php echo $dgg['id']?></td>
<?php if($pic==1){?><td style="text-align: center;"><img style="width: 120px; height: 80px; cursor: -webkit-zoom-in;" src="<?php echo $dgg[pic]?>"  onerror="this.src = '/2019newui/images/nopic.jpg'" ></td><?php }?>
<td style="text-align:center;" ><input type="text" value="<?php echo $dgg['link']?>" name="link" id="link<?php echo $dgg['id']?>" class="layui-input"></td>
<td style="text-align:center;" ><input type="text" value="<?php echo $dgg['name']?>" name="name" id="name<?php echo $dgg['id']?>"  class="layui-input"></td>
<td class="tpt-rap">
<a  onClick="xg('<?php echo $dgg['id']?>')"   class="layui-btn layui-btn-normal layui-btn-mini publish_btn">修改</a>
<a  onClick="sc2('<?php echo $dgg['id']?>')"  class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
</td>
</tr>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
$keyt.="<a href=\""."/wzpage/1/\">首页</a>"; //首页 
$keyt.="<a href=\""."/wzpage/".($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=\""."/wzpage/".$i."/\">".$i."</a>"; 
} 
} 
if($page!=$pages){ 
$keyt.="<a href=\""."/wzpage/".($page+1)."/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/wzpage/{$pages}/\">尾页</a> "; //最后一页 
}else { 
$keyt.="<p>下一页 </p>";//下一页 
$keyt.="<p>尾页</p>"; //最后一页 
} 
$keyt.="<p class='pageRemark' >当前第 <b> $page </b> 页/共 <b> $pages </b> 页  共 <b>$count</b> 条数据 </p>"; //第几页,共几页 
?>
</table>
<br>
<?php if($count =="0"){?><?php }else{?><div style="padding:0 20px;"><div class="pagination"><?php echo $keyt?></div></div><?php }?>  
</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 type="text/javascript">
function dr() {
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
var biaoshi = '<?php echo $wangzhan['biaoshi']?>';
$.ajax({
type : "post",
url : "/wztj<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {cz: 'dr', biaoshi:biaoshi},
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 sc(id) {
layer.confirm("确定要删除吗？", { title: "确认" }, function (index) {
layer.close(index);
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/wztj<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id: id, cz : 'shanchu'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('删除成功');
location.reload();
} 
},
error:function(){
}
});
});
}
function sc2(id) {
layer.confirm("确定要删除吗？", { title: "确认" }, function (index) {
layer.close(index);
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/wztj<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id: id, cz : 'shanchu2'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('删除成功');
location.reload();
} 
},
error:function(){
}
});
});
}
function xg(id) {
var link = $("#link"+id+"").val();
var name = $("#name"+id+"").val();
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/wztj<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id:id,link:link,name:name,cz :'xg'},
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(){
}
});
}
$(function () {
$("#publish_btn").click(function () {
var id = $("#recipient-id").val();
var name = $("#recipient-name").val();
var bjs = $("#bjs").val();
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/wztj<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {id:id,name:name,bjs:bjs,cz:'bj'},
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'));
$('#bjs').val($(this).data('bjs'));
document.getElementById("bjs").style.backgroundColor =$(this).data('bjs');
})
//发布推广代码
$('.pub_btn').on('click', function () {
})
$(function () {
$("#pub_btn").click(function () {
var biaoshi ='<?php echo $wangzhan['biaoshi']?>';
var link = $("#link").val();
var name = $("#name").val();
var pic = $("#pic").val();
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/wztj<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {link:link,name:name,biaoshi:biaoshi,cz :'fb',pic:pic},
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>
<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">
<label  class="control-label">背景颜色</label>
<input class="layui-input color" placeholder="背景颜色"  type="text" value="" name="bjs" id="bjs"  />
</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>
<div class="modal fade" id="myPublic2" 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 layui-form ">
<div class="form-group">
<label  class="control-label">推广链接</label>
<input type="text"  class="layui-input" id="link" placeholder="输入推广链接" >
</div>
<div class="form-group">
<label  class="control-label">广告词</label>
<input class="layui-input" placeholder="输入广告词" type="text" value=""  id="name" />
</div>
<div class="form-group">
<label  class="control-label">展示图片</label>
<input class="layui-input" placeholder="展示图片"  type="text" value=""  id="pic"  />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" id="pub_btn" class="btn btn-primary">确认</button>
</div>
</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
,laydate = layui.laydate
,$ = layui.jquery;
});
<?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>
<?php }else{?>
<form class="layui-form layui-form-pane" name="FormInfo" id="FormInfo">
<input type="hidden" name="cz" id="cz" value="wzfb">
<div class="layui-form-item">
<input type="text" name="name"  class="layui-input"  placeholder="输入站点名称" >
</div>
<div class="layui-form-item">
<input class="layui-input color" placeholder="背景颜色"  type="text" value="838B8B"  name="bjs"/>
</div>
<div class="layui-form-item">
<button class="layui-btn" lay-submit lay-filter="FormInfo" style="width:100%;">添加网站</button>
</div>
</div>
</div>
</form>   
<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('submit(FormInfo)', function (data) {
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type:'POST',
url : "/wztj<?php echo $dshz?>",
data:$("#FormInfo").serialize(),
dataType:'json',
success:function(result){
if(result.zt == '1'){
layer.closeAll('loading');
layer.open({
type: 1
,offset: 'auto'
,id: 'layerMsg'
,content: '<div style="padding: 20px 100px;">添加成功</div>'
,btn: '确定'
,btnAlign: 'c'
,shade: 0
,closeBtn: 0
,yes: function(index){
location.reload();
}
});
}else{
layer.closeAll('loading');
layer.msg(result.msg);
}
}	
});
return false;
});
});
<?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>
<?php }?>
</body>
</html>