<!--#include file="sdcms_check.asp"-->
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
sdcms.Check_lever 11
set sdcms=nothing
select case action
case "add":title="添加风格"
case "edit":stype="main":title="修改风格"
case else:title="风格管理"
end select
sd_table="sd_skins"
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"><a<%if stype="main" then%> href="javascript:void(0)" onClick="selectTag('tagContent0',this)"<%end if%>><%=title%></a></li>
	<%if stype="main" then%>
	<li class="unsub"><a href="javascript:void(0)" onClick="selectTag('tagContent1',this)">风格信息</a></li>
	<%end if%>
</ul>
<div id="sdcms_right_b">
<%
select case action
case "add":add
case "edit":edit
case "save":save
case "del":del
case "onskins":onskins
case else:main
end select
closedb
sub main
%>
  <table border="0" align="center" cellpadding="3" cellspacing="1" width="99%" >
    <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,pic,author,url,"
	if Is_sql=0 then
	sql=sql&"(iif(isused=0,'#ddd','#f30')),(iif(isused=0,'','disabled')),(iif(isused=0,'','此风格正在使用'))"
	else
	sql=sql&"(case isused when 0 then'#ddd'else'#f30'end),"
	sql=sql&"(case isused when 0 then''else'disabled'end),(case isused when 0 then''else'此风格正在使用'end)"
	end if
	sql=sql&" 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
	i=0
	do while not rs.eof and rcount1 <rs.pagesize  
	%>
   
	 
      <td align="center" valign="top" width="25%">
	  <table border="0" cellspacing="0" cellpadding="0" style="margin:6px;">
  <tr>
    <td align="center"><img src="<%=rs(2)%>" alt="<%=rs(7)%>" width="150" height="120" style="border:1px solid <%=rs(5)%>;"></td>
	 </tr>
	 <tr>
	<td height="40" align="center"><input type="button" <%=rs(6)%> class="bnt01" value="应用" onClick="if(confirm('确定要使用该风格么!'))location.href='?action=onskins&id=<%=rs(0)%>';return false;"> <input type="button" onClick="location.href='?action=edit&id=<%=rs(0)%>';" class="bnt01" value="编辑"> <input type="button" <%=rs(6)%> onClick="if(confirm('真的要删除?不可恢复!'))location.href='?action=del&id=<%=rs(0)%>';return false;" class="bnt01" value="删除"></td>
  </tr>
  <tr>
	<td style="padding-left:8px;">名称：<%=rs(1)%><br>作者：<a href="<%=rs(4)%>" target="_blank"><%=rs(3)%></a></td>
  </tr>
</table>

	  </td>
	<%
	i=i+1
	if i=4 then
	i=0
	echo "</tr><tr>"
	end if
	rs.movenext
	rcount1=rcount1+1
	loop
	end if         
	%>
    </tr>
	<%if rcount>0 then%>
	<tr>
      <td colspan="4" 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="12%" align="center" class="tdbg">风格名称：      </td>
      <td class="tdbg"><input name="t0" type="text" class="input" id="t0" size="40"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">风格作者：      </td>
      <td><input name="t1" value="<%=sdcms_adminname%>" type="text" class="input" id="t1" size="40"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">官方网站：</td>
      <td><input name="t2" type="text" class="input"   value="http://www.sdcms.cn" size="40"></td>
    </tr>
	<tr class="tdbg">
      <td align="center">效果图片：</td>
      <td><input name="t3" type="text" class="input"   size="40">
      <span>
      <select onChange="t3.value=this.value">
	  <option>选择图片</option>
        <option value="images/nopic.gif">没有图片</option>
      </select>
      尺寸：150*120</span><br><%admin_upfile 2,"40%","30",1%></td>
    </tr>
    <tr class="tdbg">
      <td align="center">风格目录：</td>
      <td><input name="t4" type="text" class="input"  size="40"></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,author,url,pic,root from "&sd_table&" where id="&id&"")
