<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
Response.Write "此文件已不再使用！请升级"
Response.End

If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.QueryString ("id")="" Then
	ef=True
	ec="请选择产品！"
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 dsdom = Server.CreateObject("ADODB.Recordset")
sql="Select * from FreeHost.FreeHost_Product_Domain where id='"&Request.QueryString ("id")&"' and (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"') order by id desc"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsdom.Open sql,conn,1,3
if dsdom.eof then
	ef=True
	ec="不存在的域名！"
end if
end if

if not ef then
if dsdom("status")<>"预注册成功" then
	ef=True
	ec="处于预注册状态的域名才能确认，请您联系管理员处理，注意所有注册失败的域名请不要重新注册。"
end if
end if

if not ef then
if dsdom("Domain_API")<>2 then
	ef=True
	ec="这是新网的接口。"
end if
end if
if not ef then
'If trim(lcase(dsdom ("username")))=trim(lcase(session("agentusername"))) Then
'	ef=True
'	ec="如果作为代理给自己开通产品，请在代理区--用户管理，用代理名作用户名切换到用户模式！"
'end if
end if

if not ef then
Dim enc
Enddomaintypeid=GetDomaintype(dsdom("Domain"))
end if

if not ef then
	Set dsDlist = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_DomainProductlist where id='"&Enddomaintypeid&"'"
		dsDlist.Open Sql,conn,1,1
if dsDlist.eof then
	ef=True
	ec="管理员没有定义域名的价格，请联系管理员！"
else
usermoney=dsDlist("usermoney")
myrealcost=dsDlist("usermoneyagn")
end if
end if

if not ef then
yearstr=dsdom("years")
if yearstr="" 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='"&dsdom ("username")&"'"
		ds.Open Sql,conn,3,2
if ds.eof then
	ef=True
	ec="此用户不是您名下的用户!"&dsdom ("username")
end if
end if

if not ef then
	Set dspre = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Preopen_Product where username='"&ds ("username")&"' and haveget='n' and type1='"&dsDlist("Domaintype")&"'"
	dspre.Open Sql,conn,1,3
if not dspre.Eof then
if Clng(yearstr)=1 then
havehostget=true
havehostgetcon="赠送"
end if
end if
end if

if not ef then
if DateDiff("s", Application("domainoptime"),NOW )<Application("domainopmax") and Application("domainoplock")=true then
	ef=True
	ec="系统繁忙，前一个操作尚未处理完，请您稍等两分钟后再试，谢谢您的支持。"
end if
end if


if not ef then
Application.lock
Application("domainoptime")=now
Application("domainoplock")=true
Application.unlock
'open
dim starttime,temptime,pdtype
pdtype=dsdom("Domain")
starttime=NOW
temptime=dateadd("yyyy",yearstr,now)

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,regapi
regapi=2
set RsDlist=dsDlist
Userpaymoney=dsDlist("usermoney")
if havehostget=false then
forpayyear=yearstr
else
forpayyear=999
end if
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="域名产品"
forpayid=dsDlist("id")
logfor="(AG)域名注册("&dsdom("Domain")&")"
if havehostget then logfor=logfor&"(虚拟主机赠送免费开通)"
pubisagnSer=isAgnHostSer
AgnRunasUser=session("AgnRunasUser")
session("moneylog_pdid")=dsdom("id")
DoPayMoneyDomainNew
Application.lock
Application("domainoplock")=false
Application.unlock
end if

if not ef then
if havehostget=true then
dspre("haveget")="y"
dsdom("isbyhost")="y"
dsdom("Hosttype")=dspre("type1")
dsdom("byid")=dspre("byid")
dspre.update
dspre.close
'删除重复
		Sql="delete from FreeHost.FreeHost_Preopen_Product where byid="&dsdom("byid")&" and haveget='n'"
  conn.Execute Sql
end if
end if


if not ef then
dsdom("status")="失败"
dsdom.update
Application.lock
Application("domainoptime")=now
Application("domainoplock")=true
Application.unlock
on error resume next

checksum=MD5("Register"+Application("Domain_Agent_username_2")+Application("Domain_Agent_password_2_API")+dsdom("Domain")+dsdom("uemail")+dsdom("uname2"))

postcon="dn="&server.URLEncode(dsdom("Domain"))&"&enc="&enc&"&period="&dsdom("years")&"&client="&Application("Domain_Agent_username_2")&"&uname1="&server.URLEncode(dsdom("uname1"))&"&uname2="&server.URLEncode(dsdom("uname2"))&"&uname3="&server.URLEncode(dsdom("uname2"))&"&uname4="&server.URLEncode(dsdom("uname2"))&"&rname1="&server.URLEncode(dsdom("rname1"))&"&rname2="&server.URLEncode(dsdom("rname2"))&"&ust=CN"&"&uprov="&server.URLEncode(dsdom("uprov"))&"&ucity1="&server.URLEncode(dsdom("ucity1"))&"&ucity2="&server.URLEncode(dsdom("ucity2"))&"&uaddr1="&server.URLEncode(dsdom("uaddr1"))&"&uaddr2="&server.URLEncode(dsdom("uaddr2"))&"&location="&server.URLEncode(dsdom("uaddr1"))&"&uzip="&server.URLEncode(dsdom("uzip"))&"&utelc="&server.URLEncode(dsdom("utelc"))&"&utela="&server.URLEncode(dsdom("utela"))&"&uteln="&server.URLEncode(dsdom("uteln"))&"&ufaxc="&server.URLEncode(dsdom("ufaxc"))&"&ufaxa="&server.URLEncode(dsdom("ufaxa"))&"&ufaxn="&server.URLEncode(dsdom("ufaxn"))&"&ufaxe=&uemail="&server.URLEncode(dsdom("uemail"))&"&aname1="&server.URLEncode(dsdom("uname1"))&"&aname2="&server.URLEncode(dsdom("uname2"))&"&atelc="&server.URLEncode(dsdom("utelc"))&"&atela="&server.URLEncode(dsdom("utela"))&"&ateln="&server.URLEncode(dsdom("uteln"))&"&atele=&afaxc="&server.URLEncode(dsdom("ufaxc"))&"&afaxa="&server.URLEncode(dsdom("ufaxa"))&"&afaxn="&server.URLEncode(dsdom("ufaxn"))&"&afaxe=&aemail="&server.URLEncode(dsdom("uemail"))&"&dns1="&server.URLEncode(dsdom("dns1"))&"&dns2="&server.URLEncode(dsdom("dns2"))&"&checksum="&checksum

