<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMoney.asp"-->
<%
If session("username")="" And session("agentusername")="" 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 not IsNumeric(Request.Form ("year"))  Then
	ef=True
	ec="时间应该是数字！"
elseIf checkscript(Request.Form ("userremindinfo")) Then
	ef=True
	ec="备注有非法字符！如<>script"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")

username=session("username")
If session("agentusername")<>"" Then
username=session("agentusername")
End If

	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&username&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		ds.Open Sql,conn,1,3
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if

if not ef then
	Set dsIDCpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_IDCProductlist where id='"&Request.Form ("id")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsIDCpdlist.Open Sql,conn,1,1
if dsIDCpdlist.Eof then
	ef=True
	ec="产品不存在！"
else

ServerlistID=dsIDCpdlist ("ServerlistID")
	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_IDCProductlist_AGN where id='"&dsIDCpdlist ("id")&"'"
	agnserverid.Open Sql,conn,1,1
if not agnserverid.Eof then
if agnserverid ("ServerlistID")<>0 then
ServerlistID=agnserverid ("ServerlistID")
isAgnIDCSer=true
else
isAgnIDCSer=false
end if
end if
end if
end if

if not ef then
If Request.Form ("year")<>999 and Request.Form ("year")<>dsIDCpdlist("PAY_Month") and Request.Form ("year")<>dsIDCpdlist("PAY_Season")  and Request.Form ("year")<>dsIDCpdlist("PAY_halfyear") and Request.Form ("year")<>1 and Request.Form ("year")<>dsIDCpdlist("PAY_2year") and Request.Form ("year")<>dsIDCpdlist("PAY_3year") and Request.Form ("year")<>dsIDCpdlist("PAY_4year") and Request.Form ("year")<>dsIDCpdlist("PAY_5year") Then
	ef=True
	ec="请选择时间！"
end If
end if

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

if not ef then
if dsIDCpdlist("canbyenduser")="n" And session("agentname")="n" then
	ef=True
	ec="本产品不允许最终用户开通！"
end if
end If

if not ef then
if dsIDCpdlist("canbyagnenduser")="n" And session("agentname")<>"n" then
	ef=True
	ec="本产品不允许用户开通！"
end if
end If

if not ef then
if dsIDCpdlist("canbyagn")="n" And session("AgnRunasUser")=true then
	ef=True
	ec="本产品不允许代理开通！"
end if
end if


if not ef then
if Request.Form ("year")=999 then
	ef=True
	ec="很抱歉,本产品不可以试用！"
end if
end If

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

if not ef then
if Request.Form ("year")=dsIDCpdlist("PAY_Season") and dsIDCpdlist("canseason")="n" then
	ef=True
	ec="很抱歉,本产品不可以季付！"
end if
end if
if not ef then
if Request.Form ("year")=dsIDCpdlist("PAY_halfyear") and dsIDCpdlist("canhalfyear")="n" then
	ef=True
	ec="很抱歉,本产品不可以半年付！"
end if
end if


'if not ef then
'if Request.Form ("year")<>1 and dsIDCpdlist("canshowyear")="n" then
'	ef=True
'	ec="不显示年限时，年的参数只能是1年！"
'end if
'end if


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

if not ef then
Set dsphIDC = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_IDC where username='"&username&"' and istest='y'"
	dsphIDC.Open Sql,conn,1,3
if Request.Form ("year")=999 then
if not dsphIDC.Eof then
	ef=True
	ec="一个用户只能试用一个产品！"
end if
end if
end if

'response.write session("AgnRunasUser")
'response.end

if not ef then
dim starttime,temptime,pdtype,isAgnHostSer
isAgnHostSer=isAgnIDCSer
pdtype=dsIDCpdlist("IDCtype")
starttime=Now
'结束时间
y=Request.Form ("year")
if y=1 then temptime=dateadd("yyyy",1,now)
if y=dsIDCpdlist("PAY_2year") then temptime=dateadd("yyyy",2,now)
if y=dsIDCpdlist("PAY_3year") then temptime=dateadd("yyyy",3,now)
if y=dsIDCpdlist("PAY_4year") then temptime=dateadd("yyyy",4,now)
if y=dsIDCpdlist("PAY_5year") then temptime=dateadd("yyyy",5,now)
if y=dsIDCpdlist("PAY_Month") then temptime=dateadd("y",31,now)
if y=dsIDCpdlist("PAY_Season") then temptime=dateadd("y",92,now)
if y=dsIDCpdlist("PAY_halfyear") then temptime=dateadd("y",182,now)
if y=999 then
temptime=dateadd("y",Application("testtime"),now)
dim isfortest
isfortest=true
end if

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,RsDlist
set RsDlist=dsIDCpdlist
Userpaymoney=dsIDCpdlist("usermoney")
forpayyear=Request.Form ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="IDC产品"
forpayid=dsIDCpdlist("id")
logfor="自动开通新建IDC产品"
pubisagnSer=isAgnIDCSer
AgnRunasUser=session("AgnRunasUser")

If session("agentusername")<>"" Then
AgnRunasUser=True
End If

