<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%server.ScriptTimeout =7200
If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("cannextagn")="" Then
	ef=True
	ec="您没有此操作的权限。"
elseIf Request("username")="" or RegExpTest("[^A-Za-z0-9]",Request("username")) Then
	ef=True
	ec="会员名没有写/或会员名中有非法字符"
ElseIf Request("agenttype")<>"y" and Request("agenttype")<>"n" 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("username")&"' and (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"')"
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
if 	LCASE(trim(session("agentusername")))=LCASE(trim(ds("username"))) 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("agenttype")<>"n" then
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_pers where 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("agenttype")="y" then
'ds("agenttype")="子代理"
	Set dsreg = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&Request("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("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("regtime")=NOW
dsreg("lastuse")=NOW
dsreg("regip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then dsreg("regip")=Request.ServerVariables("HTTP_FreeHostAPIIP")

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
end if

'domain
	Set dsagentdomain = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_ALLdomain where domain='"&replace(Request("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("username")
		dsagentdomain("domain")=replace(Request("username")&"."&dsC ("domain"),"..",".")
		dsagentdomain("agent1")=session("agentusername")
		dsagentdomain("agent2")="n"
		dsagentdomain.update
'		end if












Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=nothing



Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Email where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=nothing

Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_ALLEmail where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=nothing


Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=Nothing

Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_idc where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=nothing


Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_idc_repair where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=nothing

Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Domain where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=Nothing

Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_VPS where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=Nothing

Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_NETCN where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=nothing

Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Preopen_Product where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=nothing



Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Other where username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	dsph("agent1")=ds("username")
	dsph.update
	dsph.movenext
wend
dsph.close
set dsph=nothing















server.Transfer "admagentprice.asp"
else
ds("agenttype")="n"
end if
ds.update
ds.close
set ds=nothing

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




conn.Close 
set conn=nothing
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>　操作成功
<%=htmlwrite("html6")%><br>
<br>

<%if Request("agenttype")="y" then%>
授权 <%=Request("username")%> 用户成为 代理 成功！
<%else%>
<%=Request("username")%> 代理资格取消成功！
<%end if%>
<%=htmlwrite("html7")%>
<%
end if
if ef then
Response.Redirect "e.asp?e="&ec
end if
%>
