<?php defined('APP_NAME') || exit('Access Denied'); 
?><!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="Author" content="QQ:401421567" />
<link rel="stylesheet" href="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>admin/css/bootstrap.min.css" />
<link rel="stylesheet" href="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>admin/css/me.css" />
<script>var admin_static = "<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>" , cookie_pre = "<?php echo(isset($C['cookie_pre']) ? $C['cookie_pre'] : ''); ?>",_vip_key = "<?php echo(isset($vip['_key']) ? $vip['_key'] : ''); ?>",api_url = "<?php echo(isset($vip['api_url']) ? $vip['api_url'] : ''); ?>",_control = "<?php echo(isset($_GET['control']) ? $_GET['control'] : ''); ?>",_action = "<?php echo(isset($_GET['action']) ? $_GET['action'] : ''); ?>",version = '<?php echo(isset($vip['version']) ? $vip['version'] : ''); ?>',release = '<?php echo(isset($vip['release']) ? $vip['release'] : ''); ?>',vip_key = _vip_key;</script>
<script src="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>admin/js/jquery.js"></script>
<script src="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>admin/js/bootstrap.min.js"></script>
<script src="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>js/layer/layer.js"></script>
<script src="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>admin/js/global.js"></script>
<!--[if lt IE 9]>
  <script src="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>admin/js/html5.js"></script>
  <script src="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>admin/js/respond.min.js"></script>
<![endif]-->
<script type="text/javascript">
	var webdir = '<?php echo(isset($pp['webdir']) ? $pp['webdir'] : ''); ?>';
	layer.config({
		extend: 'extend/layer.ext.js',
		shift: -1
	});
	var pKey = "<?php echo(isset($_pkey) ? $_pkey : ''); ?>", urlKey = "<?php echo(isset($_ukey) ? $_ukey : ''); ?>", place = "<?php echo(isset($_place) ? $_place : ''); ?>";
	//全选与全不选
	function selectall(name,obj) {
		if ($(obj).is(':checked')) {
			$("input[name='"+name+"']").each(function() {
				$(this).prop('checked', true);
			});
		} else {
			$("input[name='"+name+"']").each(function() {
				$(this).prop('checked', false);
			});
		}
	}
</script>
<title><?php echo(isset($_title) ? $_title : ''); ?></title>
</head>
<body>
<script src="<?php echo(isset($C['admin_static']) ? $C['admin_static'] : ''); ?>laydate/laydate.js"></script>
<script>
var cidjson = tojson('<?php echo(isset($cidjson) ? $cidjson : ''); ?>') ;
var cid_html = '<div class="mt10"><a href="javascript:;" class="btn btn-default" id="save_cid">保存</a> <a href="javascript:;" onclick="layer.closeAll(\'tips\');" class="btn btn-default">关闭</a></div>';
	cid_html += '<select id="_cid" class="form-control mt10">';
	cid_html += '<option value="0">选择分类</option>';
	$.each(cidjson,function(i,v){
		cid_html += '<option value="'+v.cid+'">'+v.name+'</option>';
	})
	cid_html += '</select>';
var groupjson = tojson('<?php echo(isset($group_arr) ? $group_arr : ''); ?>') ;
var group_html = '';
	group_html += '<select id="_groupid" class="form-control mt10">';
	group_html += '<option value="">请选择</option>';
	group_html += '<option value="0">不限制</option>';
	$.each(groupjson,function(i,v){
		group_html += '<option value="'+v.groupid+'">'+v.groupname+'</option>';
	})
	group_html += '</select>';
