<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
Function strtobin(str, charset)
  With Server.CreateObject("ADODB.Stream")
      .Type = 2
      .Mode = 3
      .Open
      .Charset = charset
      .WriteText str
      .Flush
      .Position = 0
      .Type = 1
       strtobin = .Read()
      .Close
  End With
End Function
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.QueryString ("username")="" and Request.QueryString ("endtime2")=""  and Request.QueryString ("status")=""  and Request.QueryString ("starttime2")=""   and Request.QueryString ("beianstatus")=""  and Request.QueryString ("domain")="" and Request.QueryString ("ftpname")=""  and Request.QueryString ("ServerlistID")="" and Request.QueryString ("Emailtype")="" and Request.QueryString ("sqlname")="" or Instr(Request.QueryString ("hostname"), "'")>0  or Instr(Request.QueryString ("ftpname"), "'")>0    or Instr(Request.QueryString ("Emailtype"), "'")>0    or Instr(Request.QueryString ("sqlname"), "'")>0  Then
	ef=True
	ec="必须输入一项内容或有非法字符！"
elseIf session("canadmuser")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
if Request("domain")<>"" then	
	Set dspdallemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_ALLEmail where emailname like '%"&Request.QueryString ("domain")&"%'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dspdallemail.Open Sql,conn,1,1
		if  not dspdallemail.eof then
		havefind=true
		end if
end if


	Set dsphemail = Server.CreateObject("ADODB.Recordset")
SQL="Select * from FreeHost.FreeHost_Product_Email where "
if Request.QueryString ("username")<>"" then Sql=Sql+"username= '"&trim(Request.QueryString ("username"))&"' and "
if Request.QueryString ("domain")<>"" and havefind then Sql=Sql+"id="&dspdallemail("PdEID")&" and "
if Request.QueryString ("domain")<>"" and not havefind then Sql=Sql+"id=0 and "
if Request.QueryString ("ftpname")<>"" then Sql=Sql+"ftpname like '%"&trim(Request.QueryString ("ftpname"))&"%' and "
if Request.QueryString ("ServerlistID")<>"" then Sql=Sql+"ServerlistID = '"&trim(Request.QueryString ("ServerlistID"))&"' and "
if Request.QueryString ("Emailtype")<>"" then Sql=Sql+"Emailtype = '"&trim(Request.QueryString ("Emailtype"))&"' and "

if Request.QueryString ("status")<>"" then
if Request.QueryString ("status")="过期暂停" then
Sql=Sql+"istest = 'n' and endtime < '"&now&"' and status = '暂停' and "
elseif Request.QueryString ("status")="过期未暂停" then
Sql=Sql+"istest = 'n' and endtime < '"&now&"' and status = '正常' and "
elseif Request.QueryString ("status")="试用过期未暂停" then
Sql=Sql+"endtime < '"&now&"' and istest = 'y' and status = '正常' and "
elseif Request.QueryString ("status")="试用过期已暂停" then
Sql=Sql+"endtime < '"&now&"' and istest = 'y' and status = '暂停' and "
elseif Request.QueryString ("status")="试用过期" then
Sql=Sql+"endtime < '"&now&"' and istest = 'y' and "
elseif Request.QueryString ("status")="试用" then
Sql=Sql+"endtime > '"&now&"' and istest = 'y' and "
else
Sql=Sql+"istest = 'n' and status = '"&trim(Request.QueryString ("status"))&"' and "
end if
end if

if Request.QueryString ("beianstatus")<>"" and Request.QueryString ("beianstatus")<>"没有备案" then Sql=Sql+"beianstatus = '"&trim(Request.QueryString ("beianstatus"))&"' and "
if Request.QueryString ("beianstatus")="没有备案" then Sql=Sql+"beianstatus is null and "
if Request.QueryString ("starttime2") <>"" then  Sql=Sql+"Emailtype<>'子目录绑定' and starttime>'"&Request.QUERYSTRING ("starttime1")&"' and starttime<'"&Request.QUERYSTRING ("starttime2")&"' and "
if Request.QueryString ("endtime2") <>"" then  Sql=Sql+"Emailtype<>'子目录绑定' and endtime>'"&Request.QUERYSTRING ("endtime1")&"' and endtime<'"&Request.QUERYSTRING ("endtime2")&"' and "
if right(sql,5)=" and " then sql=left(sql,len(sql)-5)&" order by id desc"
'Response.Write sql
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
        dsphemail.Open Sql,conn,1,1
if dsphemail.Eof then
	ef=True
	ec="数据库中没有此类内容。"
else
allcount=dsphemail.recordcount
end if
end if

if not ef Then

If request.QueryString("csv")="yes" Then
con="#id,用户名,中文名,联系人,电话,手机,QQ,产品类型,大小(G),邮箱域名,所属父产品FTP名,IP,状态,购买时间,到期时间"&vbcrlf
while not dsphemail.Eof
Emailtype=dsphemail("Emailtype")
Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username = '"&dsphemail ("username")&"'"
		ds.Open Sql,conn,1,1
if Not ds.Eof Then
truename=ds("truename")
tel=ds("tel")
mobi=ds("mobi")
qq=ds("qq")
contact=ds("contact")
End If

Set dsdm = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Product_Domain where username='"&dsphemail ("username")&"' and id ='"&dsphemail("bydomain")&"'"
	dsdm.Open Sql,conn,1,1
