<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
domain=trim(LCASE(request.Form ("domain")))
emailname=Application("admmailname")&"@"&domain
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("canadmemailset")="" 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 IsValidEmail(emailname)=false 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_Email 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="邮箱不存在！"
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
if Application("notusedomain")<>"" then
emailarry=split(Application("notusedomain"),"@")
for i=0 to ubound(emailarry)
if len(emailarry(i))>3 then
If Instr(emailname, "@"&emailarry(i))>0 then
	ef=True
	ec="不允许设置这个域名！"
end if
end if
next
end if
end If


'if not ef Then
'if Application("openmustre")=True then
'status=""
'if CheckDomainDB(domain)=false then
'	ef=True
'	ec="此域名 "&Request.Form ("hostname"&ihname)&" 没有通过备案，当前状态："&status&"，请到 http://www.miitbeian.gov.cn 查询是否成功备案。"
'	If Application("beianupsaok")=True Then	ec="此域名 "&Request.Form ("hostname"&ihname)&" 尚未在工信部提交备案信息，当前状态："&status&"，请到先到 http://www.miitbeian.gov.cn 提交备案信息。"
'end If
'End if
'end If

if not ef then
	Set dshost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist where Emailtype='"&dsph ("Emailtype")&"'"
	dshost.Open Sql,conn,1,1
if dshost.Eof then
	ef=True
	ec="产品类型不存在！"
end if
end if

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

if not ef then
email=trim(emailname)
emailarry=split(email,"@")
username=emailarry(0)
domain=emailarry(1)
Set dspdallemail = Server.CreateObject("ADODB.Recordset")
		Sql="Select * from FreeHost.FreeHost_Product_ALLEmail where PdEID<>'"&dsph ("id")&"' and emailname like '%@"&domain&"'"
		dspdallemail.Open Sql,conn,1,3
if not dspdallemail.Eof then
	ef=True
	ec="此域已被使用！已存在的域管理员："&dspdallemail("emailname")&" 但要绑定："&domain
end if
end if

if not ef then
Set dspdallemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select top 1 * from FreeHost.FreeHost_Product_ALLEmail where username='"&ds ("username")&"' and PdEID='"&dsph ("id")&"'"
		dspdallemail.Open Sql,conn,1,3
'if dspdallemail.Eof then
'	ef=True
'	ec="邮箱不存在！"
'end if
'end if

'if not ef then

if not dspdallemail.Eof then
email=trim(dspdallemail("emailname"))
emailarry=split(email,"@")
name1=emailarry(0)
olddomain=lcase(trim(emailarry(1)))
if (domain<>olddomain) then
starttime=dspdallemail("starttime")
'如果旧域存在，并且与新输入的不同，就删除旧的域
sql="delete from FreeHost.FreeHost_Product_ALLEmail where username='"&ds ("username")&"' and PdEID='"&dsph ("id")&"'"
    conn.Execute Sql
ret=DelAdmEmail(dsph ("ServerlistID"),olddomain)
FreeHost_clientlog conn,dsph ("username"),session("admusername"),"超级管理员操作","邮箱产品",dsph ("id"),"删除","","",ret
end if
end if

if dspdallemail.Eof or (domain<>olddomain) then
 dspdallemail.addnew
dspdallemail("emailname")=emailname
dspdallemail("username")=ds ("username")
dspdallemail("PdEID")=dsph ("id")
dspdallemail("Emailtype")=dsph ("Emailtype")
if starttime<>"" then
dspdallemail("starttime")=starttime
else
dspdallemail("starttime")=now
end if
dspdallemail("endtime")=dsph ("endtime")
dspdallemail("istest")=dsph ("istest")
dspdallemail("status")=dsph ("status")
dspdallemail("userspacelimt")=dsph ("userspacelimt")
dspdallemail("domainspacelimt")=dsph ("domainspacelimt")
dspdallemail.update
end if
tem2=SetAdmEmail(dsph ("ServerlistID"),emailname,domain,dsph ("emailcount"),dsph ("domainspacelimt")*1024)'maxuser

if dsserver("softtype")="Imail" then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")

regpath=domain&"\users\"&emailname
key="MaxSize"
keyvalue=dshost ("userspacelimt")*1024*1024
retvlue=replace(Regimailop(URL,FreeHostsharekey,regpath,key,keyvalue,2),"操作成功，数值为：","")
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="admemail.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">
	  
	  <DIV class="tableborder" id="t4"><br><%=ret%><%=tem2%>
<br><br>
<form name="form1" method="post" action="handemail3.asp">
  <DIV class="tableborder" id="t4">
    <table width="100%" border=0 cellpadding=2 cellspacing=1>
      <tr align="center" bgcolor="#EFEFEF">
        <td height="24" colspan="2" background="img/tablebg.gif" ><font color="#FFFFFF">设置域管理员密码　　<a href="#"  onClick="t4.style.display='none';"><font color="#F7F7FF">X</font></a></font></td>
      </tr>
      <tbody>
        <tr bgcolor="#E4EAF2">
          <td width="20%" height="70" align="right" >修改密码：</td>
          <td width="80%" height="22" align="left" ><%if domainhaveset<>"" then%>
              <br>
            　 已绑定的域名为：<%=domainhaveset%><br>
            <%end If
            mailpass=Left(md5(now),8)
			%>
            　 新密码：
            <input name="password" type="text" id="password" value="<%=mailpass%>" size="14">
            重复密码：
            <input name="repassword" type="text" id="repassword" value="<%=mailpass%>" size="14">
            <input name="id" type="hidden" value="<%=Request("id")%>">
            <input type="submit" name="Submit" value="保存修改">
          </td>
        </tr>
        <tr align="center" bgcolor="#E4EAF2">
          <td height="30" colspan="2" align="right"><a href="#top"><font color="#6B9EDE" face="Arial, Helvetica, sans-serif">Top↑</font></a></td>
        </tr>
      </tbody>
    </table>
  </div>
</form> 
</div>
	  
	  
      </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%>