</script>
<style>
.laydate-icon{height:auto;}
.laydate_body .laydate_top{height:36px;}
.laydate_body .laydate_bottom{height:32px;}
.form-horizontal .form-group {margin-left: 0px;margin-right: 0px;}
.label-gray{background-color:transparent;color:#999}
a.label-gray:hover{background-color:transparent;color:#666}
</style>
<div class="container-fluid">
	<div class="panel panel-default">
		<div class="panel-heading">
		<div class="row">
			<div class="col-xs-1"><?php echo(isset($cidhtml) ? $cidhtml : ''); ?></div>
			<div class="col-xs-3">
			<form class="search" method="post" action="index.php?u=products-index">
				<div class="input-group">
					<input type="text" name="keyword" value="<?php echo(isset($keyword) ? $keyword : ''); ?>" class="form-control">
					<span class="input-group-btn"><button class="btn btn-default" type="submit">搜索</button></span>
				</div>
			</form>
			</div>
			<div class="col-xs-7">
				<a href="javascript:;" class="btn btn-default" onclick="reload_href('index.php?u=products-index');">全部(<?php echo(isset($total) ? $total : ''); ?>)</a> 
				<a href="javascript:;" class="btn btn-default" onclick="reload_href('index.php?u=products-index-status-1');">草稿</a> 
				<a href="javascript:;" class="btn btn-default" onclick="reload_href('index.php?u=products-index-tuan-3');">限时优惠中</a> 
				<a href="javascript:;" class="btn btn-default" onclick="reload_href('index.php?u=products-index-tuan-1');">限时已结束</a> 
			</div>
			<div class="col-xs-1">
				<a id="add" class="btn btn-info pull-right" href="javascript:;"><span class="glyphicon glyphicon-plus"></span> 增加</a>
			</div>
		</div>
		</div>
		<?php if (empty($cms_products_arr)) { ?>
		<div class="panel-body"><div class="alert alert-warning sky"><i class="glyphicon glyphicon-warning-sign"></i> <b>暂无内容</b></div></div>
		<?php }else{ ?>
		<table class="table table-bordered table-hover small">
			<tr>
				<th rowspan="2" width="25"><input type="checkbox" id="check_all" autocomplete="off"></th>
				<th rowspan="2" class="text-center">ID</th>
				<th rowspan="2" id="buttonDis">名称</th>
				<th rowspan="2" width="180" class="text-center">属性</th>
				<th rowspan="2" width="80" class="text-center">价格</th>
				<th rowspan="2" width="60" class="text-center">销量</th>
				<th colspan="4" class="text-center text-info">限时特价</th>
				<th rowspan="2" width="90" class="text-center">更新时间</th>
				<th rowspan="2" width="50" class="text-center">状态</th>
				<th rowspan="2" width="130" class="text-center">管理</th>
				<th rowspan="2" width="100" class="text-center text-warning">限制下载 <a href="javascript:purviews();"><i class="glyphicon glyphicon-question-sign"></i></a></th>
				<th colspan="2" class="text-center">FAQ</th>
				<th rowspan="2" width="50" class="text-center">百度</th>
			</tr>
			<tr>
				<th width="80" class="text-center">开始时间</th>
				<th width="80" class="text-center">结束时间</th>
				<th width="80" class="text-center">优惠价</th>
				<th class="text-center">操作</th>
				<th width="50" class="text-center">数量</th>
				<th width="60" class="text-center">操作</th>
			</tr>
			<?php if(isset($cms_products_arr) && is_array($cms_products_arr)) { foreach($cms_products_arr as &$v) { ?>
			<tr class="li">
				<td class="text-center"><input type="checkbox" name="chk_row" _id="<?php echo(isset($v['id']) ? $v['id'] : ''); ?>" _cid="<?php echo(isset($v['cid']) ? $v['cid'] : ''); ?>" autocomplete="off"></td>
				<td class="text-center"><a href="javascript:booklist(<?php echo(isset($v['id']) ? $v['id'] : ''); ?>,1);"><?php echo(isset($v['id']) ? $v['id'] : ''); ?></a></td>
				<td><?php echo(isset($v['cate_arr']['name']) ? $v['cate_arr']['name'] : ''); ?> <a href="<?php echo(isset($v['url']) ? $v['url'] : ''); ?>" target="_blank"><?php if ($v['price']==0) { ?><font color="green">[免费]</font> <?php } echo(isset($v['subject']) ? $v['subject'] : ''); ?> <?php echo(isset($v['imgstr']) ? $v['imgstr'] : ''); ?></a></td>
				<td class="text-center"><?php echo(isset($v['flagstr']) ? $v['flagstr'] : ''); ?></td>
				<td class="text-right"><p onclick="_edit.IN(this,<?php echo(isset($v['id']) ? $v['id'] : ''); ?>,'price')" class="mar0"><?php if (!empty($v['old_price'])) { echo(isset($v['old_price']) ? $v['old_price'] : ''); }else{ echo(isset($v['price']) ? $v['price'] : ''); } ?></p></td>
				<td class="text-center"><?php if ($v['sells']) { echo(isset($v['sells']) ? $v['sells'] : ''); }else{ ?>-<?php } ?></td>

				<td class="text-center"><span style="<?php echo(isset($v['timestyle']) ? $v['timestyle'] : ''); ?>"><?php if ($v['zk_start']) { echo(isset($v['zk_start']) ? $v['zk_start'] : ''); } ?></span></td>
				<td class="text-center"><span style="<?php echo(isset($v['timestyle']) ? $v['timestyle'] : ''); ?>"><?php if ($v['zk_end']) { echo(isset($v['zk_end']) ? $v['zk_end'] : ''); } ?></span></td>
				<td class="text-right"><span><?php if ($v['zk_price']>0) { echo(isset($v['zk_price']) ? $v['zk_price'] : ''); }else{ ?>-<?php } ?></span></td>
				<td class="text-center"><?php if ($v['price']>0 && $v['status']==0) { echo(isset($v['tuanadmin']) ? $v['tuanadmin'] : ''); } ?></td>
				<td class="text-center"> <?php  echo date('m-d H:i', $v['lasttime']); ?></td>
				<td class="text-center update_caogao text-red" id="caogao_<?php echo(isset($v['id']) ? $v['id'] : ''); ?>"><?php if ($v['status']==1) { ?>草稿<?php } ?></td>
				<td>
					<a href="javascript:edit(<?php echo(isset($v['id']) ? $v['id'] : ''); ?>, <?php echo(isset($v['cid']) ? $v['cid'] : ''); ?>);">编辑</a>
					<a class="text-danger" href="javascript:del(<?php echo(isset($v['id']) ? $v['id'] : ''); ?>, <?php echo(isset($v['cid']) ? $v['cid'] : ''); ?>);">删除</a>
					<?php if ($v['status']==1) { ?><a href="javascript:setstatus(<?php echo(isset($v['id']) ? $v['id'] : ''); ?>, <?php echo(isset($v['cid']) ? $v['cid'] : ''); ?>, 0,'status','确定？');">审核</a><?php }else{ ?><a class="text-warning" href="javascript:setstatus(<?php echo(isset($v['id']) ? $v['id'] : ''); ?>, <?php echo(isset($v['cid']) ? $v['cid'] : ''); ?>, 1,'status','确定？');">反审</a><?php } ?>
					<?php if ($v['sells']) { ?><a class="but3" href="javascript:sendsms(<?php echo(isset($v['id']) ? $v['id'] : ''); ?>);">通知</a><?php } ?>
				</td>
				<td class="text-center"><a href="javascript:;" onclick="need_groupid($(this));" _id="<?php echo(isset($v['id']) ? $v['id'] : ''); ?>" _cid="<?php echo(isset($v['cid']) ? $v['cid'] : ''); ?>"><?php if (empty($v['need_groupid'])) { ?>不限<?php }else{ echo(isset($v['need_groupname']) ? $v['need_groupname'] : ''); } ?></a></td>
				<td class="text-center">
					<?php if ($v['faqs']) { echo(isset($v['faqs']) ? $v['faqs'] : ''); } ?>
				</td>
				<td class="text-center">
					<a class="but3" href="javascript:faqlist(<?php echo(isset($v['id']) ? $v['id'] : ''); ?>);">管理</a>
				</td>
				<td class="text-center"><?php if (empty($v['baidu'])) { ?><a class="but3" href="javascript:bdts(<?php echo(isset($v['id']) ? $v['id'] : ''); ?>, <?php echo(isset($v['cid']) ? $v['cid'] : ''); ?>,'确定要推送到百度？');">推送</a><?php }else{ ?>√<?php } ?></td>
			</tr>
			<?php }} ?>
		</table>
		<div class="panel-footer text-center"><nav><ul class="pagination"><?php echo(isset($pages) ? $pages : ''); ?></ul></nav></div>
		<?php } ?>
	</div>
</div>
<div id="tuan_dialog" _mid="2" _type="0" _upid="0" style="display:none;">
	<form method="post" action="index.php?u=products-tuan_edit-ajax-1" class="form-horizontal mt10">
		<input type='hidden' name="id">
		<div class="form-group">
			<label class="col-xs-3 control-label">标题</label>
			<div class="col-xs-9"><p class="form-control-static" id="title"></p></div>
		</div>
		<div class="form-group">
			<label class="col-xs-3 control-label">原价</label>
			<div class="col-xs-7"><input class="form-control" id="price" name="price" type="text" disabled="disabled"></div>
		</div>
		<div class="form-group">
			<label class="col-xs-3 control-label">限时特价</label>
			<div class="col-xs-7"><input class="form-control" id="zk_price" name="zk_price" type="text" autocomplete="off" /></div>
		</div>
		<div class="form-group">
			<label class="col-xs-3 control-label">开始时间</label>
			<div class="col-xs-7">
				<div class="input-group">
					<input class="form-control laydate-icon" id="zk_start" name="zk_start" type="text" autocomplete="off" />
					<span class="input-group-addon">00:00:00</span>				
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-3 control-label">截止时间</label>
			<div class="col-xs-7">
				<div class="input-group">
					<input class="form-control laydate-icon" id="zk_end" name="zk_end" type="text" autocomplete="off" />
					<span class="input-group-addon">23:59:59</span>				
				</div>
			</div>
		</div>
	</form>
	<script>
	laydate.skin('molv');
	var start = {
		elem: '#zk_start',
		format: 'YYYY/MM/DD',
		min: laydate.now(), //设定最小日期为当前日期
		max: '2099-06-16', //最大日期
		istime: false,
		istoday: true,
		choose: function(datas){
			 end.min = datas; //开始日选好后，重置结束日的最小日期
			 end.start = datas //将结束日的初始值设定为开始日
		}
	};
	var end = {
		elem: '#zk_end',
		format: 'YYYY/MM/DD',
		min: laydate.now(),
		max: '2099-06-16',
		istime: false,
		istoday: false,
		choose: function(datas){
			start.max = datas; //结束日选好后，重置开始日的最大日期
		}
	};
	laydate(start);
	laydate(end);
	</script>
</div>
<div id="booklist_dialog" style="display:none;"><div id="tuan_out"></div></div>
<script type="text/javascript">
function booklist(pid,page){
	ppajax.postd("index.php?u=book-get_pro-page-"+page, {pid: pid},function(data) {
		if (window.ppEixt) return;
		ppajax.remove();
		load_boolistlog();
		$("#tuan_out").html(data);
	});
}
function load_boolistlog() {
	var H = Math.max(350, document.documentElement.clientHeight - 30) + 'px';
	layer.open({
		type: 1,
		title: ['订单列表', 'font-weight:bold;color:green'],
		area: ['800px', H],
		shadeClose: true,
		scrollbar: false,
		content: $('#booklist_dialog')
	});
}
function bdts(id,cid,err){
	ppajax.confirm(err,function(){
		ppajax.postd("index.php?u=products-baidu-ajax-1", {"id":id,"cid":cid, "baidu":1}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
		});
	});
}
var _edit = {
	IN : function (obj, id ,type) {
		var tag = obj.firstChild.tagName;
		if (typeof(tag) != "undefined" && (tag == "INPUT"))
			return;
		var org = obj.innerHTML;
		var val = window.ActiveXObject ? obj.innerText : obj.textContent;
		var txt = document.createElement("INPUT");
		txt.value = val;
		txt.style.background = "#fff";
		txt.style.width = obj.offsetWidth - 4 + 'px';
		obj.innerHTML = "";
		obj.appendChild(txt);
		txt.focus();
		txt.onblur = function (e) {
			obj.innerHTML = txt.value;
			if(txt.value!=val){
				_edit.QUERY(id,txt.value,type);
			}
			return false;
		}
		return false;
		
	},
	QUERY : function (id,txtvalue,type) {
		ppajax.postd("index.php?u=products-ajaxset-ajax-1", {"id":id, "type":type, "txtvalue":txtvalue}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
		});
	}
}
function sendsms(id) {
	ppajax.confirm('给已订购的会员发送更新通知？<br/>发送时请耐心等候！勿连续发送！', function(){
		ppajax.postd("index.php?u=book-update_sms-ajax-1", {"pid":id}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 3000);
		});
	});
}
function setstatus(id,cid,txtvalue,type,err) {
	ppajax.confirm(err, function(){
		ppajax.postd("index.php?u=products-ajaxset-ajax-1", {"id":id,"cid":cid, "type":type, "txtvalue":txtvalue}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
		});
	});
}
function setflags(id,cid,value,err){
	ppajax.confirm(err, function(){
		ppajax.postd("index.php?u=products-ajaxsetflags-ajax-1", {"id":id,"cid":cid,"value":value}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
		});
	});
}
$("#add").click(function(){
	parent.oneTab("添加资源","products-add");
});
$("#cid").change(function(){
	var index = layer.load(0,{shade:0});
	$.cookie(cookie_pre + '2_cid', $(this).val());
	location.href = "index.php?u=products-index-cid-"+ $(this).val();
});
//全选
$("#check_all").click(function(){
	var bool = $(this)[0].checked;
	var len = $("input[name='chk_row']").length;
	for(var i=0; i<len; i++) {
		$("input[name='chk_row']").eq(i)[0].checked = bool;
	}
	bool ? buttonDis() : $("#batch_del,#batch_cid").remove();
});

