<!--#include file="admin_conn.asp"-->
<%
chkLogin
dim action : action = be("get","action")

Select case action
	case "add","edit" : headAdmin "广告管理": info
	case "save" : save
	case "del" : del
	case "tj" : headAdmin "统计代码管理" : tj
	case "tjsave" : tjsave
	case else : headAdmin "广告管理" : main
End Select
dispseObj()

sub save()
	Dim file : file = be("post","file")
	Dim filecontent : filecontent = be("post","filecontent")
	objFile.createFile "../template/" & app_templatedir & "/ads/" & file&".js",filecontent
	writeA "保存完毕"
end sub

sub del()
	Dim file : file = be("get","file")
	objFile.DelFile "../template/" & app_templatedir & "/ads/" & file
    redirect getReferer()
end sub

sub tjsave()
	Dim tjstr : tjstr = be("post","tjstr")
	objFile.createFile "../js/tj.js",tjstr
	writeA "保存完毕"
end sub

sub main()
	dim fpath,files,filesarr,filearr,i
	fpath = "template/" & app_templatedir & "/ads/"
	if not objfile.isFolderExists("../"& fpath) then
		objfile.createPath("../"& fpath)
	end if
	files = objfile.fileItem("../"& fpath)
	filesarr = split(files,"||")
%>
<script type="text/javascript" src="../js/function.js"></script>
<script language="javascript">
$(document).ready(function(){
	$("#btnAdd").click(function(){
		location.href= "?action=add";
	});
});
</script>
<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1">
	<tr>
	<td>
		<h3>当前广告文件存放路径：<%writeA app_installdir & fpath%></h3>
	</td>
	</tr>
</table>
<table class="tb">
	<tr>
	<td width="15%">广告名称</td>
	<td width="10%">文件大小</td>
	<td width="15%">修改时间</td>
	<td>广告调用代码</td>
	<td width="15%">操作</td>
	</tr>
	<%
	if isN(files) then
	%>
    <tr><td align="center" colspan="5">没有任何记录!</td></tr>
	<%
	else
		for i=0 to ubound(filesarr)
			if not isN(filesarr(i)) then
			filearr = split(filesarr(i),"|")
	%>
    <tr>
      <td><%=filearr(0)%></td>
      <td><%=filearr(1)%>KB</td>
      <td><%=getColorDay(filearr(2))%></td>
      <td>
	  <input id="text<%=filearr(0)%>" name="text<%=filearr(0)%>" type="text" value='<script src="{maccms:templatepath}ads/<%=filearr(0)%>"></script>' size="70"> 
	  <input class="input" type="button" value="复制" name=Submit onClick='copyData(document.getElementById("text<%=filearr(0)%>").value);'>
	  </td>
      <td><A href="admin_ads.asp?action=edit&file=<%=filearr(0)%>">修改</a> | <A href="admin_ads.asp?action=del&file=<%=filearr(0)%>" onClick="return confirm('确定要删除吗?');">删除</a></td>
    </tr>
	<%
			end if
		next
	end if
	%>
	<tr>
	<td colspan="5"><input type="button" id="btnAdd" value="添加"  class="input"/></td>
	</tr>
</table>
<%
end sub

sub info()
	if action="edit" then
		dim file : file = be("get","file")
		dim filepath : filepath = "../template/" & app_templatedir & "/ads/"
		if not objfile.isFileExists(filepath & file) then msg "找不到该广告文件","admin_ads.asp"
		file = replace(file,".js","")
	end if
%>
<script language="javascript">
$(document).ready(function(){
	$("#form1").validate({
		rules:{
			file:{
				required:true,
				maxlength:64
			}
		}
	});
	$('#form1').form({
		onSubmit:function(){
			if(!$("#form1").valid()) {return false;}
		},
	    success:function(data){
	        $.messager.alert('系统提示', data, 'info',function(){
	        });
	    }
	});
	$("#btnCancel").click(function(){
		location.href= "?action=main";
	});
});
</script>
<form action="?action=save" method="post" name="form1" id="form1">
<table class="tb">
	<input type="hidden" id="flag" name="flag" value="<%=action%>">
	<tr>
	<td width="20%" >广告文件名：</td>
	<td><input id="file" size=50 value="<%=file%>" name="file" <%if action="edit" then%>readonly="readonly"<%end if%>>.js
	&nbsp;&nbsp;&nbsp;广告内容需要html转js操作，否则无法正常显示。
	</td>
	</tr>
	<tr>
	<td>广告内容：</td>
	<td><textarea id="filecontent" name="filecontent" style="width:90%;" rows="15"><%if action="edit" then writea objFile.getFile(filepath & file&".js") end if%></textarea></td>
	</tr>
	<tr>
	<td colspan="2" align="center"><input class="input" type="submit" value="保存" id="btnSave"> <input class="input" type="button" value="返回" id="btnCancel"></td>
	</tr>
</table>
</form>
<%
end sub

sub tj
%>
<script language="javascript">
$(document).ready(function(){
	$('#form1').form({
		onSubmit:function(){
			if(!$("#form1").valid()) {return false;}
		},
	    success:function(data){
	        $.messager.alert('系统提示', data, 'info',function(){
	        });
	    }
	});
});
</script>
<form action="?action=tjsave" method="post" name="form1" id="form1">
<table class="tb">
	<tr>
	<td width="20%">统计代码内容：</td>
	<td>
	<textarea id="tjstr" name="tjstr" style="width:100%;" rows="15" ><%=objFile.getFile("../js/tj.js")%></textarea>
	</td>
	</tr>
	<tr>
	<td>实例cnzz统计：</td>
	<td>
	<textarea id="text" name="text" style="width:100%;" rows="3"> document.writeln('<script src="http://s94.cnzz.com/stat.php?id=420039&web_id=420039" language="JavaScript"></script>'); </textarea>
	</td>
	</tr>
	<tr>
	<td>调用方法：</td>
	<td>
	将以下的代码，插入模板即可。<br>
	<xmp><script src="{maccms:path}js/tj.js"></script> 或者 {maccms:visits}  </xmp>
	</td>
	</tr>
	<tr align="center">
	<td colspan="2"><input class="input" type="submit" value="保存" id="btnSave"></td>
	</tr>
</table>
</form>
<%
end sub
%>
</body>
</html>