<!-- #INCLUDE FILE="include/onlogin.asp" -->
<!-- #INCLUDE FILE="include/conn.asp" -->
<%
dim nsort,sql2,rs2,del_temp,data_name,cid,sid,nid,ncid,nsid,id,now_id,nummer,sqladd,page,rssum,thepages,viewpage,pageurl,topic,csid,keyword
tit=vbcrlf & "<a href='?'>皮肤设置</a> | <a href='?action=markjs'>风格JS</a> | <a href='?action=menujs'>生成下拉菜单JS</a>"
response.write header(3,tit)
pageurl="?action="&action&"&":nsort="art":data_name="article":sqladd="":nummer=15
id=trim(request.querystring("id"))

if action="set" and isnumeric(id) then
	conn.execute("update Skins set IsDef=0 where IsDef=1")
	conn.execute("update Skins set IsDef=1 where ID=" & ID)
	action=""
	response.write "<script language=javascript>alert(""成功将选定的风格设置为默认风格\n请 点 生 成 风 格 JS"");</script>"
end if

select case action
case "edit"
  titt="风格编辑"
case else
  titt="风格设置"
end select

response.write admin_bar(titt,1,"99%")
select case action
case "edit"
  if not(isnumeric(id)) then
    call skins_main()
  else
    call skins_edit()
  end if
case "del"
  call skins_del()
case "markjs"
  call skins_chk()
case "menujs"
  call skins_menu()
case else
  call skins_main()
end select
response.write admin_bar("",2,"99%")

call close_conn()
'response.write ender()

sub skins_main()
	sql="select * from Skins"
	Set rs=Server.CreateObject("Adodb.RecordSet")
	rs.Open sql,conn,1,1
%>
  <table width='100%' border=0 align=center cellpadding=2 cellspacing=1>
    <tr class=tdbg-tree> 
      <td width="10" align="center"><strong>ID</strong></td>
      <td width="100" align="center"><strong>风格名称</strong></td>
      <td width="160" align="center"><strong>CSS 路径</strong></td>
      <td width="80" align="center"><strong>图片路径</strong></td>
      <td width="80" align="center"><strong>风格类型</strong></td>
      <td width="100" height="22" align="center"><strong> 操作</strong></td>
      <td width="50" align="center"><strong>选择</strong></td>
    </tr>
    <%if not(rs.bof and rs.eof) then
  do while not rs.EOF %>
    <tr class="tdbg-dark"> 
      
      <td width="10" align="center"><%=rs("ID")%></td>
      <td width="100" align="center"><%
        response.write "<a href='?Action=edit&ID=" & rs("ID") & "'>"
        if rs("isdef")=1 then
          response.write "<font class=time>"&rs("Name")&"</font></a>"
        else
          response.write ""&rs("Name")&"</a>"
        end if%></td>
      <td width="160" align="left">skins/<font class=time><%=rs("dirname")%></font>/style.css</td>
      <td width="80" align="center"><%=rs("dirname")%></td>
      <td width="80" align="center"><%if rs("hidden")=0 then response.write "用户自定义" else response.write "系统提供"%></td>
      <td width="100" align="center"><%
	response.write "<a href='admin_style.asp?action="&rs("dirname")&"&name="&rs("name")&"' title='点此查看效果页面'>预览</a>&nbsp;<a href='?Action=edit&ID=" & rs("ID") & "'>修改</a>&nbsp;"
	if rs("hidden")=0 and rs("IsDef")=0 then
		response.write "<a href='?action=del&id=" & rs("id") & "' onClick=""return confirm('确定要删除此风格吗？');"">删除</a>"
	else
		response.write "&nbsp;&nbsp;&nbsp;&nbsp;"
	end if%>
	<td width="50" align="center"><%if rs("IsDef")=0 then response.write "<a href='?action=set&id="&rs("ID")&"'>设为默认</a>"%></td>
        </td></tr>
	<%	rs.MoveNext
   	loop
      end if%>
  </table>  
<%
	rs.close
	set rs=nothing
end sub

sub skins_edit()
  dim css,name,dirname,cssbody
  dim fso,dbfolde,CountFile,dbpath,dbfiles,ckfolde,ckfile
  set rs=server.createobject("adodb.recordset")
  sql="select * from skins where id="&id
  rs.open sql,conn,1,3
  if rs.eof and rs.bof then rs.close:set rs=nothing:call skins_main():exit sub
  dbfolde="skins/"&rs("dirname")&""
  dbfiles="skins/"&rs("dirname")&"/style.css"

