<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%server.ScriptTimeout =7200
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("cansetagn")="" Then
	ef=True
	ec="您没有此操作的权限。"
elseIf Request.Form ("username")="" or RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) 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_Agent 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 dsC = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_domain where id=0"
		dsC.Open Sql,conn,1,1
if dsC.eof then
	ef=True
	ec="请您先在站点管理,代理折扣中,设置代理使用的临时域名！"
end if
end if

if not ef then
if Request.Form ("agenttype")<>"n" then
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"&Request.Form ("agenttype")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"

Response.End

end if
		dsagnettype.Open Sql,conn,1,1
if dsagnettype.eof then
	ef=True
	ec="代理类型不存在！"
end if
end if
end if

if not ef then
if Request.Form ("pertype")="b" and Request.Form ("agenttype")<>"n" then
if isnull(dsagnettype("template")) then
	ef=True
	ec="请先在管理区，站点管理，代理折扣中，设置好此级别的价格模板代理！"
end if
end if
end if

if not ef then
oritype=ds("agenttype")
ds("agenttype")=Request.Form ("agenttype")
ds("agentdegree")=0
ds("agent1")="n"
ds("agent2")="n"
ds.update




'domain
	Set dsagentdomain = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_ALLdomain where domain='"&replace(Request.Form ("username")&"."&dsC ("domain"),"..",".")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
'		response.write sql
		dsagentdomain.Open Sql,conn,1,3
		if dsagentdomain.eof then
		dsagentdomain.addnew
		end if
		dsagentdomain("username")=Request.Form ("username")
		dsagentdomain("domain")=replace(Request.Form ("username")&"."&dsC ("domain"),"..",".")
		dsagentdomain("agent1")="n"
		dsagentdomain("agent2")="n"
		dsagentdomain.update
'		end if




'ds.close
'set ds=nothing

	Set dsreg = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&request.Form ("username")&"'"
		dsreg.Open Sql,conn,1,3
if dsreg.eof then
Set dsagn = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request.Form ("username")&"'"
		dsagn.Open Sql,conn,1,1
If not dsagn.Eof Then
dsreg.AddNew
dsreg("username")=LCASE(trim(dsagn ("username")))
dsreg("password")=dsagn ("password")
dsreg("email")=dsagn ("email")
dsreg("truename")=dsagn ("truename")
dsreg("etruename")=dsagn ("etruename")
dsreg("coun")=dsagn ("coun")
dsreg("ecoun")=dsagn ("ecoun")
dsreg("prv")=dsagn ("prv")
dsreg("eprv")=dsagn ("eprv")
dsreg("city")=dsagn ("city")
dsreg("ecity")=dsagn ("ecity")
dsreg("address")=dsagn ("address")
dsreg("eaddress")=dsagn ("eaddress")
dsreg("postid")=dsagn ("postid")
dsreg("tel")=dsagn ("tel")
dsreg("qq")=dsagn ("qq")
'dsreg("perid")=dsagn ("perid")

dsreg("kefunow")=dsagn ("kefunow")

dsreg("regtime")=NOW
dsreg("lastuse")=NOW
dsreg("regip")=Request.ServerVariables("REMOTE_ADDR")

dsreg("usermoney")="0.00"

dsreg("hostphcount")=0
dsreg("emailphcount")=0
dsreg("domainphcount")=0
dsreg("haveupdate")="y"'3.0
dsreg("agent1")=dsreg("username")
dsreg("agent2")="n"
dsreg.update
end if
else'将用户金额转移到代理名下

if dsreg("usermoney")>0 And ds("agenttype")<>"n" then
olduser_money=dsreg("usermoney")
oldagn_money=ds("usermoney")
ds("usermoney")=ds("usermoney")+dsreg("usermoney")
dsreg("usermoney")=0
dsreg.update
newuser_money=dsreg("usermoney")
ds.update
newagn_money=ds("usermoney")