if not dsdm.Eof then
bydomain=dsphemail("bydomain")
end if

Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&dsphemail("byhost")&"' and username='"&dsphemail("username")&"'"
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
ftpname=dsph("ftpname")
end If

Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerEmaillist where id='"&dsphemail ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
ip=dsserver("ip")
dsserver.close
con=con&dsphemail("id")&","&dsphemail("username")&","&ds("truename")&","&ds("tel")&","&ds("mobi")&","&ds("qq")&","&ds("contact")&","&dsphemail("Emailtype")&","&dsphemail("domainspacelimt")&","&bydomain&","&ftpname&","&ip&","&dsphemail("status")&","&formatdatetime(dsphemail("starttime"),1)&","&formatdatetime(dsphemail("endtime"),1)&vbcrlf
dsphemail.movenext
Wend

conbyte=strtobin(con, "GBK")
Filesize=Lenb(conbyte)
'Response.write con
Response.AddHeader "Content-Disposition", "attachment; filename=host.csv"  '添加头信息，为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader "Content-Length", Filesize            'file.Length.ToString()    '添加头信息，指定文件大小，让浏览器能够显示下载进度
Response.ContentType = "application/csv"                '指定返回的是一个不能被客户端读取的流，必须被下载
Response.BinaryWrite conbyte
Response.Flush 
Response.end
End If

%>
<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center" bgcolor="#333333">
  <tr bgcolor="#C1BFBF" align="center">
    <td height="21">产品类型</td>
    <td>用户名</td>
    <td>绑定域名</td>
    <td height="21">所属父产品</td>
    <td>IP 地址</td>
    <td>开通日期</td>
    <td>到期日期</td>
    <td>状态</td>
    <td>操作</td>
  </tr>
<%while not dsphemail.Eof%>
<%
	Emailtype=dsphemail("Emailtype")
	Set ori_email_name = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_EmailProductlist where Emailtype='"&dsphemail("Emailtype")&"'"
		ori_email_name.Open Sql,conn,1,1
		if not ori_email_name.eof then
Set newname_email = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_EmailProductlist_AGN where agent1='"&dsphemail("agent1")&"' and id='"&ori_email_name("id")&"'"
		newname_email.Open Sql,conn,1,1
if not newname_email.eof then
Emailtype=newname_email("Emailtype")
end if
		end if

	%>
  <tr align="center" bgcolor="#FFFFFF">
    <td height="30">
<%=Emailtype%>
</td>
    <td><a href="searchuser.asp?username=<%=dsphemail("username")%>"><%=dsphemail("username")%></a>
	<%If request("showuserinfo")="y" Then

Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username = '"&dsphemail ("username")&"'"
		ds.Open Sql,conn,1,1
if Not ds.Eof then
%>
<br>
真名：<%=ds("truename")%>
电话：<%=ds("tel")%> 手机：<%=ds("mobi")%> 传真：<%=ds("fax")%> QQ:<%=ds("qq")%> 邮箱：<a href=mailto:<%=ds("email")%>><font color="#000000"><%=ds("email")%></font></a>
 地址：<%=ds("prv")%>/<%=ds("city")%>/<%=ds("address")%> 联系人：<%=ds("contact")%> 邮编：<%=ds("postid")%>
<%
End If
ds.close
End If
%></td>
    <td><%
	Set dspdallemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_ALLEmail where username='"&dsphemail ("username")&"' and PdEID='"&dsphemail ("id")&"' order by emailname"
		dspdallemail.Open Sql,conn,1,1
		if not dspdallemail.eof then
		if not isnull(dspdallemail("emailname")) then
		%><%= replace(dspdallemail("emailname"),"webmaster@","")%><%
		end if
		end if%></td>
    <td>
	<%
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&dsphemail("byhost")&"' and username='"&dsphemail("username")&"'"
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
nohost=false%>
<a href="handhost1.asp?id=<%=dsphemail("byhost")%>"><font color="black">虚拟主机(<%=dsph("ftpname")%>)</font></a>
<%else
nohost=true
end if%>
<%
Set dsdm = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Product_Domain where username='"&dsphemail ("username")&"' and id ='"&dsphemail("bydomain")&"'"
	dsdm.Open Sql,conn,1,1
if not dsdm.Eof then
nodomain=false%>
<a href="listmydomain.asp?id=<%=dsphemail("bydomain")%>"><font color="black">域名(<%=dsdm("domain")%>)</font></a>
<%else
nodomain=true
end if
if nohost and nodomain then%>
无
<%end if%>

	</td>
    <td><%
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serveremaillist where id='"&dsphemail ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
%><%=dsserver("ip")%><%dsserver.close%></td>
    <td><%=formatdatetime(dsphemail("starttime"),1)%></td>
    <td><%=formatdatetime(dsphemail("endtime"),1)%></td>
    <td><%if dsphemail("endtime")>NOW then%>
      <%if dsphemail("istest")="y" then%>
      <font color="#FF0000">试用</font><%else%>
      <%=dsphemail("status")%>
      <%end if%>
      <%else%>
      <font color="#FF0000">过期</font>
      <%if dsphemail("status")="暂停" then%>
      <br>
      <font color="#FF0000">暂停</font>
      <%end if%>
      <%end if%></td>
    <td bgcolor="#FFFFFF"><a href="handemail1.asp?id=<%=dsphemail("id")%>"><font color="#000000">管理</font></a></td>
  </tr>
<%
dsphemail.movenext
wend%>
</table>
<br>
记录数：<%=allcount%>　<a href="sxemail.asp?<%=Request.QueryString%>&csv=yes">导出CSV</a><br>

<%
dsphemail.close
set dsphemail=nothing
conn.Close 
set conn=nothing
%>
<%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>