DoPayMoneyIDC
end if

if not ef then
dsphIDC.addnew
dsphIDC("username")=ds("username")
dsphIDC("ServerlistID")=dsIDCpdlist("ServerlistID")
If IsNumeric(Request.Form ("ServerlistID"))  Then dsphIDC("ServerlistID")=Request.Form ("ServerlistID")
dsphIDC("IDCtype")=dsIDCpdlist("IDCtype")
dsphIDC("starttime")=starttime
dsphIDC("endtime")=temptime
if y=999 then
dsphIDC("istest")="y"
else
dsphIDC("istest")="n"
end if

'dsphIDC("IDCcount")=dsIDCpdlist("IDCcount")
'dsphIDC("userspacelimt")=dsIDCpdlist("userspacelimt")
'dsphIDC("domainspacelimt")=dsIDCpdlist("domainspacelimt")
'dsphIDC("domainmustsame")=dsIDCpdlist("domainmustsame")
'dsphIDC("status")="正常"
dsphIDC("status")="等待处理"
dsphIDC("userremindinfo")=Request.Form("userremindinfo")

dsphIDC("kefu")=ds("kefunow")

dsphIDC("ordertime")=Now

dsphidc("ip1")=0
dsphidc("ip2")=0
dsphidc("ip3")=0
dsphidc("ip4")=0
dsphidc("ip5")=0

if ds("agent1")<>"n" then
dsphIDC("agent1")=ds("agent1")
else
dsphIDC("agent1")="n"
end if
dsphIDC.update
'dsphIDC.close


'log
	Set dsphIDC = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_IDC where starttime='"&starttime&"' and username='"&ds("username")&"'"
	dsphIDC.Open Sql,conn,1,1
Sql="UPDATE [FreeHost].[FreeHost_Moneylog] set pdid='"&dsphIDC("id")&"' where pdid='"&session("moneylog_pdid")&"'"
    conn.Execute Sql

If Application("smsidcopen")=True And (ds("agent1")="n" Or Application("agncangetsms")=True) Then
Dim username
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsidcopencon")
'恭喜！您的数据库产品已经开通，用户名：#用户名#产品类型：#产品类型#到期时间：#到期时间#您的帐户余款是：#金额# 元
smsContent=Replace(smsContent,"#用户名#",ds("username"))
smsContent=Replace(smsContent,"#产品类型#",dsphidc("idctype"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsphidc("endtime"),1))
smsContent=Replace(smsContent,"#金额#",newuser_money)
ret=SendSms(mobi,smsContent,0,Now,"")
End if

dim Subject,body
emailIDCopen
ret=Send2Mail(conn,ds("username"),Subject,body)

if session("agentusername")<>"" Then%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>
<%else%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>
<%End if%>
　 托管/租用类自助开通成功
<%if session("agentusername")<>"" Then%>
<%=htmlwrite("html6")%>
<%else%>
<%=htmlwrite("html3")%>
<%End if%>

<br>
<br>
<br>
<table width="60%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td height="37" colspan="2" bgcolor="#999999"><font color="#000000">　　　</font><font color="#990000"><font color="#FF0000">恭喜您，订单提交成功，以下是您的资料：</font></font></td>
  </tr>
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td width="46%" height="37" align="right" bgcolor="#eeeeee">用户的原金额：</td>
    <td width="54%" height="37" align="left" bgcolor="#eeeeee">　<%=olduser_money%>元</td>
  </tr>
  <tr align="center" bordercolor="#000000" bgcolor="#eeeeee">
    <td height="37" align="right" bgcolor="#eeeeee">用户金额变化：</td>
    <td height="37" align="left"><font color=red>　<%=moneych%>元</font></td>
  </tr>
  <tr align="center" bordercolor="#000000" bgcolor="#eeeeee">
    <td height="40" align="right">用户的新金额：</td>
    <td height="40" align="left">　<%=newuser_money%>元</td>
  </tr>
<%if dsIDCpdlist("canshowyear")="y" then%>
  <tr align="center" bordercolor="#000000" bgcolor="#eeeeee">
    <td height="40" align="right"><font color="#000000">到期时间：</font></td>
    <td height="40" align="left">　<%=temptime%></td>
  </tr>
<%end if%>
  <tr align="center" bordercolor="#000000" bgcolor="#EFEFEF">
    <td height="101" colspan="2"><font color="#990000">　<font color="#000000">请 您 耐 心 等 待 订 单 处 理 完 成。<br>
      <br>
      您可以稍后登陆网站查看 <strong><a href="IDCadm.asp"><font color="#FF0000">自助管理</font></a></strong> 中的<br>
      <br>
      托管租用类的详细处理结果，您也可以马上<a href="/style/info/contact.asp"><strong><font color="#FF0000">联系我们</font></strong></a></font></font></td>
  </tr>
</table>
<br>
<br>
<br>
<br>

<br>
<%if session("agentusername")<>"" Then%>
<%=htmlwrite("html7")%>
<%else%>
<%=htmlwrite("html4")%>
<%End if%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
