<?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;}
$type = "order by id DESC limit 0,1";
$mb=queryall(dsmb,$type);
if ($mb[id]==null){
$id="1";
}else{
$id=$mb[id]+1;
}
?>
<!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/houtai.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"></script>
<script src="/layui/layui.js"></script>
<script src="/2019newui/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/2019newui/qiantai/css/bootstrap.min.css">
</head>
<body>
<body style="padding:10px;">
<div class="tplay-body-div">
<?php
$sql = mysql_query("SELECT * FROM dsmb");
$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-field-box"><br></div>-->
<div class="layui-tab layui-tab-brief">
<div class="layui-tab-content">
<div class="layui-form-item">
<div class="layui-inline">
<a class="layui-btn layui-btn-normal addNews_btn pub_btn" data-toggle="modal" data-target="#myPublic2">添加模板</a>
</div>
</div>
<div class="row">
<?php
$query = mysql_query("SELECT * FROM dsmb   order by id desc    ");
while($a = mysql_fetch_array($query)) {
?> 
<div class="col-md-2 text-center">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title"><input type="text" name="ms[]" class="ms layui-input" data-id="<?php echo $a['id']?>" value="<?php echo $a[mbmc]?>"  style=" height: 30px;text-align:center;"></h3>
<div class="actions pull-right">
</div>
</div>
<div class="panel-body" >
<img src="<?php echo $a[pic]?>" style="height:400px;width:100%;"  onerror="this.src = '/2019newui/images/nopic.jpg'" >
</div>
<div class="panel-footer">
<button class="btn<?php if($dsmb==$a[id]){?> btn-danger<?php }else{?> btn-info<?php }?>"   <?php if($dsmb==$a[id]){?><?php }else{?>onclick="hezisz('<?php echo $a[id]?>')"<?php }?>><?php if($dsmb==$a[id]){?>已设为默认<?php }else{?>设为默认<?php }?></button>
<button class="btn<?php if($a[sz]==1){?> btn-success <?php }else{?> btn-danger<?php }?>"  <?php if($a[sz]==1){?>onClick="yc('<?php echo $a[id]?>')"<?php }else{?>onClick="xs('<?php echo $a[id]?>')"<?php }?>><?php if($a[sz]==1){?>点击隐藏<?php }else{?>点击显示<?php }?></button>
<button class="btn btn-success"  onClick="sc('<?php echo $a[id]?>')">删除模板</button>
</div>
</div>
</div>
<?php }?>
</div> 
</div>
<script type="text/javascript">
function sc(id) {
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: id, lx: 'dsmbsc'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading'); 
layer.msg('删除成功');
location.reload();
} 
},
error:function(){
}
});
});
}
function xs(id) {
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: id, lx: 'dsmbszxs'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading'); 
layer.msg('设置成功');
location.reload();
} 
},
error:function(){
}
});
}
function yc(id) {
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: id, lx: 'dsmbszyc'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading'); 
layer.msg('设置成功');
location.reload();
} 
},
error:function(){
}
});
}
</script>
<script type="text/javascript">
$('.pub_btn').on('click', function () {
})
$(function () {
$("#pub_btn").click(function () {
var pd = $("#pd").val();
if (pd == '') {
layer.msg('请先上传模板图片');
return false;
}
var name = $("#name").val();
if (name == '') {
layer.msg('名称不能为空');
return false;
}
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/htpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {name:name, lx: 'dsmbadd',id:'<?php echo $id?>'},
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(){
}
});
});
})
$(document).on('change', '.ms', function(event) {
event.preventDefault();
var id  = $(this).attr('data-id'),
name = $(this).val();
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: id,name :name,lx:'dsmbname'},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('修改成功');
location.reload();
} 
},
error:function(){
}
});
});
</script>
<div class="modal fade layui-form" id="myPublic2" tabindex="-1" role="dialog" aria-labelledby="myPublicLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<input type="hidden" name="pd"  id="pd">
<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">
<div class="form-group">
<button type="button" class="layui-btn layui-btn-danger layui-input" id="userAvatar" style="margin-left:0px;"><i class="layui-icon">&#xE64A;</i>上传模板图片</button>
</div>
<div class="form-group">
<label  class="control-label">模板名称</label>
<input type="text"  class="layui-input" id="name" placeholder="输入模板名称" >
</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>
</div>
</div>
<script>
layui.use(['form', 'layedit', 'laydate', 'element', 'jquery', 'upload'], function(){
var form = layui.form
,layer   = layui.layer
,layedit = layui.layedit
,element = layui.element
,upload  = layui.upload
,$= layui.jquery
,laydate = layui.laydate;
upload.render({
elem: '#userAvatar'
,url: '/dsmbpic<?php echo $dshz?>?id=<?php echo $id?>'
,size: 500
,done: function(res){
if(res.status=='true'){
layer.msg("上传成功");
$("#userAvatar").html('上传成功');
$("#userAvatar").attr("disabled","disabled");
$("#userAvatar").addClass("layui-btn-disabled");
$("#pd").val(res.img);
}
}
});
});
function hezisz(id) {
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$.ajax({
type : "post",
url : "/htpost<?php echo $dshz?>",
dataType: "json",  
async: true,
data: {lx:'dsmbsz',id:id},
timeout: 10000 ,
success : function(data){
if(data.zt=='1'){  
layer.closeAll('loading');
layer.msg('设置成功');
location.reload();
} 
},
error:function(){
}
});
}
</script>
</body>
</html>