if trim(request.querystring("edit"))="ok" then
  css=trim(request.form("css"))
  name=trim(request.form("name"))
  dirname=trim(request.form("dirname"))
  cssbody=trim(request.form("cssbody"))
  ckfolde="skins/"&dirname&""
  ckfile="skins/"&dirname&"/style.css"
  if css="" then
      response.write "<font class=time>请输入 CSS 路径！</font><br><br>"&go_back
  elseif name="" then
      response.write "<font class=time>请输入风格名称！</font><br><br>"&go_back
  elseif cssbody="" then
      response.write "<font class=time>请输入样式表内容！</font><br><br>"&go_back
  elseif dirname="" then
      response.write "<font class=time>请输入风格图片目录！</font><br><br>"&go_back
  else
    if trim(request.form("addnew"))<>"" then
    Set Fso=server.createobject("scripting.filesystemobject")
      If CheckDir(ckfolde) = True Then
        call create_file(ckfile,cssbody)
      else
      MakeNewsDir(ckfolde)
        call create_file(ckfile,cssbody)
      end if
    rs.addnew
    rs("css")=css
    rs("name")=name
    rs("dirname")=dirname
    rs("isdef")=0
    rs("hidden")=0
    rs.update
    rs.close:set rs=nothing
    response.write "<script language=javascript>alert(""已经成功添加了风格！\n请 点 生 成 风 格 JS"");</script>"
    else
    rs("css")=css
    rs("name")=name
    rs("dirname")=dirname
    rs.update
    rs.close:set rs=nothing
    Set Fso=server.createobject("scripting.filesystemobject")
	If CheckDir(ckfolde) = True Then
	  call create_file(ckfile,cssbody)
	else
	end if
    Set FSO = Nothing
    response.write "<script language=javascript>alert(""已经成功更新了风格！\n请 点 生 成 风 格 JS"");</script>"
    end if
    call skins_main()
  end if
else
    Set Fso=server.createobject("scripting.filesystemobject")
	If CheckDir(dbfolde) = True Then
	  Set CountFile = FSO.OpenTextFile(Server.MapPath(dbfiles),1,True)
    	  If Not CountFile.AtEndOfStream Then cssbody = CountFile.ReadAll
    	  CountFile.Close
	else
	  MakeNewsDir(dbfolde)
	  response.write "<script language=javascript>alert(""指定目录未找到！系统已经自动建立！"");</script>"
	  CountFile.Close
	end if
    Set FSO = Nothing
%>
<link rel="stylesheet" href="skins/<%=rs("dirname")%>/style.css" type="text/css">
<table align=center width=95% cellpadding=3>
<form action='?action=edit&edit=ok&id=<%response.write id%>' method=post>
<tr><td width=190><b>风格名称：</b></td>
<td><input name=name type="text" value="<%=rs("name")%>" maxlength="50" size="20" class=inputbg>
</td></tr>
<tr><td width=190><b>图片目录：</b></td>
<td><input name=dirname type="text" value="<%=rs("dirname")%>" maxlength="50" size="20" class=inputbg>&nbsp;最好与CSS在相同目录下
</td></tr>
<tr><td valign=top><b>样式表位置：</b></td>
<td><input name=css type="text" value="skins/<%=rs("dirname")%>/style.css" maxlength="255" size="50" class=inputbg readonly>
</td></tr>
<tr><td valign=top><b>样式表内容：</b><br>
<iframe src="admin_style.htm?skins/<%=rs("dirname")%>/style.css" width="190" height="300" frameborder=0></iframe>	</td>
<td><textarea name=cssBody rows="22" cols="70"><%=cssbody%></textarea>
</td></tr>
<tr><td colspan=2 align=center><input id="addNew" type="checkbox" name="addNew" value="1"><label for="addNew">添加为新风格</label></td>
</tr>
<tr><td colspan=2 align=center>
<input type=submit value='提 交 修 改' class=inputbg>
</td></tr>
</form></table>	
<%
end if
end sub

sub Skins_del()
	sql="select * from Skins where ID=" & ID
	Set rs=Server.CreateObject("Adodb.RecordSet")
	rs.Open sql,conn,1,3
	if rs.bof and rs.eof then
           response.write "<script language=javascript>alert(""没有找到指定风格！"");</script>"
	else
		if rs("hidden")=1 then
           response.write "<script language=javascript>alert(""无法删除系统自带风格！"");</script>"
		rs.close
		set rs=nothing
		exit sub
		elseif rs("IsDef")=1 then
           response.write "<script language=javascript>alert(""无法删除默认风格！请改选默认风格后再进行删除！"");</script>"
		rs.close
		set rs=nothing
		exit sub
		end if
	end if
	rs.delete
	rs.update
	rs.close
	set rs=nothing
	response.write "<script language=javascript>alert(""成功删除ID为"&id&"的风格！请自行删除SKINS目录下的文件！"");</script>"
	call skins_main()
