<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("username")="" Then
	ef=True
	ec="请您先登陆用户区，再续费，在主机面板中不能续费。也有可能是超时造成了出错。"
ElseIf Request.Form ("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Instr(1, Request.Form ("id"), "'", 1)>0 then
	ef=True
	ec="非法产品ID！"
ElseIf not IsNumeric(Request.Form ("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf Request.Form ("Hostlistid")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Instr(1, Request.Form ("Hostlistid"), "'", 1)>0 then
	ef=True
	ec="非法产品号！"
ElseIf not IsNumeric(Request.Form ("Hostlistid"))  Then
	ef=True
	ec="产品号应该是数字！"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&session("username")&"'"
		ds.Open Sql,conn,1,3
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if

if not ef then
if ds("password")<>session("password") then
	ef=True
	ec="密码不正确!"
end if
end if

if not ef then
	Set dshost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist where id='"&Request.Form ("Hostlistid")&"'"
'	Response.Write sql
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dshost.Open Sql,conn,1,1
if dshost.Eof then
	ef=True
	ec="新产品不存在！"
Else
packagename=dshost("packagename")'linux
'Else
'If dshost("cantwodb")=true Then
'canselectdb=false
'else
'canselectdb=true
'End if
end if
end if

if not ef then
if Not IsNull(dshost("onlyusebyagn")) Then
If session("agentname")<>dshost("onlyusebyagn") then
	ef=True
	ec="本产品只允许特定的代理使用！"
End if
end if
end If

if not ef then
if dshost("allowupdate")="y" then
	ef=True
	ec="此产品只能直接购买不允许从别的产品升级！"
end if
end if

if not ef then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&Request.Form ("id")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,3
if dsph.Eof then
	ef=True
	ec="要升级的虚拟主机不存在！"
end if
end if

if not ef then
if dsph("istest")="y" then
	ef=True
	ec="处于试用期的虚拟主机请您通过延期操作来转成正式产品！"
end if
end if

if not ef then
if not isnull(dsph("repaymoney")) then
	ef=True
	ec="由于此产品被管理员设置了单独的续费价格，因此，请您联系管理员帮您手工升级。"
end if
end if

'if not ef then
'	Set dsserver = Server.CreateObject("ADODB.Recordset")	
'	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
'	dsserver.Open Sql,conn,1,1
'if dsserver.Eof then
'	ef=True
'	ec="服务器不存在！"
'else
 '   netby=dsserver("netby")
'	ip=dsserver("ip")
'	ostype=dsserver("ostype")'linux
'Dim isAgnHostSer
'if dsserver("agent1")="n" then
'isAgnHostSer=false
'else
'isAgnHostSer=true
'end if
'end if
'end If

if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
Else
    netby=dsserver("netby")
	ip=dsserver("ip")
	hostip=dsserver("ip")
	ftpdomain=dsserver("ftpdomain")
	ostype=dsserver("ostype")
hostip=dsserver("ip")
isuseCDN=dsserver("isuseCDN")	
usecdn1=dsserver("usecdn1")
usecdn2=dsserver("usecdn2")
usecdn3=dsserver("usecdn3")
usecdn4=dsserver("usecdn4")
usecdn5=dsserver("usecdn5")
CDNORIport=dsserver("port")
Dim isAgnHostSer
if dsserver("agent1")="n" then
isAgnHostSer=false
else
isAgnHostSer=true
end if
end if
end if

if not ef then
if isuseCDN=true then
	Set dsCDNserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerCDNlist where id='"&dsserver ("usecdn1")&"'"
	dsCDNserver.Open Sql,conn,1,3
if dsCDNserver.Eof then
	ef=True
	ec="CDN服务器不存在！"
end if
end if
end if




if not ef then
if dsph("istest")="y" then
	ef=True
	ec="试用状态的产品必须延期后成为正式产品才可以升级到高级别！"
end if
end if

if not ef then
if ds("agent1")<>"n" then

if not ef then
  Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&ds("agent1")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsagent.Open Sql,conn,1,3
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在或密码出错了！"
end if
end if

if not ef then
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"& session("agenttype")&"'"
		dsagnettype.Open Sql,conn,1,1
if dsagnettype.Eof then
	ef=True
	ec="代理类型折扣为空，请先设置它！"
end if
end if

if not ef then
	Set dsagnpri = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='虚拟主机' and username='"&session ("agentname")&"' and id="&dshost("id")&""
		dsagnpri.Open Sql,conn,1,1
if dsagnpri.eof then
myrealcost=dshost("usermoney")*dsagnettype("pers")
else
myrealcost=dsagnpri("usermoney")
end if
dsagnpri.close

	Set dsendmoney = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_user_price where prtype='虚拟主机' and username='"&session("agentname")&"' and id="&dshost("id")&""
		dsendmoney.Open Sql,conn,1,1
if dsendmoney.eof then
usermoney=dshost("usermoney")
else
usermoney=dsendmoney("usermoney")
end if
dsendmoney.close
end if
end if
end if

if not ef then
	Set dshostold = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist where Hosttype='"&dsph ("Hosttype")&"'"
	dshostold.Open Sql,conn,1,1
if dshostold.Eof then
	ef=True
	ec="旧产品不存在！"
else
typeid=dshostold("typeid")
If IsNull(dsph ("MaxConnections")) then
MaxConnectionsOLD=dshostold ("MaxConnections")
MaxBandwidthOLD=dshostold("MaxBandwidth")
Else
MaxConnectionsOLD=dsph ("MaxConnections")
MaxBandwidthOLD=dsph("MaxBandwidth")
End if
end if
end if

if not ef then
if (dshostold("updatebytypeid")="y" and dshost("typeid")=dshostold("typeid")) or isnull(dshostold("updatebytypeid")) or dshostold("updatebytypeid")="n" then
else
	ef=True
	ec="此产品只能在同一类型号中升级！类型号为："&typeid
end if
end If

if not ef then
if dshost("ostype")<>dshostold("ostype") then
	ef=True
	ec="产品只能在一样的操作系统类型中升级！您现在的操作系统类型为："&dshostold("ostype")
end if
end If

'if not ef then
'if ostype="linux" then Response.Redirect "e.asp?e=DA面板的Linux系统不能使用此功能。"
'end If

if not ef then
if dshostold("allowupdatetoother")="y" then
	ef=True
	ec="很抱歉，此产品不允许向别的产品升级。"
end if
end if

if not ef then
if ds("agent1")<>"n" then
	Set olddsagnpri = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='虚拟主机' and username='"&session ("agentname")&"' and id="&dshostold("id")&""
		olddsagnpri.Open Sql,conn,1,1
if olddsagnpri.eof then
oldmyrealcost=dshostold("usermoney")*dsagnettype("pers")
else
oldmyrealcost=olddsagnpri("usermoney")
end if
olddsagnpri.close

	Set olddsendmoney = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_user_price where prtype='虚拟主机' and username='"&session("agentname")&"' and id="&dshostold("id")&""
		olddsendmoney.Open Sql,conn,1,1
if olddsendmoney.eof then
oldusermoney=dshostold("usermoney")
else
oldusermoney=olddsendmoney("usermoney")
end if
olddsendmoney.close
end if
end if

'response.write isAgnHostSer
'response.end
'response.write "新产品价格："&myrealcost&" 旧产品价格："&oldmyrealcost
'response.end


if not ef then
if dsph("istest")<>"y" then
if dshost("Hosttype")=dsph("Hosttype") then
	ef=True
	ec="同级别不可以升级!"
end if
end if
end if

if not ef then
if dshostold("usermoney")>dshost("usermoney") or dshostold("usermoney")=dshost("usermoney") then
	ef=True
	ec="不能向低别升级!"
end if
end if

if not ef Then
daytoend=DateDiff("d",NOW,dsph("endtime"))
if daytoend<0 Then
	ef=True
	ec="您原来的产品已过期了，请您先延期原产品后才能升级。"
End If
End If

if not ef then
if dsph("istest")="y" then  daytoend=0'试用期的产品也要设置为0

if ds("agent1")="n" then'不是代理也不是代理名下用户
'不是代理也不是代理名下用户
oldusermoneyleft=dshostold("usermoney")/365*daytoend
if oldusermoneyleft<0 then oldusermoneyleft=0'防止出现特殊情况
'后面的天数用新产品所用的钱
newtypeusemoneyforuser=dshost("usermoney")/365*daytoend
oldusermoneytake=newtypeusemoneyforuser-oldusermoneyleft
else'是代理名下用户或代理自己操作自己

oldusermoneyleft=oldusermoney/365*daytoend
if oldusermoneyleft<0 then oldusermoneyleft=0'防止出现特殊情况
'后面的天数用新产品所用的钱
newtypeusemoneyforuser=usermoney/365*daytoend
oldusermoneytake=newtypeusemoneyforuser-oldusermoneyleft
if session("AgnRunasUser") Then oldusermoneytake=0'代理自己登陆用户区操作自己用户角色为0

'计算代理角色成本
oldAgentrmoneyleft=oldmyrealcost/365*daytoend
if oldAgentrmoneyleft<0 then oldAgentrmoneyleft=0'防止出现特殊情况--代理
'后面的天数用新产品所用的钱--代理
newtypeAgentmoneyforuser=myrealcost/365*daytoend
oldAgentrmoneytake=newtypeAgentmoneyforuser-oldAgentrmoneyleft
If isAgnHostSer Then oldAgentrmoneytake=0'独立模式服务器

end If'结束代理判断
end If


if not ef Then
'oldusermoneytake=round(oldusermoneytake,2)'处理格式
oldusermoneytake=round(oldusermoneytake,0)'2007-9-16 改成小数字后0位
if oldusermoneytake>ds("usermoney") then'检查用户角色上是否有足够的钱
	ef=True
	ec="很抱歉,您的余额不足！升级产品所需金额为:"&oldusermoneytake&"元，当前您的余额为："&ds("usermoney")&"元"
End If
End If

if not ef Then
if ds("agent1")<>"n" then'代理自己所需成本检查
'oldAgentrmoneytake=round(oldAgentrmoneytake,2)'处理格式
oldAgentrmoneytake=round(oldAgentrmoneytake,0)'2007-9-16 改成小数字后0位
if oldAgentrmoneytake-oldusermoneytake>dsagent("usermoney") then
	ef=True
	ec="很抱歉,上级余额不足！升级产品所需金额为:"&oldAgentrmoneytake-oldusermoneytake&"元，可操作的余额为："&dsagent("usermoney")&"元"
End If
End If
End if


if not ef Then
moneych=oldusermoneytake
if session("AgnRunasUser") Then moneych=oldAgentrmoneytake
If moneych<0 Then
	ef=True
	ec="很抱歉,余额为负("&moneych&"元)！有可能是这两个产品成本价一样造成,请联系管理员处理."
End if
End if



if not ef then
if Request.Form ("Submit")="只计算升级费用" then

moneych=oldusermoneytake
if session("AgnRunasUser") Then moneych=oldAgentrmoneytake
%>
<!--#include virtual="/inc-freehost-function/template-hostadm-top.asp"-->
　虚拟主机升级

<br><br><br>
升级到此产品所需金额为：<%=moneych%> 元
<%if session("AgnRunasUser") Then%> <font color=red>(代理成本金额为：<%=oldAgentrmoneytake%> 元)</font><%End if%>
<%If isAgnHostSer Then%> <font color=red>(独立模式)</font><%End if%>
<!--#include virtual="/inc-freehost-function/template-hostadm-end.asp"-->
<%

response.end
end if'只显示升级费用
end if

if not ef then


'开始扣费
olduser_money=ds("usermoney")
ds("usermoney") =ds("usermoney") -oldusermoneytake
newuser_money=ds("usermoney")
moneych=-oldusermoneytake
ds.update'扣用户角色费用

if ds("agent1")<>"n" then
oldagn_money=dsagent("usermoney")
dsagent("usermoney")=dsagent("usermoney")-oldAgentrmoneytake+oldusermoneytake
mymoneych=-oldAgentrmoneytake+oldusermoneytake
newagn_money=dsagent("usermoney")
dsagent.update
'response.write "新产品价格："&usermoney&" 旧产品价格："&oldusermoney&" 用户原："&ds("usermoney")&" 代理成本折算旧："&oldRmoney&" 用户折算旧："&oldmoney&" tem："&(usermoney-oldmoney)&" tem2："&(myrealcost-oldRmoney)
'response.end
end if


dim starttime,temptime,pdtype
pdtype="原类型："&dsph ("Hosttype")&" 新类型："&dshost("Hosttype")


username=dsph("Ftpname")
URL=dsserver("site")
tourl=dsserver("pauseweb")




'更新产品类别
dsph ("Hosttype")=dshost("Hosttype")

dsph("allowsub")=dshost("allowsub")
dsph("subweb")=dshost("subweb")
'dsph("useper")=100

'response.write dsph("subweb") 
'response.end
starttime=dsph ("endtime")
temptime=dsph ("endtime")


dsph.update
logfor="用户区升级(FTP名"&dsph("Ftpname")&")"
if session("AgnRunasUser")=false then 
if isAgnHostSer then logfor="自动开通升级虚拟主机独立模式"
FreeHost_moneyNewlog conn,"y","n","n","n","n",isAgnHostSer,moneych,dsph ("username"),dsph ("username"),dsph ("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,supusername,logfor,logfor,"虚拟主机",dsph("id"),pingzheng,type1,bank,haveget,havecheck
if ds("agent1")<>"n" then FreeHost_moneyNewlog conn,"n","y","n","n","y",isAgnHostSer,mymoneych,dsph ("agent1"),dsph ("username"),norusername,norStmoney,norEndmoney,dsph ("agent1"),oldagn_money,newagn_money,supusername,logfor&"代理收入",logfor&"代理收入","虚拟主机",dsph("id"),pingzheng,type1,bank,haveget,havecheck
else
FreeHost_moneyNewlog conn,"n","y","n","n","n",isAgnHostSer,-mymoneych,dsph ("username"),dsph ("username"),norusername,norStmoney,norEndmoney,dsph ("username"),oldagn_money,newagn_money,supusername,logfor&"扣代理成本",logfor&"扣代理成本","虚拟主机",dsph("id"),pingzheng,type1,bank,haveget,havecheck
olduser_money=oldagn_money
moneych=newagn_money-oldagn_money
newuser_money=newagn_money
end if


if isAgnHostSer=false then '不送域名
if dshost("isbydomain")="y" Then
if daytoend>364 Then
'送域名
	Set dspre = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Preopen_Product"
	dspre.Open Sql,conn,1,3
dspre.addnew
dspre("username")=ds("username")
dspre("haveget")="n"
dspre("byid")=dsph("id")
dspre("type1")=dshost("Domaintype")
dspre("whichProduct")="虚拟主机"
dspre("attime")=now
dspre("agent1")=ds("agent1")
dspre.update
dspre.close
set dspre=nothing
end if
end if
end if

starttime=now
'开通邮箱
	Set dsemailpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist where Hosttype='"&dshost("Hosttype")&"' and isbyhost='y'"
	dsemailpdlist.Open Sql,conn,1,1
if not dsemailpdlist.Eof then

'2008-2-14修改bug
ServerlistID=dsemailpdlist ("ServerlistID")
	Set dsemailserver = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Serveremaillist where netby='"&netby&"' and agent1='n'"

		dsemailserver.Open Sql,conn,1,1
while not dsemailserver.Eof
 if (dsemailpdlist ("ServerlistID")=dsemailserver("id") or dsemailpdlist ("ServerlistID2")=dsemailserver("id")  or dsemailpdlist ("ServerlistID3")=dsemailserver("id") or dsemailpdlist ("ServerlistID4")=dsemailserver("id") or dsemailpdlist ("ServerlistID5")=dsemailserver("id")) then
 ServerlistID=dsemailserver("id")'优先选择可选机房中的同机房
 end if
 dsemailserver.movenext
wend
dsemailserver.Requery
while not dsemailserver.Eof
 if ip=dsemailserver("ip") and (dsemailpdlist ("ServerlistID")=dsemailserver("id") or dsemailpdlist ("ServerlistID2")=dsemailserver("id")  or dsemailpdlist ("ServerlistID3")=dsemailserver("id") or dsemailpdlist ("ServerlistID4")=dsemailserver("id") or dsemailpdlist ("ServerlistID5")=dsemailserver("id")) then
 ServerlistID=dsemailserver("id")'优先选择可选机房中的同一IP
 end if
  dsemailserver.movenext
wend
dsemailserver.close


	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist_AGN where id='"&dsemailpdlist ("id")&"' and agent1='"&ds("agent1")&"'"
	agnserverid.Open Sql,conn,1,1
if not agnserverid.Eof then
if  agnserverid ("ServerlistID")<>0 then ServerlistID=agnserverid ("ServerlistID")
end if

Set dsphemail = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Email where byhost='"&dsph ("id")&"'"
	dsphemail.Open Sql,conn,1,3
if dsphemail.eof then
dsphemail.addnew
dsphemail("username")=ds("username")
dsphemail("ServerlistID")=ServerlistID
dsphemail("Emailtype")=dsemailpdlist("Emailtype")

dsphemail("starttime")=starttime
dsphemail("endtime")=temptime
dsphemail("byhost")=dsph("id")
dsphemail("istest")="n"
dsphemail("emailcount")=dsemailpdlist("emailcount")
dsphemail("userspacelimt")=dsemailpdlist("userspacelimt")
dsphemail("domainspacelimt")=dsemailpdlist("domainspacelimt")
dsphemail("domainmustsame")=dsemailpdlist("domainmustsame")
dsphemail("status")="正常"
if ds("agent1")<>"n" then
dsphemail("agent1")=ds("agent1")
else
dsphemail("agent1")="n"
end if
dsphemail.update
dsphemail.close

'log
	Set dsphemail = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Email where starttime='"&starttime&"' and username='"&ds("username")&"'"
	dsphemail.Open Sql,conn,1,1
FreeHost_oplog session("username"),"信息","用户升级虚拟主机("&dsph ("Ftpname")&")赠送邮箱ID:"&dsphemail("id")
retemail="赠送的邮箱产品已开通"
else

dsphemail("username")=ds("username")
'dsphemail("ServerlistID")=dsemailpdlist("ServerlistID")
ServerlistID=dsphemail("ServerlistID")
dsphemail("Emailtype")=dsemailpdlist("Emailtype")

'dsphemail("starttime")=starttime'不用改升级时间
dsphemail("endtime")=temptime
dsphemail("byhost")=dsph("id")
dsphemail("istest")="n"
dsphemail("emailcount")=dsemailpdlist("emailcount")
dsphemail("userspacelimt")=dsemailpdlist("userspacelimt")
dsphemail("domainspacelimt")=dsemailpdlist("domainspacelimt")
dsphemail("domainmustsame")=dsemailpdlist("domainmustsame")
dsphemail("status")="正常"
if ds("agent1")<>"n" then
dsphemail("agent1")=ds("agent1")
else
dsphemail("agent1")="n"
end if
dsphemail.update
'dsphemail.close
Set dspdallemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select top 1 * from FreeHost.FreeHost_Product_ALLEmail where username='"&ds ("username")&"' and PdEID='"&dsphemail ("id")&"'"
		dspdallemail.Open Sql,conn,1,3
if not dspdallemail.Eof then
emailname=trim(dspdallemail("emailname"))
emailarry=split(emailname,"@")
name1=emailarry(0)
domain=lcase(trim(emailarry(1)))
op=0
'temp2=PauseEmail(dsph ("ServerlistID"),dspdallemail("emailname"),op)

Set dsphemaillist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist where Emailtype='"&dsphemail ("Emailtype")&"'"
	dsphemaillist.Open Sql,conn,1,1
tem=ModAdmEmail(ServerlistID,trim(dspdallemail("emailname")),domain,dsphemail ("emailcount"),dsphemail ("domainspacelimt")*1024)'maxuser
end if

end if
end if







'SQL
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")

dim softtype,MySQLver,MSSQLver

Set dsphSql = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Sql where byhost='"&dsph ("id")&"'"
	dsphSql.Open Sql,conn,1,1

If Not dsphSql.eof Then'当已有SQL附属于这个主机时
'检查新产品有没有送的库,如果有,就更新库大小
Set dsphSql = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Sql where byhost='"&dsph ("id")&"'"
	dsphSql.Open Sql,conn,1,3
while Not dsphSql.eof
	Set dsserverSQL = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSqllist where id='"&dsphSql ("ServerlistID")&"'"
	dsserverSQL.Open Sql,conn,1,1
if not dsserverSQL.Eof Then
	
	Set dsSqlpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_SqlProductlist where Hosttype='"&dshost("Hosttype")&"' and isbyhost='y'"
'response.write sql
'response.end
	dsSqlpdlist.Open Sql,conn,1,1
while not dsSqlpdlist.Eof
	Set dsserverSQLold = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSqllist where (id='"&dsSqlpdlist ("ServerlistID")&"' or id='"&dsSqlpdlist ("ServerlistID2")&"' or id='"&dsSqlpdlist ("ServerlistID3")&"' or id='"&dsSqlpdlist ("ServerlistID4")&"' or id='"&dsSqlpdlist ("ServerlistID5")&"') and softtype='"&dsserverSQL("softtype")&"'"
	dsserverSQLold.Open Sql,conn,1,1
if not dsserverSQLold.Eof Then

dsphSql ("Sqltype")=dsSqlpdlist("Sqltype")
dsphSql ("userspacelimt")=dsSqlpdlist("userspacelimt")
dsphSql ("logspacelimt")=dsSqlpdlist("logspacelimt")
if dsphSql("istest")="y" then
dsphSql("istest")="n"
end if
dsphSql("status")="正常"
dsphSql ("endtime")=temptime
dsphSql.update

FreeHost_oplog session("username"),"信息","用户升级虚拟主机("&dsph ("Ftpname")&")据库产品同步升级,数据库名:"&sqlname&" ID:"&dsphSql("id")&"返回信息："&retsql


URL=dsserverSQL("site")
FreeHostsharekey=dsserverSQL("FreeHostsharekey")
userid=dsserverSQL ("admname")
pwd=dsserverSQL("admpass")
homedir=dsserverSQL("homedir")
ip=dsserverSQL("ip")
port=dsserverSQL("port")
userspacelimt=dsphSql("userspacelimt")
logspacelimt=dsphSql("logspacelimt")
sqlname=dsphSql("sqlname")

'dim softtype,MySQLver,MSSQLver
softtype=dsserverSQL("softtype")
MySQLver=dsserverSQL("MySQLver")
MSSQLver=dsserverSQL("MSSQLver")

if softtype="SQL2000" then
ret=SqlModify(URL,FreeHostsharekey,userid,pwd,userspacelimt,logspacelimt,sqlname)
end if

End if'存在同样类型的数据库
dsSqlpdlist.movenext
Wend
End if'有这个服务器定义
dsphSql.movenext
wend

else'当没有SQL附属于这个主机时
	Set dsSqlpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_SqlProductlist where Hosttype='"&dshost("Hosttype")&"' and isbyhost='y'"
If IsNumeric(Request.Form ("dsSqlpdlistID"&Request.Form ("Hostlistid"))) And Request.Form ("dsSqlpdlistID"&Request.Form ("Hostlistid"))<>"" Then Sql="Select * from FreeHost.FreeHost_SqlProductlist where Hosttype='"&dshost("Hosttype")&"' and id='"&Request.Form ("dsSqlpdlistID"&Request.Form ("Hostlistid"))&"' and isbyhost='y'"

'response.write sql
'response.end
'If canselectdb Then '只能选一个库

	dsSqlpdlist.Open Sql,conn,1,1
'if not dsSqlpdlist.Eof then
while not dsSqlpdlist.Eof


'2008-2-14修改bug
ServerlistID=dsSqlpdlist ("ServerlistID")
	Set dsSqlserver = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Serversqllist where netby='"&netby&"' and agent1='n'"

		dsSqlserver.Open Sql,conn,1,1
while not dsSqlserver.Eof
 if (dsSqlpdlist ("ServerlistID")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID2")=dsSqlserver("id")  or dsSqlpdlist ("ServerlistID3")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID4")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID5")=dsSqlserver("id")) then
 ServerlistID=dsSqlserver("id")'优先选择可选机房中的同机房
 end if
 dsSqlserver.movenext
wend
dsSqlserver.Requery
while not dsSqlserver.Eof
 if ip=dsSqlserver("ip") and (dsSqlpdlist ("ServerlistID")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID2")=dsSqlserver("id")  or dsSqlpdlist ("ServerlistID3")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID4")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID5")=dsSqlserver("id")) then
 ServerlistID=dsSqlserver("id")'优先选择可选机房中的同一IP
 end if
  dsSqlserver.movenext
wend
dsSqlserver.close

	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_SqlProductlist_AGN where id='"&dsSqlpdlist("id")&"' and agent1='"&ds("agent1")&"'"
	agnserverid.Open Sql,conn,1,1
if not agnserverid.Eof then
if  agnserverid ("ServerlistID")<>0 then ServerlistID=agnserverid ("ServerlistID")
end if

	Set dsserverSQL = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSqllist where id='"&ServerlistID&"'"
	dsserverSQL.Open Sql,conn,1,1
if not dsserverSQL.Eof then

'dim softtype
Set dsphSql = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Sql where byhost='"&dsph ("id")&"' and ( ServerlistID='"&dsSqlpdlist ("ServerlistID")&"' or ServerlistID='"&dsSqlpdlist ("ServerlistID2")&"' or ServerlistID='"&dsSqlpdlist ("ServerlistID3")&"' or ServerlistID='"&dsSqlpdlist ("ServerlistID4")&"' or ServerlistID='"&dsSqlpdlist ("ServerlistID5")&"' )"
	dsphSql.Open Sql,conn,1,3

if dsphSql.eof then

dsphSql.addnew
dsphSql("username")=ds("username")
dsphSql("ServerlistID")=ServerlistID
dsphSql("Sqltype")=dsSqlpdlist("Sqltype")
dsphSql("starttime")=starttime
dsphSql("endtime")=temptime
dsphSql("byhost")=dsph("id")
dsphSql("istest")="n"

Randomize
id=id&Int((10 - 0 + 1) * Rnd + 0)
sqlname="a"&right("00"& month(Now),2)& right("00" & day(Now),2)& right("00" & hour(Now),2)& right("00"& Minute(Now),2)& right( "00"& second(Now),2)&id
Randomize
id=id&Int((10 - 0 + 1) * Rnd + 0)
sqlpassword="a"&right("00"& month(Now),2)& right("00" & day(Now),2)& right("00" & hour(Now),2)& right("00"& Minute(Now),2)& right( "00"& second(Now),2)&id
'dsphSql("Sqlcount")=dsSqlpdlist("Sqlcount")
dsphSql("userspacelimt")=dsSqlpdlist("userspacelimt")
dsphSql("logspacelimt")=dsSqlpdlist("logspacelimt")
dsphSql("sqlname")=sqlname
dsphSql("sqlpassword")=sqlpassword
dsphSql("status")="等待开通"
if ds("agent1")<>"n" then
dsphSql("agent1")=ds("agent1")
else
dsphSql("agent1")="n"
end if
dsphSql.update

URL=dsserverSQL("site")
FreeHostsharekey=dsserverSQL("FreeHostsharekey")
userid=dsserverSQL ("admname")
pwd=dsserverSQL("admpass")
homedir=dsserverSQL("homedir")
ip=dsserverSQL("ip")
port=dsserverSQL("port")
userspacelimt=dsphSql("userspacelimt")
logspacelimt=dsphSql("logspacelimt")
sqlname=dsphSql("sqlname")
sqlpassword=dsphSql("sqlpassword")
'ret=SqlAdd(URL,userid,pwd,homedir,userspacelimt,logspacelimt,sqlname,sqlpassword)
'response.write ret


softtype=dsserverSQL("softtype")
MySQLver=dsserverSQL("MySQLver")
MSSQLver=dsserverSQL("MSSQLver")

if softtype="SQL2000" then
retsql=SqlAdd(URL,FreeHostsharekey,userid,pwd,homedir,userspacelimt,logspacelimt,sqlname,sqlpassword)
else
retsql=SqlAddmysql(URL,FreeHostsharekey,userid,pwd,homedir,userspacelimt,logspacelimt,sqlname,sqlpassword)
end if

dsphSql.close


'log
	Set dsphSql = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where sqlname='"&sqlname&"' and username='"&ds("username")&"'"
	dsphSql.Open Sql,conn,1,3
	dsphSql("status")="正常"
	dsphSql.update
FreeHost_oplog session("username"),"信息","用户升级虚拟主机("&dsph ("Ftpname")&")赠送数据库,数据库名:"&sqlname&" ID:"&dsphSql("id")&"返回信息："&retsql

'dim Subject,body
EmailUserSQLOpen
ret=Send2Mail(conn,ds("username"),Subject,body)
'如果是从没有数据库升级到有数据库
else
'原来有数据库
'更新产品类别
while not dsphSql.Eof
dsphSql ("Sqltype")=dsSqlpdlist("Sqltype")
dsphSql ("userspacelimt")=dsSqlpdlist("userspacelimt")
dsphSql ("logspacelimt")=dsSqlpdlist("logspacelimt")
if dsphSql("istest")="y" then
dsphSql("istest")="n"
end if
dsphSql("status")="正常"
dsphSql ("endtime")=temptime
dsphSql.update

FreeHost_oplog session("username"),"信息","用户升级虚拟主机("&dsph ("Ftpname")&")据库产品同步升级,数据库名:"&sqlname&" ID:"&dsphSql("id")&"返回信息："&retsql


URL=dsserverSQL("site")
FreeHostsharekey=dsserverSQL("FreeHostsharekey")
userid=dsserverSQL ("admname")
pwd=dsserverSQL("admpass")
homedir=dsserverSQL("homedir")
ip=dsserverSQL("ip")
port=dsserverSQL("port")
userspacelimt=dsphSql("userspacelimt")
logspacelimt=dsphSql("logspacelimt")
sqlname=dsphSql("sqlname")

softtype=dsserverSQL("softtype")
MySQLver=dsserverSQL("MySQLver")
MSSQLver=dsserverSQL("MSSQLver")

if softtype="SQL2000" then
ret=SqlModify(URL,FreeHostsharekey,userid,pwd,userspacelimt,logspacelimt,sqlname)
end if
dsphSql.movenext
wend
'完成更新
end if

end If

dsSqlpdlist.movenext
wend
end if'有与没有都处理完




%>
<!--#include virtual="/inc-freehost-function/template-hostadm-top.asp"-->
　虚拟主机升级

<%
'调用开通function
AccessFlags=1
if dshost("asp")="y" then
AccessFlags=513
ScriptMaps=dsserver("asp") 
end if

if dshost("aspx")="y" then
AccessFlags=513
netver=dsserver("netver")
If Not IsNull(dshost("netver")) Then netver=dshost("netver")
If netver="1.1" Then ScriptMaps=ScriptMaps&"|"&dsserver("aspx") 
If netver="2.0" Then ScriptMaps=ScriptMaps&"|"&dsserver("aspx2") 
If netver="4.0" Then ScriptMaps=ScriptMaps&"|"&dsserver("aspx4") 
dsph("netver")=netver
end If

if dshost("cgi")="y" then
AccessFlags=517
end if
if dshost("php")="y" then
AccessFlags=513
ScriptMaps=ScriptMaps&"|"&dsserver("php") 
end If
if dshost("notuserar")="y" then
ScriptMaps=ScriptMaps&"|"&dsserver("notuserar") 
end if
if dsserver("infosafe")<>""  And AccessFlags>1 then
ScriptMaps=ScriptMaps&"|"&dsserver("infosafe") 
end if
ScriptMaps=trim(replace(ScriptMaps,"||","|"))

URL=dsserver("site")
'username=dsph ("Ftpname")
'password=dsph("Ftppassword")
'comment=dsph ("username")
'homedir=dsserver("homedir")
homedir=""
spacelimit=dshost ("spacelimt")
'starttime=dsph("starttime")
'endtime=dsph("endtime")
type1=dsph("Hosttype")
'email=ds("email")
'host=dsph("hostname")
'hostcomment_arry=Split(host, ",")
'hostcomment=Replace(hostcomment_arry(0),":80:","")&"_"&username&"_"&dsph ("username")
MaxConnections=dshost ("MaxConnections")
EnumAppsInPool=dshost ("AppPoolnum")
MaxBandwidth=dshost("MaxBandwidth")
'DefaultDoc=""'dshost ("DefaultDoc")
ScriptMaps=ScriptMaps
AccessFlags=AccessFlags
'LogFileDirectory=""'dsserver ("LogFileDirectory")
'HttpErrors=""'Request.Form ("HttpErrors")

'response.write MaxBandwidth
'response.end
FreeHostsharekey=dsserver("FreeHostsharekey")
'Response.Write 

If ostype="windows" Then
returnstr = ShowUser2(URL,FreeHostsharekey,username)
MaxConnectionsNow=CDbl(GETvalue(returnstr,";IIS连接数：",";带宽限制："))
MaxBandwidthNow=CDbl(GETvalue(returnstr,";带宽限制：",";主机头名："))

MaxConnections=CDbl(MaxConnections)+MaxConnectionsNow-CDbl(MaxConnectionsOLD)
MaxBandwidth=CDbl(MaxBandwidth)+MaxBandwidthNow-CDbl(MaxBandwidthOLD)
End if

dsph.update


If Not IsNull(dsph("CurPoolname")) Then
dsph("AppPoolnum")=dshost("AppPoolnum")'2011
dsph("CurPoolname")=Null
dsph.update
'response.write "新的受控..........."
'新的受控
CurPoolname=dsph("AppPoolnum")&"_FreeHost_1"
Curpoolid=1
haneemptypool=False
	Set dsPooldist = Server.CreateObject("ADODB.Recordset")	
Sql="Select distinct CurPoolname from FreeHost.FreeHost_Product_Host where serverlistid='"&dsph("ServerlistID")&"' and hosttype<>'子目录绑定' and AppPoolnum='"&EnumAppsInPool&"' and CurPoolname is not null and CurPoolname like '"&EnumAppsInPool&"_F%' order by CurPoolname Asc"
	dsPooldist.Open Sql,conn,1,1
'	response.write sql
If dsPooldist.Eof Then haneemptypool=true'一个这样的池也没有
Do Until dsPooldist.Eof
CurPoolname=dsPooldist("CurPoolname")
If CInt(Replace(CurPoolname,dsph("AppPoolnum")&"_FreeHost_",""))>Curpoolid Then Curpoolid=CInt(Replace(CurPoolname,dsph("AppPoolnum")&"_FreeHost_",""))
'response.write "<br>"&CurPoolname&"<br>"
Set dsCurPcount = Server.CreateObject("ADODB.Recordset")	
Sql="Select count(*) from FreeHost.FreeHost_Product_Host where serverlistid='"&dsph("ServerlistID")&"' and hosttype<>'子目录绑定' and CurPoolname='"&CurPoolname&"'"
	dsCurPcount.Open Sql,conn,1,1
'	response.write dsCurPcount(0)&"<br>"
	If dsCurPcount(0)<CInt(EnumAppsInPool) Then'池没装完
	If dsCurPcount(0)>0 Then CurPoolname=dsPooldist("CurPoolname")'池名不变
	haneemptypool=true
	Exit do
	End if
	dsCurPcount.close
dsPooldist.movenext
loop
dsPooldist.close
if haneemptypool=False Then CurPoolname=EnumAppsInPool&"_FreeHost_"&CStr(Curpoolid+1)
dsph("CurPoolname")=CurPoolname
dsph.update
End If


if isuseCDN=true Then host=Replace(host,":80:",":"&CDNORIport&":")
If Not IsNull(dsph("CurPoolname")) Then
outpoolname=dsph("CurPoolname")
op=1
temp="新受控"&ModifyUser3(URL,FreeHostsharekey,username,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth,outpoolname,op)
else
temp=ModifyUser2(URL,FreeHostsharekey,username,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
End if


FreeHost_oplog session("username"),"信息","用户自己升级虚拟主机: "&temp

if dsph("status")="暂停" Then
if dsph("beianstatus")="备案成功" Or (dsph("pausereason")<>4 and dsph("pausereason")<>2) then
op=0
Response.Write PauseSite(URL,FreeHostsharekey,username,tourl,op)
Response.Write FTPOP(URL,FreeHostsharekey,username,0)
dsph("status")="正常"
dsph("pausereason")=0
dsph.update
End if
end if

dsph("CDNMaxMb")=dshost("CDNMaxMb")
dsph("Maxbytes")=dshost("Maxbytes")
dsph("MaxCPU")=dshost("MaxCPU")

dsph("canseelog")=dshost("canseelog")
dsph("canrar")=dshost("canrar")
dsph("canback")=dshost("canback")
dsph("canrecypool")=dshost("canrecypool")
dsph("canchnetver")=dshost("canchnetver")
dsph("notuserar")=dshost("notuserar")

dsph("spacelimt")=null
dsph("MaxConnections")=null
dsph("MaxBandwidth")=null
dsph("AppPoolnum")=dshost("AppPoolnum")'2011

If dsph("allowsub")="n" then
dsph("allowsub")=dshost("allowsub")
dsph("subweb")=dshost("subweb")
dsph("useper")=100
Else
dsph("subweb")=dshost("subweb")
End If

dsph.update

'处理子目录绑定
Set dsphsub = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&dsph("id")&"'"
	dsphsub.Open Sql,conn,1,3
while not dsphsub.eof
IISID=dsphsub("IISID")
op=0
if dsph("beianstatus")="备案成功" Or (dsph("pausereason")<>4 and dsph("pausereason")<>2) then
Response.Write PauseSiteSub(URL,FreeHostsharekey,IISID,tourl,op)
dsphsub("status")="正常"
dsphsub("pausereason")=0
End If
dsphsub("endtime")=temptime
dsphsub.update
dsphsub.movenext
wend
dsphsub.close

%>
<br>
<br>
<table width="65%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td height="39" colspan="4"><font color="#000000">　　　</font><font color="#990000"><font color="#FF0000">恭喜您的虚拟主机升级成功，以下是您的资料：</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td width="44%" height="30"><font color="#000000"> 　　　 您的原金额：</font></td>
    <td width="56%" colspan="3"><%=FormatNumber(olduser_money,2,-1,-1,0)%> 元</td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="41"><font color="#000000">　　　 您的金额变化：</font></td>
    <td colspan="3"><font color=red><%=moneych%> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 您的新金额：</font></td>
    <td colspan="3"><font color="#000000"><%=FormatNumber(newuser_money,2,-1,-1,0)%> 元</font></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 到期时间是:</font></td>
    <td colspan="3" bgcolor="#eeeeee"><%=temptime%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td colspan="4"><font color="#000000">　　　</font><font color="#000000">　　　</font><font color="#000000">　</font><font color="#000000">　　　</font><font color="#000000">　　　</font><font color="#000000"> 　　　</font> 　</td>
  </tr>
  <tr align="center" bordercolor="#000000">
    <td height="34" colspan="4" bgcolor="#999999"><font color="#990000">　我　们　为　您　提　供　优　质　的　服　务！</font></td>
  </tr>
</table>
<br>
<br>
<!--#include virtual="/inc-freehost-function/template-hostadm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>