<!--#include file="sdcms_check.asp"-->
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
sdcms.Check_lever 10
set sdcms=nothing
select case action
case "add":title="添加模板"
case "edit":title="修改模板"
case else:title="模板管理"
end select
sd_table="sd_temp"
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 "copy":copy
case "del":del
case else:main
end select
closedb
sub main
%>
  <table border="0" align="center" cellpadding="3" cellspacing="1" class="table_b">
	<tr>
      <td class="title_bg">模板名称</td>
      <td width="20%" 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  from "&sd_table&" order by id desc"
	rs.open sql,conn,1,1	
	if rs.eof then
	echo "<tr><td colspan=2 bgcolor=#ffffff>没有模板</td></tr>"
	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><%=rs(1)%></td>
      <td align="center"><a href=?action=copy&id=<%=rs(0)%> onclick='return confirm("确实要复制？");'>复制</a> <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  
	if rcount>0 then       
	%>
	<tr>
      <td colspan="2" 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>　<%
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%>
  </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="9%" align="center" class="tdbg">模板名称：      </td>
      <td width="91%" class="tdbg"><input name="t0" type="text" class="input" id="t0" size="40"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">模板类别：      </td>
      <td><input type='radio' name='t1' value='0' checked>频道模板 <input type='radio' name='t1' value='1'>列表模板 <input type='radio' name='t1' value='2'>信息模板 <input type='radio' name='t1' value='3'>单页面模板</td>
    </tr>
   <tr class="tdbg" id="c">
      <td align="center">模板内容：</td>
      <td><textarea name="t2" rows="20" class="inputs"></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,content 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="9%" align="center" class="tdbg">模板名称：      </td>
      <td width="91%" class="tdbg"><input name="t0" type="text" class="input" value="<%=rs(1)%>" id="t0" size="30"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">模板类别：      </td>
      <td><input type='radio' name='t1' value='0' <%=w_check(rs(2),0)%>>频道模板 <input type='radio' name='t1' value='1' <%=w_check(rs(2),1)%>>列表模板 <input type='radio' name='t1' value='2' <%=w_check(rs(2),2)%>>信息模板 <input type='radio' name='t1' value='3' <%=w_check(rs(2),3)%>>单页面模板</td>
    </tr>
   <tr class="tdbg">
      <td align="center">模板内容：</td>
      <td>
	  <textarea name="t2" rows="20" class="inputs"><%=sdcms_f.TempEncode(rs(3))%></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"))

set rs=server.CreateObject("adodb.recordset")
sql="select title,classid,content from "&sd_table&""
if act="save" then 
 sql=sql&" where id="&id&""
end if
rs.open sql,conn,1,3

if act="add" then 
  rs.addnew
else
  rs.update
end if
rs(0)=left(t0,255)
rs(1)=t1
rs(2)=t2
rs.update
if act="add" then
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','添加模板："&rs(0)&"')")
else
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','修改模板："&rs(0)&"')")
end if
response.Redirect("?")
end sub

sub copy
set rs1=conn.execute("select top 1 title,classid,content from "&sd_table&" where id="&id&"")
if not rs1.eof then
set rs=server.CreateObject("adodb.recordset")
sql="select title,classid,content from "&sd_table&""
rs.open sql,conn,1,3
rs.addnew
rs(0)=rs1(0)&"(复制)"
rs(1)=rs1(1)
rs(2)=rs1(2)
rs.update
rs.close
end if
 
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','复制模板："&rs1(0)&"')")
 
response.Redirect("?")
end sub

sub del
set rs=conn.execute("select id from sd_class where indexshow="&id&" or listshow="&id&" or infoshow="&id&"")
if not rs.eof then
echo "不能删除正在使用的模板":Died
end if
set rs=conn.execute("select id from sd_other where tempid="&id&"")
if not rs.eof then
echo "不能删除正在使用的模板":Died
end if
 
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&"")
response.Redirect("?")
end sub


sub check_info
with response
.write("	<script>")
.write("	function checkadd()")
.write("	{")
.write("	if (document.add.t0.value=='')")
.write("	{")
.write("	alert('模板名称不能为空');")
.write("	document.add.t0.focus();")
.write("	return false")
.write("	}")
.write("	if (document.add.t2.value=='')")
.write("	{")
.write("	alert('模板内容不能为空');")
.write("	document.add.t2.focus();")
.write("	return false")
.write("	}")
.write("	}")
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>