<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("canadmvpsset")="" 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 trim(Request.Form ("starttime"))<>"" And trim(Request.Form ("endtime"))="" Then
	ef=True
	ec="手工指定开通时间时，必须填写到期时间及扣除金额！"
ElseIf not IsDate(Request("starttime")) and Request("starttime")<>""  Then
	ef=True
	ec="请输入合法的开始日期！"
ElseIf not IsDate(Request("endtime")) and Request("endtime")<>""  Then
	ef=True
	ec="请输入合法的到期日期！"
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_VPS where id='"&Request.Form ("id")&"'"
	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="VPS不存在！"
end if
end If

if not ef then
if Not dsph("isagentpd")=true 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='"&dsph("username")&"'"
		ds.Open Sql,conn,1,3
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if


if not ef then
	Set dshost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_VPSProductlist where VPStype='"&dsph ("VPStype")&"'"
	dshost.Open Sql,conn,1,1
if dshost.Eof then
	ef=True
	ec="产品类型不存在！"
Else
'读取月付
PAY_Month=dshost("PAY_Month")
PAY_Season=dshost("PAY_Season")
PAY_halfyear=dshost("PAY_halfyear")
PAY_Nextyear=dshost("PAY_Nextyear")
if dsph("istest")="y" then PAY_Nextyear="1"
PAY_2year=dshost("PAY_2year")
PAY_3year=dshost("PAY_3year")
PAY_4year=dshost("PAY_4year")
PAY_5year=dshost("PAY_5year")
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_2year and Request.Form ("year")<>PAY_3year and Request.Form ("year")<>PAY_4year and Request.Form ("year")<>PAY_5year and Request.Form ("year")<>PAY_Nextyear Then
	ef=True
	ec="请选择时间！"
end If
end If

if not ef Then
if dshost("cancloud")=true then'是弹性购买产品
Dim cloudAddmoney
cloudAddmoney=0
if (dsph("CpuNum")>dsHost("CpuNum")) then	cloudAddmoney=cloudAddmoney+((dsph("CpuNum")-dsHost("CpuNum"))/dsHost("addCpuNum"))*dsHost("addCpuCost")
if (dsph("MAXRAM")>dsHost("MAXRAM")) then	cloudAddmoney=cloudAddmoney+((dsph("MAXRAM")-dsHost("MAXRAM"))/dsHost("addRamNum"))*dsHost("addRamCost")
if (dsph("Maxspace")>dsHost("Maxspace")) then	cloudAddmoney=cloudAddmoney+((dsph("Maxspace")-dsHost("Maxspace"))/dsHost("addVHDNum"))*dsHost("addVHDCost")
if (dsph("Maxmbps8")>dsHost("Maxmbps8")) then	cloudAddmoney=cloudAddmoney+((dsph("Maxmbps8")-dsHost("Maxmbps8"))/dsHost("addMbpsNum"))*dsHost("addMbpsCost")
If dsHost("CDNMaxMb")>0 then'如果限制流量
if (dsph("CDNMaxMb")>dsHost("CDNMaxMb")) then	cloudAddmoney=cloudAddmoney+((dsph("CDNMaxMb")-dsHost("CDNMaxMb"))/1000/dsHost("addNGBNum"))*dsHost("addNGBCost")
End If
If dsHost("MaxIOPS")>0 then'如果限制IOPS
if (dsph("MaxIOPS")>dsHost("MaxIOPS")) then	cloudAddmoney=cloudAddmoney+((dsph("MaxIOPS")-dsHost("MaxIOPS"))/dsHost("addIOPSNum"))*dsHost("addIOPSCost")
End if
if (dsph("MaxSNA")>dsHost("MaxSNA")) then	cloudAddmoney=cloudAddmoney+((dsph("MaxSNA")-dsHost("MaxSNA"))/dsHost("addSnaNum"))*dsHost("addSnaCost")
if (dsph("MaxBak")>dsHost("MaxBak")) then	cloudAddmoney=cloudAddmoney+((dsph("MaxBak")-dsHost("MaxBak"))/dsHost("addBakNum"))*dsHost("addBakCost")
if (dsph("MaxIP")>dsHost("MaxIP")) then	cloudAddmoney=cloudAddmoney+((dsph("MaxIP")-dsHost("MaxIP"))/dsHost("addIpNum"))*dsHost("addIPCost")
cloudAddmoney=Clng(FormatNumber(cloudAddmoney,0,-1,0,0))'四舍五入
end If
End if


if not ef then
if Request.Form ("endtime")<>"" and Request.Form ("usermoney")="" then
	ef=True
	ec="手工指定时间必须填写扣除金额"
end if
end if

