<!--#include file="sdcms_check.asp"-->
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
sdcms.Check_lever 15
set sdcms=nothing
select case action
case "add":title="添加标签"
case "edit":title="修改标签"
case else:title="标签管理"
end select
sd_table="sd_label"
sdcms_head
%>

<div class="sdcms_notice"><span>管理操作：</span><a href="?action=add">添加标签</a>　┊　<a href="?">标签管理</a></div>
<br>
<ul id="sdcms_sub_title">
	<li class="sub"><%=title%></li> 
</ul>
<div id="sdcms_right_b">
<%
select case action
case "add":add
case "edit":edit
case "save":save
case "del":del
case else:main
end select
closedb
sub main
%>
  <table border="0" align="center" cellpadding="3" cellspacing="1" class="table_b">
    <form name="add" action="?" method="post"  onSubmit="return confirm('确定要执行选定的操作吗？');">
	<tr>
	  <td class="title_bg">选择</td>
      <td class="title_bg">I　D</td>
      <td class="title_bg" width="300">标签</td>
      <td class="title_bg">类别</td>
      <td class="title_bg">日期</td>
      <td class="title_bg">管理</td>
    </tr>
	<%
	page=request.querystring("page")
	if page="" or not isnumeric(page) then
	page=1
	end if
	pages = 20
	set rs=server.CreateObject("adodb.recordset")
	sql="select id,title,"
	if Is_sql=0 then
	sql=sql&"(iif(classid=0,'静态标签','动态标签'))"
	else
	sql=sql&"(case classid when 0 then'静态标签'else'动态标签'end)"
	end if
	sql=sql&",adddate from "&sd_table&" order by id desc"
	rs.open sql,conn,1,1	
	if rs.eof then
	else
	rs.pagesize = pages
	maxpagecount=rs.pagecount
	rs.absolutepage = page 
	rcount1=0
	pagestart=page-5
	pageend=page+5
	if pagestart<1 then
	pagestart=1
	end if
	if pageend>maxpagecount then
	pageend=maxpagecount
	end if
	rcount=rs.RecordCount
	do while not rs.eof and rcount1 <rs.pagesize  
	%>
    <tr onmouseover=this.bgColor='#EBFFDC'; onmouseout=this.bgColor='#ffffff';  bgcolor='#ffffff'>
	 <td align="center"><input name="id"  type="checkbox" onClick="unselectall()"   value="<%=rs(0)%>"></td>
	 <%for i=0 to 3%>
      <td <%if i<>1 then%>align="center"<%end if%>><%if i=1 then echo "{sdcms_" end if%><%=rs(i)%><%if i=1 then echo "}" end if%></td>
      <%next%>
      <td align="center"><a href="?action=edit&id=<%=rs(0)%>">编辑</a> <a href="?action=del&id=<%=rs(0)%>" onclick='return confirm("真的要删除?不可恢复!");'>删除</a></td>
    </tr>
	<%
	rs.movenext
	rcount1=rcount1+1
	loop
	end if         
	%>
	<tr>
      <td colspan="6" class="tdbg" >
	  <span class="right">转到第
		 <select onChange="location.href='?page='+this.value+''">
		 <%for i=1 to maxpagecount%>
		 <option value="<%=i%>" <%if clng(page)=clng(i) then echo "selected" end if%>><%=i%></option>
		 <%next%>
		 </select>页</span>　<input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox"> 全选 
              <select name="action">
			  <option>→操作</option>
			  <option value="del">删除</option>
			  </select> 
             
      <input type="submit" class="bnt01" value="执行">

</td>
    </tr>
	<%if rcount>0 then%>
	<tr>
      <td colspan="6" class="tdbg" align="center"><%
if page<>"1" then
echo "<a href=?page="&page-1&">上一页</a> "
else
echo "上一页 "
end if
for i=pagestart to pageend
if i=0 then 
i=1
end if
if i=clng(page) then
str="<font color=red><b>"&i&"</b></font>"
else
str=i
end if
strurl="[<a href=?page="&i&">"&str&"</a>]"
echo strurl
next
if page=maxpagecount then
echo " 下一页"
elseif  page<>""&maxpagecount&"" then
echo " <a href=?page="&page+1&"&stype="&stype&"&classid="&classid&">下一页</a>"
else
echo " 下一页"
end if
echo " 页次:"&page&"/"&maxpagecount&" 页   每页: "&pages&" 条  总数: "&rcount&" 条"
%></td>
	  </tr>
	  <%end if%>
	</form>
  </table>