//是否显示删除按钮
$("input[name='chk_row']").click(function(){
	var len = $("input[name='chk_row']:checked").length;
	len ? buttonDis() : $("#batch_del,#batch_cid").remove();
});

//显示删除按钮
function buttonDis() {
	if (!$("#batch_del").length) $("#buttonDis").prepend(' <input id="batch_del" onclick="batch_del()" type="button" value="批量删除" class="btn btn-danger btn-xs" /> <input id="batch_cid" onclick="change_cid()" type="button" value="移动分类" class="btn btn-warning btn-xs" />');
}
function reload_href(url) {
	$.cookie(cookie_pre + '2_cid', '');
	location.href = url;
}
function change_cid() {
	var tipsi = layer.tips(cid_html, '#batch_cid',{time:0});
	var id_arr = {};
	var len = $("input[name='chk_row']").length;
	for(var i=0; i<len; i++) {
		var obj = $("input[name='chk_row']").eq(i);
		if(obj[0].checked) {
			id_arr[i] = [obj.attr("_id"), obj.attr("_cid")];
		}
	}
	$('#save_cid').click(function(){
		var cid = $('#_cid').val();
		var cid_name = $("#_cid").find("option:selected").text();
		ppajax.postd("index.php?u=products-batch_cid-ajax-1", {"id_arr":id_arr,"cid":cid}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
		});
	})
}
//编辑
function edit(id, cid) {
	parent.oneTab("编辑资源","products-edit-cid-"+cid+"-id-"+id,"content");
}
function faqlist(id) {
	parent.oneTab("FAQ管理","products-faq-pid-"+id,"content");
}
//删除
function del(id, cid) {
	ppajax.confirm("如果此资源已有订单，会造成数据不完整！<br />删除不可恢复，确定删除？", function(){
		ppajax.postd("index.php?u=products-del-ajax-1", {"id":id, "cid":cid}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
		});
	});
}
//完成
function tuan_over(id, cid,type) {
	if(type==3){
		msg = '将过期的限时特价，重置为普通状态？';
	}
	ppajax.confirm(msg, function(){
		ppajax.postd("index.php?u=products-tuan_over-ajax-1", {"id":id, "cid":cid, "type":type}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
		});
	});
}
//批量删除
function batch_del() {
	ppajax.confirm("如果此资源已有订单，会造成数据不完整！<br />删除不可恢复，确定删除？", function(){
		var id_arr = {};
		var len = $("input[name='chk_row']").length;
		for(var i=0; i<len; i++) {
			var obj = $("input[name='chk_row']").eq(i);
			if(obj[0].checked) {
				id_arr[i] = [obj.attr("_id"), obj.attr("_cid")];
			}
		}
		ppajax.postd("index.php?u=products-batch_del-ajax-1", {"id_arr":id_arr}, function(data){
			ppajax.alert(data);
			if(window.ppdata.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
		});
	});
}
function tuan_edit(id){
	ppajax.postd("index.php?u=products-get_pro_json-ajax-1", {id: id},function(data) {
		data = tojson(data);
		if (window.ppEixt) return;
		ppajax.remove();
		load_tuanlog();
		for (var v in data) {
			$("#tuan_dialog [name='" + v + "']").val([data[v]]);
		}
		$('#title').html(data.title);
	});
}
function purviews() {
	layer.alert("<ol><li>默认不限制，所有用户组可购买下载！</li><li>如指定“银卡会员”，只有“银卡会员”或高于“银卡会员”的用户组才可购买下载！</li><li>已经购买过的用户不受此限制！</li><li>超级用户(全站免费)不受此限制！</li></ol>",{area:500,title:"下载权限设置"});
}
function load_tuanlog() {
	layer.open({
		type: 1,
		title: ['限时优惠', 'font-weight:bold;color:green'],
		area: ['600px', '400px'],
		shadeClose: true,
		scrollbar: false,
		btn: ['确认保存', '取消'],
		yes: function(index, layero){
			$("#tuan_dialog form").submit();
		},cancel: function(index){
		},
		content: $('#tuan_dialog')
	});
	ppajax.submit("#tuan_dialog form",	function(data){
		ppajax.alert(data);
		if (window.ppdata.err == 0) {
			setTimeout(function(){ window.location.reload(); }, 1000);
		}
	});
}
</script>
</body>
</html>