<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("canadmidcadd")="" Then
	ef=True
	ec="您没有此操作的权限。"
ElseIf Request.Form ("username")="" Then
	ef=True
	ec="请输入用户名！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) Then
	ef=True
	ec="用户名中有非法字符！"
ElseIf Request.Form ("idctype")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Instr(1, Request.Form ("idctype"), "'", 1)>0 then
	ef=True
	ec="产品类型有非法字符！"
ElseIf Request.Form ("ServerlistID")="" Then
	ef=True
	ec="请选择服务器！"
ElseIf not IsNumeric(Request.Form ("ServerlistID"))  Then
	ef=True
	ec="服务器ID应该是数字！"
ElseIf not IsNumeric(Request.Form ("year"))  Then
	ef=True
	ec="时间应该是数字！"
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='"&Request.Form ("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 idctype='"&Request.Form ("idctype")&"'"
	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="产品不存在！"
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 Request.Form ("usermoney")="" Then
cost=dsidcpdlist("usermoney")
cost=cost*Request.Form ("year")
if Request.Form ("year")=999 then cost=0
if cost>ds("usermoney") then
	ef=True
	ec="很抱歉,用户的余额不足！"
end if
else
cost=Clng(Request.Form ("usermoney"))
if cost>ds("usermoney") then
	ef=True
	ec="很抱歉,用户的余额不足！"
end if
end if
end if

if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")
If Request.Form ("ServerlistID")="0" Then
	Sql="Select * from FreeHost.FreeHost_IDCJG where id='"&dsidcpdlist ("ServerlistID")&"'"
else
	Sql="Select * from FreeHost.FreeHost_IDCJG where id='"&Request.Form ("ServerlistID")&"'"
end if
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="机柜不存在！"
end if
end if

if not ef then

If Request.Form("status")<>"空闲" then
'开始扣费
olduser_money=ds("usermoney")
moneych=0
ds("usermoney") =ds("usermoney") -cost
moneych=-cost
ds.update
End if

newuser_money=ds("usermoney")


	Set dsphidc = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_idc"
	dsphidc.Open Sql,conn,1,3
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)
end if
if request.Form ("endtime")<>"" then temptime=request.Form ("endtime")
dsphidc.addnew
dsphidc("username")=ds("username")
dsphidc("ServerlistID")=dsserver("id")
dsphidc("idctype")=Request.Form("idctype")
dsphidc("status")=Request.Form("status")
dsphidc("admremindinfo")=Request.Form("admremindinfo")

dsphidc("userremindinfo")=Request.Form("userremindinfo")
dsphidc("openinfo")=Request.Form("openinfo")
dsphidc("admname")=Request.Form("admname")
dsphidc("admpass")=Request.Form("admpass")

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

dsphidc("starttime")=starttime
dsphidc("endtime")=temptime
if y=999 then
dsphidc("istest")="y"
dim isfortest
isfortest=true
else
dsphidc("istest")="n"
end if

temptime=dsphidc("endtime")

dsphidc("status")="正常"

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
pdtype=dsphidc("idctype")

If dsphidc("status")<>"空闲" then

FreeHost_moneyNewlog conn,"y","n","y","n","n",isAgnHostSer,-moneych,dsphidc ("username"),session("admusername"),dsphidc ("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,session("admusername"),"管理员开通IDC业务","管理员开通IDC业务","IDC产品",dsphidc("id"),pingzheng,type1,bank,haveget,havecheck
End if

for IPID=1 to 5000
If Request.Form("IPID"&IPID)<>"" and IsNumeric(Request.Form("IPID"&IPID)) Then conn.Execute "update FreeHost.FreeHost_IDCIP set PDID="&dsphidc("id")&" where ID="&Request.Form("IPID"&IPID)
Next

If dsphidc("status")<>"空闲" then
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)
End if
%>
<!--#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="admidc.asp"><font color="#FFFFFF">IDC管理</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">
	  

<table width="65%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	
	
	<br><DIV class="tableborder">
<table width="100%"  border="0" align="center" cellpadding="2" cellspacing="1">
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td height="24" colspan="4" background="img/tablebg.gif"><font color="#990000"><font color="#FFFFFF">业务添加成功，以下是相关的资料</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td width="47%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="53%" colspan="3"><%=olduser_money%> 元</td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="41"><font color="#000000">　　　 用户的金额变化：</font></td>
    <td colspan="3"><font color=red><%=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"><%=temptime%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37" colspan="4" align="right" bgcolor="#E4EAF2"><font color="#000000"> 　　　</font><a href="#top"><font color="#6B9EDE" face="Arial, Helvetica, sans-serif">Top↑</font></a>	</td>
    </tr>


</table>
	</div>

	
	
	</td>
  </tr>
</table>

      </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%>