if not ef then
olduser_money=ds("usermoney")
if Request.Form ("usermoney")="" then
cost=dshost("usermoney")
if dshost("cancloud")=true then'是弹性购买产品
cost=cost+cloudAddmoney
End if
cost=cost*Request.Form ("year")
else
cost=Clng(Request.Form ("usermoney"))
end If
if cost>ds("usermoney") then
	ef=True
	ec="很抱歉,用户的余额不足！共需:"&cost&"元"
end if
end if


if not ef then
'结束时间
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)

if trim(Request.Form ("endtime"))<>"" then temptime=Request.Form ("endtime")
end if

if not ef then

'开始扣费
ds("usermoney") =ds("usermoney") -cost
ds.update
'更新产品类别
'dsph ("Hosttype")=dshost("Hosttype")
'if dsph("istest")="y" then
starttime=dsph ("endtime")

dsph ("endtime")=temptime
dsph("istest")="n"
dsph("emailstatus")=Null
dsph("smsstatus")=null


'end if

newuser_money=ds("usermoney")
temptime=dsph("endtime")
moneych=-cost

pdtype=dsph("VPStype")
logfor="超级管理员延期云服务器"
if trim(Request.Form ("starttime"))<>"" then logfor="超级管理员修改开通云服务器时间原时间:"&starttime&"新时间:"&Request.Form ("starttime")
if trim(Request.Form ("starttime"))<>"" then dsph ("starttime")=Request.Form ("starttime")

dsph.update

FreeHost_moneyNewlog conn,"y","n","y","n","n",isAgnHostSer,-moneych,dsph ("username"),session("admusername"),dsph ("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,session("admusername"),"管理员延期云服务器",logfor,"云服务器产品",dsph("id"),pingzheng,type1,bank,haveget,havecheck

if Len(Request.Form ("endtime"))<3 Then
dsph("isagentpd")=dshost("isagentpd")
dsph("VPSComName")=dshost("VPSComName")
dsph("VPSApiName")=dshost("VPSApiName")
dsph("VPScpdomain")=dshost("VPScpdomain")
dsph("Agnuserid")=dshost("Agnuserid")
dsph("Domain_Agent_nonemd5_6")=dshost("Domain_Agent_nonemd5_6")
dsph("Agnidc")=dshost("Agnidc")
dsph("Agnproductid")=dshost("Agnproductid")
dsph.update

VPSApiName=dsph("VPSApiName")
userid=dsph("Agnuserid")
userstr=md5(dsph("Domain_Agent_nonemd5_6")&"7i24.com")
yearAgn=Request.Form ("year")
idc=dsph("Agnidc")
productid=dsph("Agnproductid")
attach=ds("username")
tar="http://"&VPSApiName&"/api/cloudapi.asp?userid="&userid&"&userstr="&userstr&"&year="&yearAgn&"&vpsname="&dsph ("vpsname")&"&action=renew&attach="&attach
'Response.write tar
temp=ONLY_GET(tar,"")

vpsname=dsph ("vpsname")
FreeHost_oplog session("admusername"),"信息","管理区，管理员开通云服务器产品(外部代理产品):("&vpsname&") "&temp

If InStr(temp,"et=ok") then
Sql="update FreeHost.FreeHost_Product_VPS set status='正常' where vpsname='"&vpsname&"'"
    conn.Execute Sql
Else
Sql="update FreeHost.FreeHost_Product_VPS set status='失败' where vpsname='"&vpsname&"'"
    conn.Execute Sql
'Response.Redirect "e.asp?e=调用上级API时出错，开通失败，但费用已扣，请联系管理员手工处理！出错原因为："&server.urlencode(temp)
End If
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 align="left"><table height="59"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="7" background="img/midtop.gif">&nbsp;</td>
            <td width="90" align="center" valign="middle" background="img/r3.jpg" id="tableTop1" style="Cursor:hand"><a href="admVPS.asp"><font color="#FFFFFF"><strong>云服务器管理</strong></font></a></td>
            <td width="5" background="img/midtop2.gif">&nbsp;</td>
          </tr>
      </table></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>
              </td>
        </tr>
      </table>
        <br>
        <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">VPS延期成功，以下是相关的资料</font></font></td>
                    </tr>
<%if Len(Request.Form ("endtime"))<3 Then%>
					<tr bordercolor="#000000" bgcolor="#E4EAF2">
                      <td width="53%" height="30"><font color="#000000"> 　　　 上级API返回：</font></td>
                      <td width="47%" colspan="3"><%
If InStr(temp,"et=ok") then
Response.write "成功:"
Else
Response.write "失败:"
End If					  
					  
					  %><%=temp%></td>
                    </tr>
<%End if%>

                    <tr bordercolor="#000000" bgcolor="#E4EAF2">
                      <td width="53%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
                      <td width="47%" 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"><%=oldtime%></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%>
