<%@ 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/FreeHostDomain.asp"-->
<!--#include virtual="/inc-freehost-function/ZPapi.asp"-->
<!--#include virtual="/inc-freehost-function/xml.cls.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("canadmdomain")="" Then
	ef=True
	ec="您没有此操作的权限。"
elseIf session("candomainpay")="" and Request.QueryString ("op")="a" Then
	ef=True
	ec="您没有此操作的权限。"
elseIf session("candomaindel")="" and Request.QueryString ("op")="d" 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")&"'"
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("Domain_API")=4 then
If TOLOGINZP()=true then
	ef=True
	ec="登陆API4域名接口失败，可能是网络忙的原因造成的，请再试一次，或请联系管理员。相关出错信息为:"&server.URLEncode(ZPEC)
end if
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 username='"&dsdom("username")&"'"
		ds.Open Sql,conn,3,2
if ds.eof then
	ef=True
	ec="用户不存在!"
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

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=dsdom("Domain_API")
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="管理区开通(域名"&dsdom("Domain")&")"
if Request.QueryString ("pay")="n" then
forpayyear=999
logfor=logfor&"(管理员设置不扣费)"
end if
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



'赠送的邮箱
'开通邮箱
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("admusername"),"信息","管理员帮用户"&dsphemail ("username")&"开通域名"&dsdom("Domain")&"赠送邮箱产品ID:"&dsphemail("id")
retemail="赠送的邮箱产品已开通"
end if
'结束赠送

Application.lock
Application("domainoptime")=now
Application("domainoplock")=true
Application.unlock

dim returncodevalue,failreason
RegisterDomainNow()

Application.lock
Application("domainoplock")=false
Application.unlock

dsdom.update

end if

if not ef then



'UPDATE
dsdom("starttime")=starttime
dsdom("endtime")=temptime
dsdom("agent1")=ds("agent1")
dsdom("Domaintype")=""
dsdom("status")="正常"
dsdom.update
'action


'pass

if Application("DNS_API")=1 then
dsdom("DNS_API")=Application("DNS_API")
end if
dsdom.update
'mail
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("html8")%>
<%=htmlwrite("html9")%>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0 background="img/midtop4.gif">
  <TBODY>
    <TR>
      <TD width=53 align="left" background="img/midtop1.gif"><strong> 　 </strong><font color="#FFFFFF">─<strong>&gt;</strong></font> </TD>
      <TD width="83"><table height="59"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="7" background="img/midtop.gif">&nbsp;</td>
            <td width="60" align="center" valign="middle" background="img/r3.jpg" id="tableTop1" style="Cursor:hand"><a href="listmydomain.asp"><font color="#FFFFFF">域名管理</font></a><a href="systeminfo.asp"></a><a href="logininfo.asp"></a></td>
            <td width="5" background="img/midtop2.gif">&nbsp;</td>
          </tr>
      </table></TD>
      <TD width="83">&nbsp;</TD>
      <TD width="83">&nbsp;</TD>
      <TD width="83" align="left">&nbsp;</TD>
      <TD align="left">&nbsp;</TD>
      <TD width=23 align="right"><IMG height=59 
                  src="img/rtop4.jpg" 
                  width=19></TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0>
  <TBODY>
    <TR>
      <TD width=19 background="img/midlef.gif" id=rightid>&nbsp;</TD>
      <TD height="300" align="center" vAlign=top bgcolor="#FFFFFF"><br><br>



<DIV class="tableborder">
<table width="65%"  border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FF0000">
  <tr align="center" bordercolor="#000000">
    <td height="24" colspan="4" background="img/tablebg.gif"><font color="#000000">　　　</font><font color="#FFFFFF">域名开通成功，以下是用户的资料
        <%if havehostget then%>      
        <%=havehostgetcon%>        <%end if%>
      ：</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td width="44%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="56%" colspan="3"><font color="#000000"><%=olduser_money%>元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="41"><font color="#000000">　　　 用户的金额变化：</font></td>
    <td colspan="3"><font color=#000000><%=moneych%> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39"><font color="#000000">　　　 用户的新金额：</font></td>
    <td colspan="3"><font color="#000000"><%=newuser_money%> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000">　　　 域名是：</font></td>
    <td colspan="3"><%=dsdom("Domain")%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 到期时间是：</font></td>
    <td colspan="3"><%=temptime%></td>
  </tr>
  <tr align="center" bordercolor="#000000" bgcolor="#E4EAF2">
    <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%>

<%If Right(dsdom("Domain"),"3")=".cn" then%>
  <tr align="center" bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39" colspan="4"><font color="#000000"> 注意：<br>
您注册的是.cn类域名，请马上上传身份证等注册材料,6天内不上传材料到CNNIC则域名将会注册失败。
</td>
  </tr>
<%End if%>

</table>
</div>



</TD>
      <TD width=18 background="img/midri.gif">&nbsp;</TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
    <TR>
      <TD width=30><IMG height=19 
                  src="img/rb1.jpg" 
                  width=30></TD>
      <TD 
                background=img/rb2.jpg>&nbsp;</TD>
      <TD width=30><IMG height=19 
                  src="img/rb3.jpg" 
                  width=30></TD>
    </TR>
  </TBODY>
</TABLE>
<%=htmlwrite("html10")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
