{include "header.inc.html"}
{$adLang = $lang.admin.ad.form}
<div class="content_box mw1100">
	<div class="toolbar_box">
		<div class="toolbar"> <span> <strong>{$lang.admin.ad.name}</strong><br />
		<span class="english">{$lang.admin.ad.name_en}</span> </span> </div>
	</div>
<div class="tool">
{if $smarty.get.act=="list" || $smarty.get.act==""}<a id="deleteChecked" class="ui-btn">删除所选</a>{/if}
	</div>
{include 'image.inc.html'}
<div class="adForm">
<form class="form" action="" method="post" id="adForm"><input type="hidden" name="inajax" value="1" />
 {if $smarty.get.act=="edit" || $smarty.get.act=="add"}
<input type="hidden" name="act" value="{$smarty.get.act}" />
{if $smarty.get.act=="edit"}
<input type="hidden" name="id" value="{$smarty.get.id}" />
{/if}
<div class="form-line">
<label class="label">{$adLang.adPlace}：</label><div class="element"><select name="placeId">
	{adplace limit="false" order="id asc"}
	<option value="{$item.id}"{if $adInfo.placeId==$item.id} selected{/if}>{$item.name}</option>
	{/adplace}
</select></div>
</div>
<div class="form-line">
<label class="label">{$adLang.name}：</label><div class="element"><input type="text" class="text w200" name="name" value="{$adInfo.name}" /></div>
</div>
<div class="form-line">
<label class="label">{$adLang.url}：</label><div class="element"><input type="text" class="text w200" name="link" value="{$adInfo.link}" /></div>
</div>
<div class="form-line"><label class="label">{$lang.form.sort}：</label><div class="element"><input type="text" class="text w200" name="sortId" value="{$adInfo.sortId|default:50}" /></div></div>
<div class="form-line"><label class="label">绑定商品分类：</label><div class="element"><input type="text" class="text w200" name="goodsCatId" value="{$adInfo.goodsCatId}" /></div></div>
<div class="form-line">
<label class="label">{$lang.form.iStatus}：</label><div class="element"><input type="checkbox" name="iStatus" value="1"{if $adInfo.iStatus==1 || $smarty.get.act=='add'} checked{/if}/></div>
</div>
<div class="form-line">
<label class="label">{$adLang.image}：</label><div class="element"><input type="hidden" name="thumbId" id="id_pic_url" value="{$adInfo.thumbId}" />
<script>document.write(generatePicAreaHTML('pic_url',-1, '广告图片','image',true, true));</script>
{if $adInfo.thumbId}
{attachment id=$adInfo.thumbId limit=1}
<script type="text/javascript">UPLOAD_IMG_NAME_VALUE='pic_url';showUploadImgResult({ "state":"SUCCESS","url":"{$item.url}","id":{$item.id} });</script>
{/attachment}
{/if}

</div>
</div>

<div class="form-line">
<label class="label"></label><div class="element"><input class="btn_sub" type="submit" value="{$lang.form.submit}"></div>
</div>
</form>
</div>
 {else}
 <table class="table-ca table_1" id="tInfo">
 <tr>
<th class="w30"><input type="checkbox" value="1" name="allid" id="checkall" /></th><th class="w30">{$lang.form.id}</th><th>{$adLang.name}</th><th class="w200">{$adLang.url}</th><th class="w200">{$adLang.image}</th><th class="w90">绑定商品分类</th><th class="w60">{$lang.form.iStatus}</th><th class="w180">{$adLang.adPlace}</th><th class="w30">{$lang.form.sort}</th><th class="w70">{$lang.form.posttime}</th><th class="w60">{$lang.form.operate}</th>
 </tr>
{ad limit="15"}
<tr sid="{$item.id}">
<td><input type="checkbox" name="id[]" value="{$item.id}" /></td><td>{$item.id}</td><td title="{$item.name}"><div class="nowrap w140">{$item.name}</div></td><td><div class="w190 nowrap"><a href="{$item.link}" target="_blank">{$item.link}</a></div></td><td><div class="nowrap w150"><a href="{$item.thumbnail.url}" target="_blank">{$item.thumbnail.url}</a></div></td><td>{$item.goodsCatId} {$item.goodsCatName}</td><td><img class="smodtoggle" name="iStatus" sid="{$item.id}" src="{$baseUrl}admin/images/{if $item.iStatus==1}yes{else}no{/if}.gif"></td><td>{$item.placeName}</td><td>{$item.sortId}</td><td><div class="nowrap">{$item.posttime|date_format:"Y-m-d"}</div></td><td><a href="{$adminUrl}ad/act/edit/id/{$item.id}" class="modBtn">{$lang.edit}</a> <a href="javascript:void(0)" class="delBtn" title="{$lang.del}" sid="{$item.id}">{$lang.del}</a></td>
</tr>
{/ad}
</table>
<div class="page">
	<div class="pagin fr">{pager allCount=$allCount url='/qkadmin/ad/page/' number="false"}</div>
</div>

{/if}
{if $smarty.get.act=="edit" || $smarty.get.act=="add"}
<script type="text/javascript">
$(function(){
	$('#adForm').validate({
		rules:{ name:{ required:true } },
		messages:{ name:{ required:'广告名称不能为空'  } },
		submitHandler:function(){
			$("#thumbId").val($("#id_pic_url").val());
			$("#adForm").ajaxSubmit({ dataType:'json',success:function(json){ qlib.tips({ icon:'success',msg:json.message}); if($("#adForm input[name='act']").val()=='add'){ $("#adForm input[type='text']").val("");$("#adForm textarea").val("");DELETE_IMG_NAME_VALUE='pic_url';deleteShopImageCallback(); } },error:function(){ alert('ajax处理失败'); } });
		}
	});
});
</script>
{else}
<script type="text/javascript">
$(function(){
	$("a#deleteChecked").button().click(function(){
		if(!confirm(lang[4])){ return false; }		
		var id = [];
		$("input[name='id[]']:checkbox:checked").each(function(index){
			id[index] = $(this).val();
			var sid = $(this).val();
			if(sid){
				var tr = $(this).parent("td").parent("tr");
				var sdata = "inajax=1&act=del&id="+sid;
				$.ajax({
					type:"POST",
					url:"{$adminUrl}ad",
					data:sdata,
					dataType:"json",
					success:function(data){
						if(data.success){
							tr.fadeOut("slow").remove();
						}else{
							alert(data.message);
						}
					}
				});			
			}
		});
	});
	$(".delBtn").click(function(){
		if(!confirm(lang[4])){ return false; }
		var id = $(this).attr("sid");
		if(id!=''){
			var tr = $(this).parent("td").parent("tr");
			$.ajax({
				type:"POST",
				url:"{$adminUrl}ad",
				data:"inajax=1&act=del&id="+id,
				dataType:'json',
				success:function(json){
					if(json.success){
						tr.remove();
					}else{
						qlib.tips(json.message);
					}
				}
			});
		}
	})
})
</script>

{/if}
</div><!--.content_box-->
{include "footer.inc.html"}