<%
end sub
sub add
check_info
%>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" method="post" action="?action=save&act=add" onSubmit='return checkadd()'>
    <tr>
      <td width="12%" align="center" class="tdbg">标签名称：      </td>
      <td class="tdbg">{sdcms_
        <input name="t0" type="text" class="input" id="t0" size="20">}
        <span>标签名称均以{sdcms_开头,不可重复，不可更改</span></td>
    </tr>
    <tr class="tdbg">
      <td align="center">标签类型：</td>
      <td><input name='t1' type='radio' onClick=$('flag').style.display='none';$('flag1').style.display='none';$('flag2').style.display='none';$('flag3').style.display='none';this.form.t2.disabled=true;$('sdcms').style.display='none';$('label').innerHTML='标签';  checked value='0' >静态 <input name='t1' type='radio' onClick=$('flag').style.display='block';$('flag1').style.display='block';$('flag2').style.display='block';$('flag3').style.display='block';this.form.t2.disabled=false;$('sdcms').style.display='block';$('label').innerHTML='循环'; value='1' >动态</td>
    </tr>
    
    <tr class="tdbg dis" id='flag'>
      <td align="center">SQL语句：</td>
      <td><input name="t2" type="text" disabled="disabled" class="input" id="t2" size="100"><span><br>不得包含Delete、Update、Insert、Create等语句</span></td>
    </tr>
	<tr class="tdbg dis" id='flag1'>
      <td align="center">开始部分：</td>
      <td><textarea name="t3" rows="2" class="inputs" id="t3"></textarea></td>
    </tr>
	
   <tr class="tdbg" id="c">
      <td align="center"><a id="label">标签</a>内容：</td>
      <td><textarea name="t5" rows="6" class="inputs" id="t5"></textarea>
        <span id="sdcms" class="dis">动态标签只支持sd_info表,字段对应标签：<br>编号 → {id}　作者 → {author}　文字标题 → {title} 　图片标题 → {pic}　日期 → {date}　人气 → {hits}　简介 → {jj}　连接地址 → {link}　类别 → {classid}　评论数量 → {comment}　标签 → {tags}</span></td>
   </tr>
	<tr class="tdbg dis" id='flag3'>
	  <td align="center">选项设置：</td>
	  <td class="tdbg">标题长度：
	    <input name="t6" type="text" class="input" id="t6"  size="5" maxlength="3" />
	    简介长度：
        <input name="t7" type="text" class="input" id="t7"  size="5" maxlength="3" /> 
        时间显示格式：
        <select id="t8" name="t8">
		<option value="0" SELECTED>YYYY-M-D H:M:S(长格式)</option>
		<option value="1">YY-M-D</option>
		<option value="2">M-D</option>
	    </select><span>以上设置只有在标签调用的情况下才生效</span>
        </td>
	</tr>
	<tr class="tdbg dis" id='flag2'>
      <td align="center">结束部分：</td>
      <td><textarea name="t4" rows="2" class="inputs" id="t4"></textarea></td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="添 加">
        <input name="Submit2" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%

end sub
sub edit
set rs=conn.execute("select id,title,classid,sdcms_sql,sdcms_begin,sdcms_over,sdcms_content,sdcms_title,sdcms_jj,sdcms_date from "&sd_table&" where id="&id&"")
if rs.eof then
echo "请勿非法提交参数":Died
end if
check_info
set sdcms_f=new sdcms_function
%>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" method="post" action="?action=save&act=save&id=<%=id%>" onSubmit='return checkadd()'>
    <tr>
      <td width="12%" align="center" class="tdbg">标签名称：      </td>
      <td>{sdcms_<%=rs(1)%>}</td>
    </tr>
    <tr class="tdbg">
      <td align="center">标签类型：</td>
      <td><input name='t1' type='radio' onClick=$('flag').style.display='none';$('flag1').style.display='none';$('flag2').style.display='none';$('flag3').style.display='none';this.form.t2.disabled=true;$('sdcms').style.display='none';$('label').innerHTML='标签';  <%=w_check(rs(2),0)%> value='0' >静态 <input name='t1' type='radio' onClick=$('flag').style.display='block';$('flag1').style.display='block';$('flag2').style.display='block';$('flag3').style.display='block';this.form.t2.disabled=false;$('sdcms').style.display='block';$('label').innerHTML='循环'; value='1' <%=w_check(rs(2),1)%>>动态</td>
    </tr>
    <tr class="tdbg <%if rs(2)=0 then%>dis<%end if%>" id='flag'>
      <td align="center">SQL语句：</td>
      <td><input name="t2" value="<%=rs(3)%>" type="text" <%if rs(2)=0 then%>disabled="disabled"<%end if%> class="input" id="t2" size="100"><span><br>不得包含Delete、Update、Insert、Create等语句</span></td>
    </tr>
	<tr class="tdbg <%if rs(2)=0 then%>dis<%end if%>" id='flag1'>
      <td align="center">开始部分：</td>
      <td><textarea name="t3" rows="3" class="inputs" id="t3"><%=sdcms_f.TempEncode(rs(4))%></textarea></td>
    </tr>
	
   <tr class="tdbg" id="c">
      <td align="center"><a id="label"><%if rs(2)=0 then%>标签<%else%>循环<%end if%></a>内容：</td>
      <td><textarea name="t5" rows="6" class="inputs" id="t5"><%=sdcms_f.TempEncode(rs(6))%></textarea>
        <span id="sdcms" class="<%if rs(2)=0 then%>dis<%end if%>">动态标签只支持sd_info表,字段对应标签：<br>编号 → {id}　作者 → {author}　文字标题 → {title} 　图片标题 → {pic}　日期 → {date}　人气 → {hits}　简介 → {jj}　连接地址 → {link}　类别 → {classid}　评论数量 → {comment}　标签 → {tags}</span></td>
   </tr>
   <tr class="tdbg <%if rs(2)=0 then%>dis<%end if%>" id='flag3'>
	  <td align="center">选项设置：</td>
	  <td class="tdbg">标题长度：
	    <input name="t6" value="<%=rs(7)%>" type="text" class="input" id="t6"  size="5" maxlength="3" />
	    简介长度：
        <input name="t7" value="<%=rs(8)%>" type="text" class="input" id="t7"  size="5" maxlength="3" /> 
        时间显示格式：
        <select id="t8" name="t8">
		<option value="0" <%=w_select(rs(9),0)%>>YYYY-M-D H:M:S(长格式)</option>
		<option value="1" <%=w_select(rs(9),1)%>>YY-M-D</option>
		<option value="2" <%=w_select(rs(9),2)%>>M-D</option>
	    </select><span>以上设置只有在标签调用的情况下才生效</span>
        </td>
	</tr>
	<tr class="tdbg <%if rs(2)=0 then%>dis<%end if%>" id='flag2'>
      <td align="center">结束部分：</td>
      <td><textarea name="t4" rows="3" class="inputs" id="t4"><%=sdcms_f.TempEncode(rs(5))%></textarea></td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input name="Submit22" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%
set sdcms_f=nothing
end sub
sub save
t0=trim(request("t0"))
t1=trim(request("t1"))
t2=trim(request("t2"))
t3=trim(request("t3"))
t4=trim(request("t4"))
t5=trim(request("t5"))
t6=trim(request("t6"))
t7=trim(request("t7"))
t8=trim(request("t8"))

if t1=1 and t2<>"" then
if instr(lcase(t2),"delete")>0 then echo"sql语句中含有非法字符：Delete":died
if instr(lcase(t2),"update")>0 then echo"sql语句中含有非法字符：Update":died
if instr(lcase(t2),"insert")>0 then echo"sql语句中含有非法字符：Insert":died
if instr(lcase(t2),"Create")>0 then echo"sql语句中含有非法字符：Create":died
on error resume next
conn.execute(""&t2&"")
if err then
echo "SQL语句错误，请检查！":Died
end if
end if

if t6="" or not isnumeric(t6) then t6=0
if t7="" or not isnumeric(t7) then t7=0


set rs=server.CreateObject("adodb.recordset")
sql="select title,sdcms_sql,sdcms_begin,sdcms_over,classid,sdcms_content,id,sdcms_title,sdcms_jj,sdcms_date from "&sd_table&""
if act="add" then 
 sql=sql&" where title='"&t0&"'"
else
 sql=sql&" where id="&id&""
end if
rs.open sql,conn,1,3
if act="add" then 
  if not rs.eof then
  echo "该标签名已存在，请换个试试":Died
  end if
end if
if act="add" then 
  rs.addnew
else
  rs.update
end if
if act="add" then 
rs(0)=left(t0,50)
end if
if t1=1 then rs(1)=t2
rs(2)=t3
rs(3)=t4
rs(4)=t1
rs(5)=t5
rs(7)=t6
rs(8)=t7
rs(9)=t8
rs.update
id=rs(6)
if act="add" then
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','添加标签：{sdcms_"&rs(0)&"}')")
else
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','修改标签：{sdcms_"&rs(0)&"}')")
end if
response.Redirect("?") 
end sub

sub del
if id<>"" then
	if instr(id,", ")>0 then
	id=split(id,", ")
		for i=0 to ubound(id)
			conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除标签：编号为"&id(i)&"')")
			conn.execute("delete from "&sd_table&" where id="&id(i)&"")
		Next
	Else
		conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除标签：编号为"&id&"')")
		conn.execute("delete from "&sd_table&" where id="&id&"")
	End If
end if
response.Redirect("?")
end sub

 
sub check_info
with response
.write("	<script>")
.write("	function checkadd()")
.write("	{")
if action="add" then
.write("	if (document.add.t0.value=='')")
.write("	{")
.write("	alert('标签名称不能为空');")
.write("	document.add.t0.focus();")
.write("	return false")
.write("	}")
end if
.write("	if (!document.add.t2.disabled && document.add.t2.value=='')")
.write("	{")
.write("	alert('SQL语句不能为空');")
.write("	document.add.t2.focus();")
.write("	return false")
.write("	}")
.write("	if (document.add.t5.value=='')")
.write("	{")
.write("	alert('标签内容不能为空');")
.write("	document.add.t5.focus();")
.write("	return false")
.write("	}")
.write("	}")
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>