{include "header.inc.html"}
{$linksLang = $lang.admin.links.form}
<div class="content_box">
	<div class="toolbar_box">
		<div class="toolbar"> <span> <strong>{$lang.admin.links.name}</strong><br />
		<span class="english">{$lang.admin.links.name_en}</span> </span>
				<div class="toolbar_menu">
			<a href="{$adminUrl}links">友情链接管理</a>
			<a href="{$adminUrl}links/act/add">添加友情链接</a>
			<a href="{$adminUrl}linkscat">友情链接分类管理</a>
			<a href="{$adminUrl}linkscat/act/add">添加友情链接分类</a>
		</div>
	</div>
	</div>
<div class="tool">
{if $smarty.get.act=="list" || $smarty.get.act==""}
<a id="deleteChecked">删除所选</a>
{/if}
</div>

{if $smarty.get.act=="edit" || $smarty.get.act=="add"}
<div class="linksForm">
<form class="form" action="" method="post">
<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">链接分类：</label><div class="element">
<select name="catId">{linkscat}<option value="{$item.id}"{if $linksInfo.catId==$item.id} selected{/if}>{$item.name}</option>{/linkscat}</select>
</div></div>
<div class="form-line"><label class="label">{$linksLang.name}：</label><div class="element"><input type="text" class="text w300" name="name" value="{$linksInfo.name}" /></div></div>
<div class="form-line"><label class="label">{$linksLang.title}：</label><div class="element"><input type="text" class="text w300" name="title" value="{$linksInfo.title}" /></div></div>
<div class="form-line"><label class="label">{$linksLang.url}：</label><div class="element"><input type="text" class="text w300" name="url" value="{$linksInfo.url}" /></div></div>
<div class="form-line"><label class="label">{$lang.form.iStatus}：</label><div class="element"><input type="checkbox" class="" name="iStatus" id="iStatus" value="1"{if $linksInfo.iStatus==1 || not isset($linksInfo)} checked{/if} /><label for="iStatus">有效</label></div></div>
<div class="form-line"><label class="label">{$lang.form.sort}：</label><div class="element"><input type="text" class="text w300" name="sortId" value="{$linksInfo.sortId}{if $smarty.get.act=='add'}50{/if}" /></div></div>
<div class="form-line">
<label class="label">图标：</label><div class="element"><input type="hidden" name="thumbId" id="thumbId" value="{$linksInfo.thumbId}" />
{if  $linksInfo.thumbId}
{attachment id=$linksInfo.thumbId limit=1}
<img id="img-thumb" src="{$item.url}" />
{/attachment}
{else}
<img id="img-thumb" src="/static/images/default.png" />
{/if}<br><span id="uploadBtn"></span>
</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>

{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="w60">编号</th><th class="w100">分类</th><th class="w150">链接名</th><th class="w150">链接描述</th><th class="w100">链接地址</th><th class="w50">排序</th><th class="w60">用户</th><th class="w30">状态</th><th class="w120">提交时间</th><th class="w60">{$lang.form.operate}</th>
</tr>
{links limit=15}
<tr>
<td><input type="checkbox" name="id[]" value="{$item.id}" /></td><td>{$item.id}</td><td>{$item.catInfo.name} {$item.catId}</td><td>{$item.name}</td><td>{$item.title}</td><td>{$item.url}</td><td>{$item.sortId}</td><td>{$item.userId}</td><td><img src="{$baseUrl}static/images/{if $item.iStatus==1}yes{else}no{/if}.gif" class="smodtoggle" sid="{$item.id}" name="iStatus" /></td><td>{$item.posttime|date_format:"Y-m-d H:i:s"}</td><td><a href="{$adminUrl}links/act/edit/id/{$item.id}" class="modBtn">{$lang.edit}</a> <a href="javascript:void(0)" class="delBtn">{$lang.del}</a></td>
</tr>
{/links}
</table>
<div class="page">
	<div class="pagin fr">{pager allCount=$allCount url='/qkadmin/links/page' number="false"}</div>
</div>


<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}links",
					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 tr = $(this).parent("td").parent("tr");
			var id = tr.find("td").eq(1).text();
			if(parseInt(id,10)){
				var sdata = "inajax=1&act=del&id="+id;
				$.ajax({
					type:"POST",
					url:"{$adminUrl}links",
					data:sdata,
					dataType:"json",
					success:function(data){
						if(data.success){
							tr.fadeOut("slow").remove();
						}else{
							alert(data.message);
						}
					}
				});
			}
		return false;
	});
})
</script>

{/if}


{if $smarty.get.act=="edit" || $smarty.get.act=="add"}
<script type="text/javascript" src="/plugins/swfupload/swfupload.js"></script>
<script type="text/javascript">
$(function(){
swfu_settings.button_placeholder_id = "uploadBtn";
swfu = new SWFUpload(swfu_settings);
swfu.uploadSuccess = function(obj,data,resp){
		var data = eval('('+data+')');
		if(data.success){
			var url = decodeURIComponent(data.url);
			swfu.setButtonText("<span class='redText'>上传成功</span>");
			swfu.setButtonDisabled(false);
			$("#img-thumb").attr("src","/"+url);
			$("#thumbId").val(data.id);
		}
}
});
</script>
{/if}

{include "footer.inc.html"}