end sub

sub skins_menu()
  dim wdim
  wdim=split(web_style,"|")
  dim filetemp,fileos,filepath,file_name,filetype
  file_name="include/menu_style.asp"
  set fileos=CreateObject("Scripting.FileSystemObject")
  filepath=server.mappath(file_name)
  set filetemp=fileos.createtextfile(filepath,true)
    filetemp.writeline("<script language=javascript1.2>")
    filetemp.writeline("linkset[0]=new Array()")
  for i=0 to ubound(wdim)
    filetype="linkset[0]["&i&"]='<div class=""menuitems""><a href=""skins.asp?id="&i&""">"&right(wdim(i),len(wdim(i))-instr(wdim(i),":"))&"</a></div>'"
    filetemp.writeline(""&filetype&"")
  next
  erase wdim
    filetemp.writeline("</script>")
  filetemp.close
  set filetemp=nothing
  set fileos=nothing
  response.write "<script language=javascript>alert(""风格下拉菜单JS生成成功！"");</script>"
  call skins_main()
end sub

sub skins_chk()
  dim rs1,sql1
  sql1="select * from skins where isdef=1"
  set rs1=server.createobject("adodb.recordset")
  rs1.open sql1,conn,1,3
  if rs1.eof and rs1.bof then
  web_skins="metal"
  else
  web_skins=rs1("dirname")
  end if
  rs1.close:set rs1=nothing
  dim rssum,j,name,dirname,web_styles
  sql="select id,name,dirname from skins order by id desc"
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,1,1
  if rs.eof and rs.bof then
    rssum=0
  else
    rssum=rs.recordcount
  end if
if trim(request.querystring("mark"))="ok" then
    dim tn,t1
    tn=int(trim(request.form("web_styles_num")))
    for i=1 to tn-1
      t1=request.form("web_styles_"&i)
      if len(t1)>1 then if instr(1,t1,":")>1 then web_styles=web_styles&t1&"|"
    next
    'if len(t1)>1 then if instr(1,t1,":")>1 then web_styles=web_styles&t1
    if right(web_styles,1)="|" then web_styles=left(web_styles,len(web_styles)-1)
  dim filetype,file_name
  filetype="<"&""&"%" & vbcrlf & _
	"web_skins="""&web_skins&""""&vbcrlf&_
	"web_style="""&web_styles&""""&vbcrlf&_
	"%"&""&">"
  file_name="include/common_skins.asp"
  call create_file(file_name,filetype)
  response.write "<script language=javascript>alert(""风格JS生成成功！"");</script>"
  call skins_main()
else
%>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
<form action='?action=<%response.write action%>&mark=ok' method=post>
<%
  for i=1 to rssum
  if rs.eof then exit for
    name=rs("name"):dirname=rs("dirname")
    response.write "<tr class=tdbg-dark><td width='20%'>网站风格"&i&"：</td><td><input type=text name=web_styles_"&i&" value='"&dirname&":"&name&"' size=50 readonly></td></tr>"
    rs.movenext
  next
%>
    <input type=hidden name=web_styles_num value='<%response.write i%>'>
    <tr class=tdbg-dark><td colspan=2 align=center height=30><input type=submit value='生 成 风 格 JS'></td></tr>
    </form>
    </table>
<%
rs.close:set rs=nothing
end if
end sub

sub create_file(file_name,filetype)
  dim filetemp,fileos,filepath
  set fileos=CreateObject("Scripting.FileSystemObject")
  filepath=server.mappath(file_name)
  set filetemp=fileos.createtextfile(filepath,true)
  filetemp.writeline( filetype )
  filetemp.close
  set filetemp=nothing
  set fileos=nothing
end sub

'-------------检查指定目录是否存在-----------------------
Function CheckDir(FolderPath)
   dim fso1
	folderpath=Server.MapPath(".")&"\"&folderpath
    Set fso1 = CreateObject("Scripting.FileSystemObject")
    If fso1.FolderExists(FolderPath) then
       '存在
       CheckDir = True
    Else
       '不存在
       CheckDir = False
    End if
    Set fso1 = nothing
End Function
'-------------根据指定名称生成目录-----------------------
Function MakeNewsDir(foldername)
	dim f,fso1
    Set fso1 = CreateObject("Scripting.FileSystemObject")
        Set f = fso1.CreateFolder(foldername)
        MakeNewsDir = True
    Set fso1 = nothing
End Function
%>