<%@ Language=VBScript %>
<%server.ScriptTimeout =240%>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseif lcase(session("agentusername"))="freehost" Then
	ef=True
	ec="非法用户名。"
ElseIf Request("id")<>"" and not IsNumeric(Request("id")) Then
	ef=True
	ec="编号必须是数字"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
if Request.Form ("nowuse")<>"" then
Sql="update FreeHost.FreeHost_HtmlStyle set nowuse='0' where username='"&session("agentusername")&"'"
conn.Execute Sql
end if
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_HtmlStyle where username='"&session("agentusername")&"' and id='"&Request("id")&"'"
		ds.Open Sql,conn,1,3


if ds.eof or Request.Form ("newstyle")="y" Then
	Set dscount = Server.CreateObject("ADODB.Recordset")	
		Sql="Select count(*) from FreeHost.FreeHost_HtmlStyle where username='"&session("agentusername")&"'"
		dscount.Open Sql,conn,1,1
If dscount(0)>2 Then
Response.Redirect "e.asp?e=很抱歉，最多只允许保存3个模板"
End If


	Set dscount = Server.CreateObject("ADODB.Recordset")	
		Sql="Select stylename from FreeHost.FreeHost_HtmlStyle"
		dscount.Open Sql,conn,1,1
While Not dscount.eof
If dscount("stylename")=Trim(Request.Form ("stylename")) then
Response.Redirect "e.asp?e=已存在同名的模板，请您换一个模板名称再保存。"
End if
dscount.movenext
wend

ds.AddNew 
End if
ds("username")=session("agentusername")
ds("html1")=Request.Form ("html1")
ds("html2")=Request.Form ("html2")
ds("html3")=Request.Form ("html3")
ds("html4")=Request.Form ("html4")
ds("html5")=Request.Form ("html5")
ds("html6")=Request.Form ("html6")
ds("html7")=Request.Form ("html7")
'ds("html8")=Request.Form ("html8")
'ds("html9")=Request.Form ("html9")
'ds("html10")=Request.Form ("html10")
ds("html11")=Request.Form ("html11")
ds("html12")=Request.Form ("html12")
ds("html13")=Request.Form ("html13")
ds("html14")=Request.Form ("html14")
ds("html15")=Request.Form ("html15")
ds("html16")=Request.Form ("html16")
ds("html17")=Request.Form ("html17")
ds("html18")=Request.Form ("html18")
ds("html19")=Request.Form ("html19")
ds("html20")=Request.Form ("html20")
ds("html21")=Request.Form ("html21")
ds("html22")=Request.Form ("html22")
ds("html23")=Request.Form ("html23")
ds("html24")=Request.Form ("html24")
ds("html25")=Request.Form ("html25")

ds("html26")=Request.Form ("html26")
ds("html27")=Request.Form ("html27")
ds("html28")=Request.Form ("html28")
ds("html29")=Request.Form ("html29")
ds("html30")=Request.Form ("html30")
ds("html31")=Request.Form ("html31")
ds("html32")=Request.Form ("html32")

ds("stylename")=Trim(Request.Form ("stylename"))
if Request.Form ("nowuse")="" then
ds("nowuse")=0
else
ds("nowuse")=1
end if

if Request.Form ("pubuse")="" then
ds("pubuse")=0
else
ds("pubuse")=1
end if


ds("haveupdate")="y"
ds.Update
ds.Close

set ds=nothing

Set ds = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_HtmlStyle where username='"&session("agentusername")&"' and nowuse='1'"
ds.open sql,conn,1,1
if not ds.eof then
session("html1")=ds("html1")
session("html2")=ds("html2")
session("html3")=ds("html3")
session("html4")=ds("html4")
session("html5")=ds("html5")
session("html6")=ds("html6")
session("html7")=ds("html7")
'session("html8")=Application("html8")
'session("html9")=Application("html9")
'session("html10")=Application("html10")
session("html11")=ds("html11")
session("html12")=ds("html12")
session("html13")=ds("html13")
session("html14")=ds("html14")
session("html15")=ds("html15")
session("html16")=ds("html16")
session("html17")=ds("html17")
session("html18")=ds("html18")
session("html19")=ds("html19")
session("html20")=ds("html20")
session("html21")=ds("html21")
session("html22")=ds("html22")
session("html23")=ds("html23")
session("html24")=ds("html24")
session("html25")=ds("html25")

session("html26")=ds("html26")
session("html27")=ds("html27")
session("html28")=ds("html28")
session("html29")=ds("html29")
session("html30")=ds("html30")
session("html31")=ds("html31")
session("html32")=ds("html32")

end if
ds.close
set ds=nothing

session("ism")=false

conn.Close 
set conn=nothing
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>　修改成功
<%=htmlwrite("html6")%>
修改成功！请您注意，如果您要看到修改后的效果，请您新打开一个IE，直接在地址栏输入您的服务域名，就可以看到。
<%=htmlwrite("html7")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
