<% Option Explicit %>
<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../Inc/Cls_Admin.asp" -->
<!--#include file="../../Inc/Md5.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P0801") then Call ReturnError()
Dim AdminID,Result
Result = Request("Result")
AdminID = Replace(Replace(Request("AdminID"),"'",""),"""","")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>系统管理员</title>
</head>
<link href="System.css" rel="stylesheet">
<%
Dim RsAdminObj,SelectShowGroupStr,CheckInfo
Dim AdminName,AdminEmail,AdminOicq,AdminHomePage,AdminSex,AdminLock,AdminRealName,AdminSelfInfo,AdminGroupID
if AdminID <> "" then
	Set RsAdminObj = Conn.Execute("Select * from Admin where ID=" & AdminID)
	if RsAdminObj.Eof then
		Response.Write("<script>alert('此管理员可能已经被删除了！');window.close();</script>")
		Response.End
	else
		if Result = "Submit" then
			AdminName = Request.Form("Name")
			AdminEmail = Request.Form("Email")
			AdminOicq = Request.Form("OICQ")
			AdminHomePage = Request.Form("HomePage")
			AdminSex = Request.Form("Sex")
			AdminLock = Request.Form("Lock")
			AdminRealName = Request.Form("RealName")
			AdminSelfInfo = Request.Form("SelfIntro")
			AdminGroupID = Request.Form("GroupID")
			SaveSubmit
		else
			AdminName = RsAdminObj("Name")
			AdminEmail = RsAdminObj("Email")
			AdminOicq = RsAdminObj("OICQ")
			AdminHomePage = RsAdminObj("HomePage")
			AdminSex = RsAdminObj("Sex")
			AdminLock = RsAdminObj("Lock")
			AdminRealName = RsAdminObj("RealName")
			AdminSelfInfo = RsAdminObj("SelfIntro")
			AdminGroupID = RsAdminObj("GroupID")
		end if
	end if
else
		AdminName = Request.Form("Name")
		AdminEmail = Request.Form("Email")
		AdminOicq = Request.Form("OICQ")
		AdminHomePage = Request.Form("HomePage")
		AdminSex = Request.Form("Sex")
		AdminLock = Request.Form("Lock")
		AdminRealName = Request.Form("RealName")
		AdminSelfInfo = Request.Form("SelfIntro")
		AdminGroupID = Request.Form("GroupID")
		if Result = "Submit" then
			SaveSubmit
		end if
end if
if AdminGroupID <> "0" then
	Set RsAdminObj = Conn.Execute("Select * from AdminGroup")
	SelectShowGroupStr = ""
	do while Not RsAdminObj.Eof
		if (RsAdminObj("ID") = AdminGroupID) then
			SelectShowGroupStr = SelectShowGroupStr & "<option selected value=" & RsAdminObj("ID") & ">" & RsAdminObj("GroupName") & "</option>"
		else
			SelectShowGroupStr = SelectShowGroupStr & "<option value=" & RsAdminObj("ID") & ">" & RsAdminObj("GroupName") & "</option>"
		end if
		RsAdminObj.MoveNext
	loop
	RsAdminObj.Close
end if
Set RsAdminObj = Nothing
Sub SaveSubmit()
	if Result = "Submit" then
		Dim AClass,ReturnCheckInfo
		Set AClass = New AdminClass
		AClass.TForm = Request.Form
		ReturnCheckInfo = AClass.AddAndModifyAdmin()
		if ReturnCheckInfo = "" then
	%>
	<script>dialogArguments.location.reload();window.close();</script>
	<%
		else
	%>
	<script>alert('<% = ReturnCheckInfo %>');history.back();</script>
	<%
		end if
	end if
End Sub
%>
<body scrolling=no leftmargin="0" topmargin="6" bgcolor="#E6E6E6">
<div align="center">
  <table width="90%" border="0" cellpadding="5" cellspacing="0">
    <form action="" id="AdminForm" method="post" name="AdminForm">
      <tr> 
        <td width="18%"> 
          <div align="center">用户名称：</div></td>
        <td width="80%"> 
          <input value="<% =AdminName %>" <% if AdminName <> "" then Response.Write("readonly") %> name="Name" style="width:95%;" type="text" id="Name2" size="36" maxlength="40"> 
          <font color="#FF0000">*</font>
<input value="<% =AdminID %>" name="AdminID" type="hidden" id="AdminID2"> 
          <input name="Result" type="hidden" id="Result2" value="Submit"></td>
      </tr>
<% if AdminID = "" then%>
      <tr> 
        <td> 
          <div align="center">您的密码：</div></td>
        <td> <input name="PassWord" type="password" style="width:95%;" id="PassWord2" size="36">
          <font color="#FF0000">*</font></td>
      </tr>
      <tr> 
        <td> 
          <div align="center">确认密码：</div></td>
        <td> 
          <input name="AffirmPassWord" type="password" style="width:95%;" id="AffirmPassWord2" size="36"> 
          <font color="#FF0000">*</font></td>
      </tr>
<% end if %>
      <% if AdminGroupID <> "0" then %>
      <tr> 
        <td> 
          <div align="center">所属组：</div></td>
        <td> 
          <select style="width:95%;" name="GroupID" id="select">
            <% =SelectShowGroupStr %>
          </select>
          <font color="#FF0000">*</font></td>
      </tr>
      <% else %>
      <input value="0" type="hidden" name="GroupID">
      <% end if %>
      <tr> 
        <td> 
          <div align="center">真实姓名：</div></td>
        <td> 
          <input style="width:95%;" value="<% =AdminRealName %>" name="RealName" type="text" id="RealName2" size="36" maxlength="50"> 
          <font color="#FF0000">*</font></td>
      </tr>
      <tr> 
        <td height="18"> 
          <div align="center">性 别：</div></td>
        <td> 
          <input <% if AdminSex = 0 then Response.Write("checked") %> name="Sex" type="radio" value="0" checked>
          男 
          <input <% if AdminSex = 1 then Response.Write("checked") %> type="radio" name="Sex" value="1">
          女</td>
      </tr>
      <% if AdminGroupID <> "0" then %>
      <tr> 
        <td height="16"> 
          <div align="center">是否锁定：</div></td>
        <td> 
          <input name="Lock" <% if AdminLock = 1 then Response.write("checked") %> type="checkbox" id="Lock" value="1">
          是否锁定</td>
      </tr>
      <% end if %>
      <tr> 
        <td> 
          <div align="center">邮箱地址：</div></td>
        <td> 
          <input style="width:95%;" value="<% =AdminEmail %>" name="Email" type="text" id="Email2" size="36" maxlength="50"></td>
      </tr>
      <tr> 
        <td> 
          <div align="center">Oicq：</div></td>
        <td> 
          <input style="width:95%;" value="<% =AdminOicq %>" name="Oicq" type="text" id="Oicq2" size="36" maxlength="15"></td>
      </tr>
      <tr> 
        <td> 
          <div align="center">主页地址：</div></td>
        <td> 
          <input style="width:95%;" value="<% =AdminHomePage %>" name="HomePage" type="text" id="HomePage2" size="36" maxlength="150"></td>
      </tr>
      <tr> 
        <td> 
          <div align="center">简要说明：</div></td>
        <td> 
          <textarea style="width:95%;" name="SelfIntro" cols="34" rows="6" id="textarea"><% =AdminSelfInfo %></textarea></td>
      </tr>
      <tr> 
        <td colspan="2"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr> 
              <td id="AddBtn" width="15%"><div align="center"> 
                  <input type="button" name="Submit3" onClick="AddSubmit();" value=" 保 存 ">
                </div></td>
              <td width="15%"><div align="center"> 
                  <input name="Submitaa" type="reset" id="Submitaa" value=" 重 填 ">
                </div></td>
              <td width="15%"> <div align="center"> 
                  <input type="reset" name="Submit2" onClick="window.close();" value=" 取 消 ">
                </div></td>
            </tr>
          </table>
          </td>
      </tr>
    </form>
  </table>
</div>
</body>
</html>
<%
Set Conn = Nothing
%>
<script>
function AddSubmit()
{
	if (CheckAdminForm())
	{
		document.AdminForm.submit();
	}
}
function CheckAdminForm()
{
	var ErrorCode='';
	if (document.AdminForm.Name.value=='') ErrorCode=ErrorCode+'没有填写用户名！\n';
	<% if AdminID = "" then %>
	if (document.AdminForm.PassWord.value=='') ErrorCode=ErrorCode+'没有填写密码！\n';
	if (document.AdminForm.AffirmPassWord.value=='') ErrorCode=ErrorCode+'没有填写确认密码！\n';
	if (document.AdminForm.PassWord.value!=document.AdminForm.AffirmPassWord.value) ErrorCode=ErrorCode+'密码和确认密码不符！\n';
	<% end if %>
	if (document.AdminForm.GroupID.value=='') ErrorCode=ErrorCode+'没有填写管理员组！\n';
	if (document.AdminForm.RealName.value=='') ErrorCode=ErrorCode+'没有填写真实姓名！\n';
	if (ErrorCode!='') 
	{
		alert(ErrorCode);
		return false
	}
	else return true;
}
function SetEmptyForm()
{
	var i;
	for(i=0;i<document.AdminForm.elements.length;i++)
	{
		if (document.AdminForm.elements.item(i).tagName.toLowerCase()=='input')
		{
			if (document.AdminForm.elements.item(i).type=='text') document.AdminForm.elements.item(i).value='';
			if (document.AdminForm.elements.item(i).type=='checkbox') document.AdminForm.elements.item(i).checked=false;
		}
		if (document.AdminForm.elements.item(i).tagName.toLowerCase()=='textarea') document.AdminForm.elements.item(i).innerText='';
	}
}
</script>