if rs.eof then
echo "请勿非法提交参数":Died
end if
check_info
%> 
<form name="add" method="post" action="?action=save&act=save&id=<%=id%>" onSubmit='return checkadd()'>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" id="tagContent1" class="dis">
    <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 name="t1" type="text" class="input" value="<%=rs(2)%>" id="t1" size="30"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">官方网站：</td>
      <td><input name="t2" type="text" class="input"  value="<%=rs(3)%>" size="40"></td>
    </tr>
	<tr class="tdbg">
      <td align="center">效果图片：</td>
      <td><input name="t3" type="text" class="input"  value="<%=rs(4)%>"   size="40">
      <span>尺寸：150*120</span><br><%admin_upfile 2,"40%","30",1%></td>
    </tr>
    <tr class="tdbg">
      <td align="center">风格目录：</td>
      <td><input name="t4" type="text" class="input"  value="<%=rs(5)%>" size="40">
	  <span>将风格放置系统路径../skins/下,直接输入模板文件夹名 如"default"</span></td>  
    </tr>
   </table>
   <%
   set sdcms=new Sdcms_Function
   skin_tmp="../skins/"&rs(5)&"/"
   %>
   <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" id="tagContent0">
	<tr class="tdbg">
      <td align="center" width="12%"><input name="up1" id="up1" type="checkbox" value="1" checked="checked" /><label for="up1">首页风格：<br>sdcms_index.htm</label></td>
      <td><textarea name="s0" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_index.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up2" id="up2" type="checkbox" value="1" checked="checked" /><label for="up2">公告列表：<br>sdcms_notice.htm</label></td>
      <td><textarea name="s1" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_notice.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up3" id="up3" type="checkbox" value="1" checked="checked" /><label for="up3">公告信息：<br>sdcms_notice_info.htm</label></td>
      <td><textarea name="s2" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_notice_info.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up4" id="up4" type="checkbox" value="1" checked="checked" /><label for="up4">信息列表：<br>(文字类)</label><br>sdcms_info_text.htm</td>
      <td><textarea name="s3" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_info_text.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up5" id="up5" type="checkbox" value="1" checked="checked" /><label for="up5">信息列表：<br>(图片类)</label><br>sdcms_info_pic.htm</td>
      <td><textarea name="s4" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_info_pic.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><br /><input name="up6" id="up6" type="checkbox" value="1" checked="checked" /><label for="up6">信息显示：</label><br>sdcms_info_show.htm</td>
      <td><textarea name="s5" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_info_show.htm"))%></textarea></td>
    </tr>
	 
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up7" id="up7" type="checkbox" value="1" checked="checked" /><label for="up7">投票页面：</label><br>sdcms_vote.htm</td>
      <td><textarea name="s6" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_vote.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up8" id="up8" type="checkbox" value="1" checked="checked" /><label for="up8">搜索页面：</label><br>sdcms_search.htm</td>
      <td><textarea name="s7" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_search.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up9" id="up9" type="checkbox" value="1" checked="checked" /><label for="up9">单 页 面：</label><br>sdcms_page.htm</td>
      <td><textarea name="s8" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_page.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up10" id="up10" type="checkbox" value="1" checked="checked" /><label for="up10">标签页面：</label><br>sdcms_tag.htm</td>
      <td><textarea name="s9" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_tag.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up11" id="up11" type="checkbox" value="1" checked="checked" /><label for="up11">标签列表：</label><br>sdcms_tag_list.htm</td>
      <td><textarea name="s10" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_tag_list.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up12" id="up12" type="checkbox" value="1" checked="checked" /><label for="up12">插件页面：</label><br>sdcms_plug.htm</td>
      <td><textarea name="s11" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_plug.htm"))%></textarea></td>
    </tr>
	<tr class="tdbg">
      <td align="center" width="9%"><input name="up13" id="up13" type="checkbox" value="1" checked="checked" /><label for="up13">站点地图：</label><br>sdcms_map.htm</td>
      <td><textarea name="s12" rows="10" class="inputs"><%=sdcms.TempEncode(sdcms.LoadFile(""&skin_tmp&"sdcms_map.htm"))%></textarea></td>
    </tr>
	</table>
	<%set sdcms=nothing%>
	<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" >
    <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>
  </table>
   
<%
set sdcms=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"))
s0=trim(request("s0"))
s1=trim(request("s1"))
s2=trim(request("s2"))
s3=trim(request("s3"))
s4=trim(request("s4"))
s5=trim(request("s5"))
s6=trim(request("s6"))
s7=trim(request("s7"))
s8=trim(request("s8"))
s9=trim(request("s9"))
s10=trim(request("s10"))
s11=trim(request("s11"))
s12=trim(request("s12"))

up1=trim(request("up1"))
up2=trim(request("up2"))
up3=trim(request("up3"))
up4=trim(request("up4"))
up5=trim(request("up5"))
up6=trim(request("up6"))
up7=trim(request("up7"))
up8=trim(request("up8"))
up9=trim(request("up9"))
up10=trim(request("up10"))
up11=trim(request("up11"))
up12=trim(request("up12"))
up13=trim(request("up13"))
t4=dir_check(t4)

sysfile="../skins/"&t4&"/"

set rs=server.CreateObject("adodb.recordset")
sql="select title,author,url,pic,root 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)=left(t1,50)
rs(2)=t2
rs(3)=left(t3,255)
if t4<>rs(4) then remove_app "systempdir"
rs(4)=t4
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
if act="save" then
set sdcms=new Sdcms_Function
files="sdcms_index.htm|sdcms_notice.htm|sdcms_notice_info.htm|sdcms_info_text.htm|sdcms_info_pic.htm|sdcms_info_show.htm|sdcms_vote.htm|sdcms_search.htm|sdcms_page.htm|sdcms_tag.htm|sdcms_tag_list.htm|sdcms_plug.htm|sdcms_map.htm"
files=split(files,"|")
for i=0 to ubound(files)
	if len(eval("up"&i+1))>0 then sdcms.savefile sysfile,files(i),eval("s"&i)
next
set sdcms=nothing
end if
response.Redirect("?")
end sub
sub del
  if conn.execute("select isused from "&sd_table&"  where id="&id&"")(0)=1 then
  echo "该风格正在使用,不能删除":Died
  end if
  conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除风格："&conn.execute("select title from "&sd_table&" where id="&id&"")(0)&"')")
  conn.execute("delete from "&sd_table&" where id="&id&"")
  response.Redirect("?") 
end sub

sub onskins
  conn.execute("update   "&sd_table&" set isused=0 ")
  conn.execute("update   "&sd_table&" set isused=1 where id="&id&"")
  conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','应用风格："&conn.execute("select title from "&sd_table&" where id="&id&"")(0)&"')")
  application.Contents.Remove(sdcms_cookies&"systempdir")
  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.t3.value=='')")
.write("	{")
.write("	alert('效果图片不能为空');")
.write("	document.add.t3.focus();")
.write("	return false")
.write("	}")
.write("	if (document.add.t4.value=='')")
.write("	{")
.write("	alert('风格目录不能为空');")
.write("	document.add.t4.focus();")
.write("	return false")
.write("	}")
.write("	}")
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>