<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("username")="" Then
	ef=True
	ec="请您先登陆用户区，再续费，在主机面板中不能续费。也有可能是超时造成了出错。"
ElseIf Request ("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Instr(1, Request ("id"), "'", 1)>0 then
	ef=True
	ec="非法产品ID！"
ElseIf not IsNumeric(Request ("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
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 dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&Request ("id")&"' and username='"&session("username")&"'"
			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
	Set dshost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist where Hosttype='"&dsph ("Hosttype")&"'"
	dshost.Open Sql,conn,1,1
if dshost.Eof then
	ef=True
	ec="产品类型不存在！"
Else
'读取月付
PAY_Month=dshost("PAY_Month")
PAY_Season=dshost("PAY_Season")
PAY_halfyear=dshost("PAY_halfyear")
PAY_Nextyear=dshost("PAY_Nextyear")
if dsph("istest")="y" then PAY_Nextyear="1"
PAY_2year=dshost("PAY_2year")
PAY_3year=dshost("PAY_3year")
PAY_4year=dshost("PAY_4year")
PAY_5year=dshost("PAY_5year")
packagename=dshost("packagename")'linux
end if
end if

if not ef then
If Request ("year")<>PAY_Month and Request ("year")<>PAY_Season  and Request ("year")<>PAY_halfyear and Request ("year")<>PAY_Nextyear and Request ("year")<>PAY_2year and Request ("year")<>PAY_3year and Request ("year")<>PAY_4year and Request ("year")<>PAY_5year Then
	ef=True'不包含一年,不包含试用,只有续费
	ec="请选择时间！"&Request ("year")
end If
end If

if not ef then
if dsph("istest")="y" then
MaxConnections=dshost ("MaxConnections")
spacelimit=dshost ("spacelimt")
MaxBandwidth=dshost("MaxBandwidth")
end if
end if

if not ef then
if Request ("year")=PAY_Month and dshost("canmonth")="n" then
	ef=True
	ec="很抱歉,本产品不可以月付！"
end if
end if

if not ef then
if Request ("year")=PAY_Season and dshost("canseason")="n" then
	ef=True
	ec="很抱歉,本产品不可以季付！"
end if
end if
if not ef then
if Request ("year")=PAY_halfyear and dshost("canhalfyear")="n" 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
	ostype=dsserver("ostype")'linux
if dsserver("agent1")="n" then
isAgnHostSer=false
else
isAgnHostSer=true
end if
end if
end if

if not ef then
'结束时间
dim starttime,temptime,pdtype
starttime=dsph("endtime")
pdtype=dsph ("Hosttype")
oldtime=dsph("endtime")
if dsph("istest")="y" then  oldtime=now
y=Request ("year")
if y=PAY_Nextyear then temptime=dateadd("yyyy",1,oldtime)
if y=PAY_2year then temptime=dateadd("yyyy",2,oldtime)
if y=PAY_3year then temptime=dateadd("yyyy",3,oldtime)
if y=PAY_4year then temptime=dateadd("yyyy",4,oldtime)
if y=PAY_5year then temptime=dateadd("yyyy",5,oldtime)
if y=PAY_Month then temptime=dateadd("y",31,oldtime)
if y=PAY_Season then temptime=dateadd("y",92,oldtime)
if y=PAY_halfyear then temptime=dateadd("y",182,oldtime)
end if

if not ef then
dim ef,ec,Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser,isRepaymoney,Repaymoney
Userpaymoney=dsHost("usermoney")
forpayyear=Request ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="虚拟主机"
forpayid=dshost("id")
logfor="用户区延期(FTP名"&dsph("Ftpname")&")"
pubisagnSer=isAgnHostSer
AgnRunasUser=session("AgnRunasUser")
if not isnull(dsph("repaymoney")) and not isAgnHostSer then'管理员单独设置续费价格
logfor="用户区延期(单独价格)(FTP名"&dsph("Ftpname")&")"
Repaymoney=dsph("repaymoney")
isRepaymoney=true
else
isRepaymoney=false
end if
DoPayMoney
Sql="UPDATE [FreeHost].[FreeHost_Moneylog] set pdid='"&dsph("id")&"' where pdid='"&session("moneylog_pdid")&"'"
    conn.Execute Sql
end if


if not ef then

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

'更新产品类别
'dsph ("Hosttype")=dshost("Hosttype")
'if dsph("istest")="y" then
dsph ("endtime")=temptime

dsph("emailstatus")=Null
dsph("smsstatus")=null

dsph("istest")="n"
'end if
dsph.update


'送CDN
haveopenCDN=False
	Set dsCDNpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_CDNProductlist where id='"&dshost("CDNpdID")&"'"
	dsCDNpdlist.Open Sql,conn,1,1
if Not dsCDNpdlist.Eof Then
Set dsphCDN = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_CDN where username='"&dsph ("username")&"'"
	dsphCDN.Open Sql,conn,1,3
haveopenCDN=true
dsphCDN("endtime")=temptime
dsphCDN("status")="正常"
dsphCDN("kefu")=ds("kefunow")
dsphCDN.Update
End If


'开通邮箱
Set dsphemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Email where byhost='"&dsph("id")&"' and username='"&session ("username")&"'"
	dsphemail.Open Sql,conn,1,3
if not dsphemail.Eof then
dsphemail("endtime")=temptime
dsphemail("status")="正常"
dsphemail("istest")="n"
dsphemail.update
retemail="赠送的邮箱产品已延期"
dsphemail.close
end if



endtime=dsph("endtime")
dsph.update
homedir=""

'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
dsphSql("endtime")=endtime
dsphSql("istest")="n"
dsphSql("status")="正常"
dsphSql.update
retSql="赠送的数据库产品已延期"
'dsphSql.movenext
	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
dim softtype,MySQLver,MSSQLver
softtype=dsserverSQL("softtype")
MySQLver=dsserverSQL("MySQLver")
MSSQLver=dsserverSQL("MSSQLver")

FreeHostsharekey_SQL=dsserverSQL("FreeHostsharekey")
URL_SQL=dsserverSQL("site")
opport=dsserverSQL("port")
userid=dsserverSQL ("admname")
pwd=dsserverSQL("admpass")
sqlname=dsphSql("sqlname")
sqlpassword=dsphSql("sqlpassword")
op=0
ret=PauseSQL(URL_SQL,FreeHostsharekey_SQL,userid,pwd,sqlname,sqlpassword,op)
End if
'response.write ret
dsphSql.movenext
wend
dsphSql.close

'on error resume next
'Response.Write

If ostype="windows" then
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

'Response.Write temp


if dsph("status")="暂停" Or ostype="linux" Then
op=0
if dsph("beianstatus")="备案成功" Or (dsph("pausereason")<>4 and dsph("pausereason")<>2) then
'Response.Write
temp=PauseSite(URL,FreeHostsharekey,username,tourl,op)
Response.Write "受控IIS操作返回："&temp&"<br>"
'Response.Write 
temp=FTPOP(URL,FreeHostsharekey,username,0)'恢复FTP权限
Response.Write "受控FTP操作返回："&temp&"<br>"
dsph("status")="正常"
dsph("pausereason")=0
Else
Response.Write "不需要操作受控<br>"
End if
dsph.update
End if

'处理子目录绑定
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 
temp=PauseSiteSub(URL,FreeHostsharekey,IISID,tourl,op)
dsphsub("status")="正常"
dsphsub("pausereason")=0
End If
dsphsub("endtime")=endtime
dsphsub.update
dsphsub.movenext
wend
dsphsub.close




%>
<!--#include virtual="/inc-freehost-function/template-hostadm-top.asp"-->
 　虚拟主机自助延期 
 
<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"><%=olduser_money%> 元</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"><%=newuser_money%> 元</font></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000">　　　 原来的到期时间是:</font></td>
    <td colspan="3" bgcolor="#eeeeee"><%=oldtime%></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 现在的到期时间是:</font></td>
    <td colspan="3" bgcolor="#eeeeee"><%=temptime%></td>
  </tr>
<%if haveopenCDN then%>
    <tr bordercolor="#000000">
    <td height="60" bgcolor="#eeeeee"><font color="#000000"> 　　　 CDN说明：</font></td>
    <td bgcolor="#eeeeee"><a href="/user/sqladm.asp"><font color="#000000">附送的CDN产品已延期</font></a></td>
  </tr>
<%end if%>
  <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>
<br>
<!--#include virtual="/inc-freehost-function/template-hostadm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>