retdns=ONLY_POST(Application("API2Register"),Application("API2Register"),postcon)

If Instr(1, retdns, "err=", 1)>0 or Instr(1, retdns, "reg-failure", 1)>0 Or Instr(1, retdns, "Error", 1)>0 then
	ef=True
	ec="操作失败，请联系管理员！请不要重复尝试！代码为："&server.URLEncode (retdns)
	FreeHost_oplog session("agentusername"),"失败","域名注册时由于"&retdns&"等原因操作失败:"&dsdom("Domain")
	dsdom("status")="失败"
end if
If retdns="" then
	ef=True
	ec="操作失败，但款项已扣。请联系管理员！请不要重复尝试！可能的原因是原始注册商的网络不正常"
	FreeHost_oplog session("agentusername"),"失败","款项已扣，域名注册时由于原始注册商的网络不正常等原因操作失败:"&dsdom("Domain")
	dsdom("status")="失败"
end if
dsdom("retdns")=retdns
dsdom.update
Application.lock
Application("domainoplock")=false
Application.unlock
end if

if not ef then
'赠送的邮箱
'开通邮箱
starttime=now
	Set dsemailpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist where Domaintype='"&dsDlist("Domaintype")&"' and isbydomain='y'"
	dsemailpdlist.Open Sql,conn,1,1
if not dsemailpdlist.Eof then
Set dsphemail = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Email where username='"&ds ("username")&"'"
	dsphemail.Open Sql,conn,1,3
dsphemail.addnew
dsphemail("username")=ds("username")
dsphemail("ServerlistID")=dsemailpdlist("ServerlistID")
dsphemail("Emailtype")=dsemailpdlist("Emailtype")
dsphemail("starttime")=starttime
dsphemail("endtime")=temptime
dsphemail("bydomain")=dsdom("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 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("agentusername"),"信息","代理帮用户"&dsphemail ("username")&"开通域名"&dsdom("Domain")&"赠送邮箱产品ID:"&dsphemail("id")
retemail="赠送的邮箱产品已开通"
end if
'结束赠送
end if

if not ef then
'UPDATE
dsdom("starttime")=starttime
dsdom("endtime")=temptime
dsdom("agent1")=ds("agent1")
dsdom("Domaintype")=""
dsdom("status")="正常"
dsdom.update

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

If Application("smsdomainopen")=True And (ds("agent1")="n" Or Application("agncangetsms")=True) Then
Dim username
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsdomainopencon")
'恭喜！您的域名已开通了！用户名：#用户名#域名：#域名#到期时间是：#到期时间#您的帐户余款是：#金额# 元
smsContent=Replace(smsContent,"#用户名#",ds("username"))
smsContent=Replace(smsContent,"#域名#",dsdom("domain"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsdom("endtime"),1))
smsContent=Replace(smsContent,"#金额#",newuser_money)
ret=SendSms(mobi,smsContent,0,Now,"")
End if

end if


if not ef then
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>　操作结果
<%=htmlwrite("html6")%>
<%if Request.QueryString ("op")="d" then%>
<br><br>删除成功。
<%else%>
<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">域名开通成功，以下是用户的资料<%if havehostget then%><font color=red><%=havehostgetcon%></font><%end if%>：</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td width="52%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="48%" 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=#000000><%=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" 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"><%=dsdom("Domain")%></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">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 域名的初始管理密码是：</font></td>
    <td colspan="3" bgcolor="#eeeeee"><%=domainpass%></td>
  </tr>
  <tr align="center" bordercolor="#000000" bgcolor="#eeeeee">
    <td height="39" colspan="4"><font color="#000000"> 新注册的域名会在24小时后生效，<br>
域名的管理密码请五分钟后使用&quot;<a href="listmydomain.asp" target="_blank"><font color="#FF0000">重置密码功能</font></a>&quot;修改一个初始密码。</font></td>
  </tr>

<%If Right(dsdom("Domain"),"7")=".gov.cn" then%>
  <tr align="center" bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39" colspan="4"><font color="#000000"> 注意：<br>
您注册的是.gov.cn类域名，请您联系管理员提交审核材料才能注册成功。
</td>
  </tr>
<%End if%>

</table>
<br><br><br>
<%end if%>
<%=htmlwrite("html7")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
