<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
server.ScriptTimeout =240
If session("SQLAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。此功能只有代理可以操作。"
elseIf session("SQLAUID")<>Clng(Request.Form ("id")) Then
	ef=True
	ec="授权非法，有可能是超时造成的。请返回上一步重新操作。"&Request.Form ("id")&"-"&session("SQLAUID")
ElseIf not IsNumeric(session("SQLAUID"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf Request.Form ("newusername")<>"" and RegExpTest("[^A-Za-z0-9]",Request.Form ("newusername")) Then
	ef=True
	ec="转移用户名中有非法字符！"
ElseIf Request.Form ("newusername")="" And Request.Form ("Submit")="马上转移" Then
	ef=True
	ec="请输入转移用户名！"
ElseIf Request("ip1")<>"" And not IsNumeric(replace(Request("ip1"),".","")) Then
	ef=True
	ec="ip1不对"
ElseIf Request("ip2")<>"" And not IsNumeric(replace(Request("ip2"),".","")) Then
	ef=True
	ec="ip2不对"
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_SQL where id='"&session("SQLAUID")&"'"
			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="不存在的邮箱产品ID！"
end if
end If

if not ef then
if dsph("agent1")<>session("agentusername") then
	ef=True
	ec="此邮箱产品ID并不是当前代理名下所有！"
end If
end If

if not ef then
If Request.Form ("Submit")="马上转移" then
	Set dsNew = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where  (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"') and username='"&Request.Form ("newusername")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsNew.Open Sql,conn,1,1
if dsNew.eof then
	ef=True
	ec="要转移的用户不存在或不是您名下的用户!"
end if
end if
end if

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

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

if not ef then
%>
<!--#include virtual="/inc-freehost-function/template-SQLadm-top.asp"-->
　代理 <%=session("agentusername")%> 管理名下用户 <%=dsph("username")%> 的数据库


<br>
<br>
<%
if Request.Form ("Submit")="马上转移" then%>
用户 <%=dsph("username")%> 的数据库成功转移：<br><br>
<%
dsph("username")=Request.Form ("newusername")
response.write "产品已转移到用户："&Request.Form ("newusername")&" 名下。<br>"
'if Request.Form ("changeagn")="y" then
'dsph("agent1")=dsNEW("agent1")
'end if
dsph.update
'dsph.close
end if

URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")


dim softtype,MySQLver,MSSQLver
softtype=dsserver("softtype")
MySQLver=dsserver("MySQLver")
MSSQLver=dsserver("MSSQLver")


userid=dsserver ("admname")
pwd=dsserver("admpass")
homedir=dsserver("homedir")
ip=dsserver("ip")
port=dsserver("port")
userspacelimt=dsph("userspacelimt")
logspacelimt=dsph("logspacelimt")
sqlname=dsph("sqlname")
FreeHostsharekey=dsserver("FreeHostsharekey")

if Request.Form ("Submit")="删除" then
op=2
ret=PauseSQL(URL,FreeHostsharekey,userid,pwd,sqlname,sqlpassword,op)
'dsph("status")="正常"
ret=ret&"删除成功"
homedir=dsserver("homedir")
username=dsph("ftpname")
ftpdir=homedir&"\backup\"&sqlname&"_"&dsph("randir")
varcon=" /E /T /R "&username
todeluser=1
delacl=1
todelftp=1
if not isnull(dsph("ftpendtime")) then
ret = ret&"删除这个库的备份FTP："&DelFTP(URL,FreeHostsharekey,username,ftpdir,varcon,todeluser,delacl,todelftp)
end if
if not isnull(dsph("randir")) then
ret = ret&"删除这个库的备份目录："&DelDir(URL,FreeHostsharekey,ftpdir)
end if

for iipsec=1 to 2
if not isnull(dsph("ip"&iipsec)) then
	Set dsphip = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where (ip1='"&dsph("ip"&iipsec)&"' or ip2='"&dsph("ip"&iipsec)&"') and id<>'"&dsph ("id")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsphip.Open Sql,conn,1,3
if dsphip.Eof then
response.write "删除允许的IP："&dsph("ip"&iipsec)&"<br>"
opvar="del"
ret=ret&OPIpsec(URL,FreeHostsharekey,opvar,dsph("ip"&iipsec),opport)
end if
dsphip.close
end if
next


FreeHost_oplog session("agentusername"),"信息","代理删除"&dsph ("username")&"数据库产品ID:"&dsph ("id")&"返回："&ret

dsph.delete
dsph.close
response.write ret
end if	

%>

<%if isAgnHostSer then%><b>独立模式专有内容：</b><br><br>
<%





if Request.Form ("Submit")="下一步" Then
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='"&dsph ("username")&"'"
		ds.Open Sql,conn,1,1
if ds.eof then
	ef=True
	ec="此用户不是您名下的用户!"&dsph ("username")
end if
end If

if not ef then
olduser_money=ds("usermoney")
oldtime=dsph ("endtime")
'数据库操作：
moneych=0

If Request.Form ("endtime")<>"" Then
dsph ("endtime")=Request.Form ("endtime")
end if
'response.write Request.Form ("endtime")

If Request.Form ("chmoney")<>"" Then
'变更金额
if Request.Form ("usermoney")<>"" then'手工指定变更金额
if Request.Form ("usermoney")>0 then'大于0才能操作
'ds("usermoney")=ds("usermoney")-Request.Form ("usermoney")
moneych=-Request.Form ("usermoney")
End if
end if
end if

newuser_money=ds("usermoney")
temptime=dsph ("endtime")
'ds.update

if Request.Form ("istestch1")="y" or Request.Form ("istestch2")="y" then
dsph("status")="正常"
dsph("istest")="n"
end If

'dim starttime,temptime,pdtype
'pdtype="原类型："&dsph ("SQLtype")&" 新类型："&dshost("SQLtype")

'更新产品类别
'dsph ("SQLtype")=dshost("SQLtype")
dsph ("logspacelimt")=Request.Form("logspacelimt")
dsph ("userspacelimt")=Request.Form("userspacelimt")

'dsph ("domainmustsame")=dshost("domainmustsame")
'dsph("status")="正常"
'starttime=dsph ("endtime")
'temptime=dsph ("endtime")
dsph.update


'dim softtype
softtype=dsserver("softtype")
MySQLver=dsserver("MySQLver")
MSSQLver=dsserver("MSSQLver")
if softtype="SQL2000" then
ret=SqlModify(URL,FreeHostsharekey,userid,pwd,userspacelimt,logspacelimt,sqlname)
FreeHost_oplog session("username"),"信息","独立模板代理修改，SQL2000数据库名:"&sqlname&" 返回信息："&retsql
end If


End If

%>
<br>

<br>
<br>
<table width="75%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr align="center" bgcolor="#CCCCCC">
    <td height="39" colspan="4"><font color="#000000">　　　<font color="#990000">邮箱产品修改成功，以下是相关的资料：</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td width="53%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="47%" 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=red><%=moneych%></font><font color=#FF0000> 元</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">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 原来的到期时间是:</font></td>
    <td colspan="3" bgcolor="#eeeeee"><font color="#000000"><%=oldtime%></font></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"><%=dsph("status")%></td>
  </tr>
</table>
<%=ret%>
<%end If'是下一步


if ef then
Response.Redirect "e.asp?e="&ec
end if
%>

<%end if%>
<br>
<br>
　<a href="selfSQLmodify.asp?id=<%=session("SQLAUID")%>"><font color="#000000">[返回上一页]</font></a>
<!--#include virtual="/inc-freehost-function/template-SQLadm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>