<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("HOSTAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。此功能只有代理可以操作。"
ElseIf not IsNumeric(session("HOSTAUID"))  Then
	ef=True
	ec="产品ID应该是数字！"
elseIf session("HOSTAUID")<>clng(Request.Form ("id")) Then
	ef=True
	ec="授权非法，有可能是超时造成的。请返回上一步重新操作。"&Request.Form ("id")&"-"&session("HOSTAUID")
end if

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&session("HOSTAUID")&"'"
			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="不存在的虚拟主机ID！"
end if
end If

if not ef then
if dsph("agent1")<>session("agentusername") then
	ef=True
	ec="此虚拟主机ID并不是当前代理名下所有！"
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 ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"') and username='"&dsph ("username")&"'"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		ds.Open Sql,conn,3,2
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if

if not ef then
	Set dsHostpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist where Hosttype='"&dsph("Hosttype")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsHostpdlist.Open Sql,conn,1,1
if dsHostpdlist.Eof then
	ef=True
	ec="产品类型不存在！"
Else
'读取月付
PAY_Month=dsHostpdlist("PAY_Month")
PAY_Season=dsHostpdlist("PAY_Season")
PAY_halfyear=dsHostpdlist("PAY_halfyear")
PAY_Nextyear=dsHostpdlist("PAY_Nextyear")
if dsph("istest")="y" then PAY_Nextyear="1"
PAY_2year=dsHostpdlist("PAY_2year")
PAY_3year=dsHostpdlist("PAY_3year")
PAY_4year=dsHostpdlist("PAY_4year")
PAY_5year=dsHostpdlist("PAY_5year")
packagename=dsHostpdlist("packagename")'linux
end if
end If

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

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

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

if not ef then
if Request.Form ("year")=PAY_Season and dsHostpdlist("canseason")="n" and Application("Agentcanunlimit")=false then
	ef=True
	ec="很抱歉,本产品不可以季付！"
end if
end if
if not ef then
if Request.Form ("year")=PAY_halfyear and dsHostpdlist("canhalfyear")="n" and Application("Agentcanunlimit")=false 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
dim isAgnHostSer
if dsserver("agent1")=dsph("agent1") then
isAgnHostSer=true
Else
isAgnHostSer=false
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.Form ("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
Userpaymoney=dsHostpdlist("usermoney")
forpayyear=Request.Form ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="虚拟主机"
forpayid=dsHostpdlist("id")
logfor="延期(AG)(FTP名"&dsph("Ftpname")&")"
pubisagnSer=isAgnHostSer
AgnRunasUser=false
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")
'开始扣费
ds.update
'更新产品类别
'dsph ("Hosttype")=dsHostpdlist("Hosttype")
'if dsph("istest")="y" then
dsph ("endtime")=temptime
dsph("istest")="n"
dsph("emailstatus")=Null
dsph("smsstatus")=null
'end if
dsph.update


'送CDN
haveopenCDN=False
	Set dsCDNpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_CDNProductlist where id='"&dsHostpdlist("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

'email
'开通邮箱

Set dsphemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Email where username='"&dsph ("username")&"' and byhost='"&dsph("id")&"'"
	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")


'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")=temptime
dsphSql("istest")="n"
dsphSql("status")="正常"
dsphSql.update
retSql="赠送的数据库产品已延期"
	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


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")="暂停" then
if dsph("beianstatus")="备案成功" Or (dsph("pausereason")<>4 and dsph("pausereason")<>2) then
op=0
outinfo1=PauseSite(URL,FreeHostsharekey,username,tourl,op)
outinfo2=FTPOP(URL,FreeHostsharekey,username,0)
dsph("status")="正常"
dsph("pausereason")=0
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
outinfo3=PauseSiteSub(URL,FreeHostsharekey,IISID,tourl,op)
dsphsub("status")="正常"
dsphsub("pausereason")=0
End If
dsphsub("endtime")=temptime
dsphsub.update
dsphsub.movenext
wend
dsphsub.close




End If


if not ef then
%>
<!--#include virtual="/inc-freehost-function/template-hostadm-top.asp"-->
　代理 <%=session("agentusername")%> 管理名下用户 <%=dsph("username")%> 的虚拟主机 FTP用户名：<%=dsph("ftpname")%>


续费/升级<br>
<br>
<table width="84%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr align="center" bordercolor="#000000" bgcolor="#CCCCCC">
    <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="50%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="50%" colspan="3"><font color="#000000"><%=olduser_money%>元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="41"><font color="#000000">　　　 用户的金额变化：</font></td>
    <td colspan="3"><font color=red><%=moneych%></font><font color=#FF0000> 元</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" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 我的原金额：</font></td>
    <td colspan="3"><font color="#000000"><%=oldagn_money%> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 我的金额变化：</font></td>
    <td colspan="3"><font color=red><%=newagn_money-oldagn_money%></font><font color="#000000"> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 我的新金额：</font></td>
    <td colspan="3"><font color="#000000"><%=newagn_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 color="#FF0000">现在的到期时间是:</font></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%>
</table>
<div align="center"><!--<%=outinfo1%><%=outinfo2%><%=outinfo3%>--></div>
      <br>
      <br>
    
　<a href="selfhostmodify.asp?id=<%=session("HOSTAUID")%>"><font color="#000000">[返回上一页]</font></a>

<!--#include virtual="/inc-freehost-function/template-hostadm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>