FreeHost_moneyNewlog conn,"y","n","y","n","n",isAgnHostSer,-(newuser_money-olduser_money),dsreg("username"),session("admusername"),dsreg("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,session("admusername"),"开通代理自动扣除用户金额并转移给代理名下,扣用户所有金额","开通代理自动扣除用户金额并转移给代理名下,扣用户所有金额",whichProduct,pdid,pingzheng,type1,bank,haveget,havecheck

FreeHost_moneyNewlog conn,"n","y","y","n","y",isAgnHostSer,newagn_money-oldagn_money,dsreg("username"),session("admusername"),norusername,norStmoney,norEndmoney,dsreg("username"),oldagn_money,newagn_money,session("admusername"),"开通代理自动扣除用户金额并转移给代理名下增加给新开通的代理","开通代理自动扣除用户金额并转移给代理名下增加给新开通的代理",whichProduct,pdid,pingzheng,type1,bank,haveget,havecheck

out="<br><br>开通代理自动扣除用户金额并转移给代理名下:"&(newagn_money-oldagn_money)&"元"



end if
end if

'删除
Sql="delete from FreeHost.FreeHost_Agent_price where username='"&Request.Form ("username")&"'"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
    conn.Execute Sql

'删除
Sql="delete from FreeHost.FreeHost_Agent_user_price where username='"&Request.Form ("username")&"'"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
    conn.Execute Sql

if Request.Form ("agenttype")<>"n" then'不取消代理时
if Request.Form ("pertype")="b" then'使用别的代理价格模板时

Set dsagnpri = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Agent_price where username='"&dsagnettype("template")&"'"
'response.write sql
	dsagnpri.Open Sql,conn,3,3
while not dsagnpri.eof

Set dsagnpri2 = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where username='"&Request.Form ("username")&"'"
'response.write sql
	dsagnpri2.Open Sql,conn,1,3
	dsagnpri2.addnew
	dsagnpri2("id")=dsagnpri("id")
	dsagnpri2("username")=trim(lcase(Request.Form ("username")))
	dsagnpri2("prtype")=dsagnpri("prtype")
	dsagnpri2("usermoney")=dsagnpri("usermoney")
	dsagnpri2("agent1")=dsagnpri("agent1")
	dsagnpri2("agent2")=dsagnpri("agent2")
	dsagnpri2("usermoneyrepay")=dsagnpri("usermoneyrepay")
	dsagnpri2("usermoneyrepay2")=dsagnpri("usermoneyrepay2")
	dsagnpri2("usermoneyrepay3")=dsagnpri("usermoneyrepay3")
	dsagnpri2("usermoneyrepay4")=dsagnpri("usermoneyrepay4")
	dsagnpri2("usermoneyrepay5")=dsagnpri("usermoneyrepay5")
	dsagnpri2("usermoneyrepay6")=dsagnpri("usermoneyrepay6")
	dsagnpri2("usermoneyrepay7")=dsagnpri("usermoneyrepay7")
	dsagnpri2("year2")=dsagnpri("year2")
	dsagnpri2("year3")=dsagnpri("year3")
	dsagnpri2("year4")=dsagnpri("year4")
	dsagnpri2("year5")=dsagnpri("year5")
	dsagnpri2("year6")=dsagnpri("year6")
	dsagnpri2("year7")=dsagnpri("year7")
	dsagnpri2("year8")=dsagnpri("year8")
	dsagnpri2("year9")=dsagnpri("year9")
	dsagnpri2("year10")=dsagnpri("year10")


For api=1 To 7
dsagnpri2("usermoneyAPI"&api)=dsagnpri("usermoneyAPI"&api)
'dsagnpri2("usermoneyagnAPI"&api)=dsagnpri("usermoneyagnAPI"&api)
dsagnpri2("year2API"&api)=dsagnpri("year2API"&api)
'dsagnpri2("year2agnAPI"&api)=dsagnpri("year2agnAPI"&api)
dsagnpri2("year3API"&api)=dsagnpri("year3API"&api)
'dsagnpri2("year3agnAPI"&api)=dsagnpri("year3agnAPI"&api)
dsagnpri2("year4API"&api)=dsagnpri("year4API"&api)
'dsagnpri2("year4agnAPI"&api)=dsagnpri("year4agnAPI"&api)
dsagnpri2("year5API"&api)=dsagnpri("year5API"&api)
'dsagnpri2("year5agnAPI"&api)=dsagnpri("year5agnAPI"&api)
next



	dsagnpri2.update
	dsagnpri2.close

dsagnpri.movenext
wend
dsagnpri.close
Response.Write "已复制代理"&dsagnettype("template")&"的价格给代理："&Request.Form ("username")
end if
end if

if Request.Form ("agenttype")<>"n" then'不取消代理时

conn.Execute "update FreeHost.FreeHost_user set agent1=username where username='"&Request.Form ("username")&"'"'更改同名用户
conn.Execute "update FreeHost.FreeHost_Product_Host set agent1=username where username='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_Email set agent1=username where username='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_SQL set agent1=username where username='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_Other set agent1=username where username='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_IDC set agent1=username where username='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_domain set agent1=username where username='"&Request.Form ("username")&"'"

if Request.Form ("pertype")="c" then'使用别的代理价格模板时
Response.Write "请现在设置此代理的具体价格：<a href=""admagentprice.asp?username="&Request.Form ("username")&"""><font color=red>点击这儿设置>>></font></a><br><br>"
end if
end if

if Request.Form ("agenttype")="n" Then
'将代理的钱转回给用户


'if ds("usermoney")>0 then
olduser_money=dsreg("usermoney")
oldagn_money=ds("usermoney")

dsreg("usermoney")=dsreg("usermoney")+ds("usermoney")
'ds("usermoney")=ds("usermoney")+dsreg("usermoney")
'dsreg("usermoney")=0
ds("usermoney")=0
dsreg.update
newuser_money=dsreg("usermoney")
ds.update
newagn_money=ds("usermoney")

FreeHost_moneyNewlog conn,"y","n","y","n","y",isAgnHostSer,(newuser_money-olduser_money),dsreg("username"),session("admusername"),dsreg("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,session("admusername"),"取消代理资格自动扣除代理金额并转移给用户名下,增加给用户","取消代理资格自动扣除代理金额并转移给用户名下,增加给用户",whichProduct,pdid,pingzheng,type1,bank,haveget,havecheck

FreeHost_moneyNewlog conn,"n","y","y","n","n",isAgnHostSer,oldagn_money-newagn_money,dsreg("username"),session("admusername"),norusername,norStmoney,norEndmoney,dsreg("username"),oldagn_money,newagn_money,session("admusername"),"取消代理资格自动扣除代理金额并转移给用户名下","取消代理资格自动扣除代理金额并转移给用户名下",whichProduct,pdid,pingzheng,type1,bank,haveget,havecheck

out="<br><br>取消代理资格自动扣除代理金额并转移给用户名下:"&(oldagn_money-newagn_money)&"元"

'end if

conn.Execute "update FreeHost.FreeHost_user set agent1='n' where username='"&Request.Form ("username")&"'"'取消代理同名用户所属代理
conn.Execute "update FreeHost.FreeHost_user set agent1='n' where agent1='"&Request.Form ("username")&"'"'转到主站名下
conn.Execute "update FreeHost.FreeHost_agent set agent1='n' where agent1='"&Request.Form ("username")&"'"'转到主站名下
conn.Execute "update FreeHost.FreeHost_online_aws set agent1='n' where agent1='"&Request.Form ("username")&"'"'转到主站名下

conn.Execute "update FreeHost.FreeHost_Product_Host set agent1='n' where agent1='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_Email set agent1='n' where agent1='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_SQL set agent1='n' where agent1='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_Other set agent1='n' where agent1='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_IDC set agent1='n' where agent1='"&Request.Form ("username")&"'"
conn.Execute "update FreeHost.FreeHost_Product_domain set agent1='n' where agent1='"&Request.Form ("username")&"'"

'删除
conn.Execute "delete from FreeHost.FreeHost_Agent_price where username='"&Request.Form ("username")&"'"
conn.Execute "delete from FreeHost.FreeHost_Agent_user_price where username='"&Request.Form ("username")&"'"

'删除
Sql="delete from FreeHost.FreeHost_Agent_ALLdomain where username='"&Request.Form ("username")&"'"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
    conn.Execute Sql

'删除
Sql="delete from FreeHost.FreeHost_HtmlStyle where username='"&Request.Form ("username")&"'"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
    conn.Execute Sql
end if



'conn.Close 
'set conn=nothing
%>

<br>

<%if Request.Form ("agenttype")="n" Then%>
取消 <%=Request.Form ("username")%> 代理资格！操作完成。
<%else%>
<%=Request.Form ("username")%> 代理用户从 <b><%=oritype%></b> 变更为 <b><%=Request.Form ("agenttype")%></b> 成功！
<%

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

end if%>
<%=out%>
<%
end if

if ef then%>
<%=ec%>
<%end if%>
<script>
var partable=parent.document.getElementById("table0");
if (partable!=null)
partable.style.display='';

partable=parent.document.getElementById("outconM");
if (partable!=null)
partable.innerHTML = document.body.innerHTML;
</script>