<!--#include file="../fy.Function.asp"-->
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>管理员添加/修改</title>
<link rel="stylesheet" type="text/css" href="../css/base.css">
<link rel="stylesheet" type="text/css" href="../css/content.css">
<script type='text/javascript' src='../js/main.js'></script>
</head>
<body>
<% 
	Dim Rs,ShowErr
	Set Rs=server.CreateObject("adodb.recordset") 
	  If Request.QueryString("Action") = "Edit" Then	
		Dim AdminID,Admin_Name,Locked,Tel,Email,Description,Sex,RealName,Action
		AdminID= ChkNumeric(fycms.S("AdminID"))
		'AdminID = Cint(Request.Cookies(fycmsN)("AdminID"))
		If AdminID =0 Or AdminID="" Then  Call fycms.fycmsErr("")
		 If Not fycms.ChkAdmin() Then '超级管理员检测
			If Cint(Request.Cookies(fycmsN)("AdminID"))<>AdminID Then Call fycms.fycmsErr("")
		 End If 
		Rs.OPen "Select * from Admin_fy Where Id = "&AdminID&" order by ID desc",Conn,1,1
			IF Not Rs.eof Then
				Admin_Name = Rs("Admin_Name")
				Locked = Rs("Locked")
				RealName = Rs("RealName")
				Tel = Rs("Tel")
				Email = Rs("Email")
				Description = Rs("Description")
				Sex = Rs("Sex")
			Else
				Admin_Name = ""
				Locked = 0
				Sex = 0
			End IF
			Rs.Close:Set Rs = Nothing
		End IF
		IF Request.QueryString("Action") = "Edit" Then Action = "Save" Else Action = "AddAdmin"
		Select Case Request.QueryString("Action")	
			   Case "AddAdmin" 
			   		Call Saveadmin()
					Response.End
			   Case "Save"
					Call SaveAdmin()
					Response.End
		End Select
			
		
		Sub Saveadmin()
		Dim Admin_Name ,PassWord,RPassWord,Locked,Tel,Email,Description,Sex,RealName,TempRs,AdminRS,AdminSql,AdminID
			Admin_Name = RSQL(Request.Form("Admin_Name"))
			PassWord = Request.Form("PassWord")
			RPassWord = Request.Form("RPassWord")	
			Sex = ChkNumeric(Request.Form("Sex"))
			Locked = ChkNumeric(Request.Form("Locked"))
			RealName = RSQL(Request.Form("RealName"))	
			Tel = RSQL(Request.Form("Tel"))	
			Email = RSQL(Request.Form("Email"))	
			Description = RSQL(Request.Form("Description"))	
			IF Trim(PassWord) <> Trim(RPassWord) Then
				ShowErr = "2次输入的密码不一致!"
				 Call fycms.alert(ShowErr,"")
				Response.end
			End IF
			
		IF Request.QueryString("Action") = "AddAdmin" Then
			 If Not fycms.ChkAdmin() Then '超级管理员检测
				Call fycms.fycmsErr("")
			 End If 
			IF Admin_Name <> "" Then
				IF Len(Admin_Name) >= 100 Then
					ShowErr = "管理员名称不能超过50个字符"
 					 Call fycms.alert(ShowErr,"")
					Response.end
				End IF
			Else
					ShowErr = "请输入管理员名称!"
					 Call fycms.alert(ShowErr,"")
					Response.end
			End if	
		
			Set TempRs = Conn.Execute("Select Admin_Name from Admin_fy where Admin_Name='" & Admin_Name & "'")
			IF Not TempRs.Eof Then
					ShowErr = "数据库中已存在该管理员名称!"
					 Call fycms.alert(ShowErr,"")
					Response.end
			End IF			
			
			 Set AdminRS = Server.CreateObject("adodb.recordset")
				  AdminSql = "select * from Admin_fy"
				  AdminRS.Open AdminSql, Conn, 1, 3
				  AdminRS.AddNew
				  AdminRS("AddDate") = Now
				  AdminRS("Admin_Name") = Admin_Name
				  AdminRS("PassWord")=MD5(RPassWord,64)
				  AdminRS("Locked") = Locked
				  AdminRS("RealName") = RealName
				  AdminRS("Sex") = Sex
				  AdminRS("Tel") = Tel
				  AdminRS("Email") = Email
				  AdminRS("Description") = Description
				  AdminRS("SuperTF") = 0
				  AdminRS("LoginTime") = Now
				  AdminRS("LoginIP") = GetIP()
				  AdminRS.Update
				  AdminRS.Close:Set AdminRS = Nothing			
 				  Call fycms.alert("添加管理员成功","index.asp")
 				  Response.end
			ElseIF Request("Action") = "Save" Then
				  AdminID = ChkNumeric(Request("AdminID"))
				 If Not fycms.ChkAdmin() Then '超级管理员检测
					If CStr(Request.Cookies(fycmsN)("AdminID"))<>CStr(AdminID) Then Call fycms.fycmsErr("")
					If Not fycms.fycms_QXYZ(0,"editmypassword","") Then   Call fycms.Alert("对不起，您不能修改自己的密码！")
				 End If 
				  Set AdminRS = Server.CreateObject("adodb.recordset")
				  AdminSql = "select * from Admin_fy Where ID="&AdminID
				  AdminRS.Open AdminSql, Conn, 1, 3
				  IF RPassWord <> "" Then  AdminRS("PassWord")=MD5(RPassWord,64)
				  AdminRS("Locked") = Locked
				  AdminRS("RealName") = RealName
				  AdminRS("Sex") = Sex
				  AdminRS("Tel") = Tel
				  AdminRS("Email") = Email
				  AdminRS("Description") = Description
				  AdminRS.Update
				Response.Cookies(fycmsN)("AdminName") = AdminRS("Admin_Name")'更新
				Response.Cookies(fycmsN)("AdminPassword") = AdminRS("PassWord")
				Response.Cookies(fycmsN)("AdminID") = AdminRS("ID")
				If AdminRS("SuperTF")=1 Then Response.Cookies(fycmsN)("SuperTF")=1
				Response.Cookies(fycmsN)("Purview") = AdminRS("Purview")
				Response.Cookies(fycmsN)("ACT_Other") = AdminRS("ACT_Other")
				Response.Cookies(fycmsN)("HQQXLX") = AdminRS("fycms_QXLX")
			    AdminRS.Close:Set AdminRS = Nothing			
			    ShowErr = "操作成功!"
				
			     Call fycms.alert(ShowErr,"index.asp")
			    Response.end
			End If
		
		End Sub
		
 %>
<div class="content"> 
	<div class="breadnav">当前位置：<a href="#">后台首页</a> >> 添加\修改管理员管理员</div>
 <form id="HFCMS" name="HFCMS" method="post" action="?Action=<%=Action %>&AdminID=<%=Request.QueryString("AdminID")%>">
    <div class="divtable"> 
        <dl>
            <dt>管理员帐号:</dt>
            <dd>
              <input  class="Ainput"  <%IF Request.QueryString("Action") = "Edit" Then echo "readonly disabled=true" %> name="Admin_Name" type="text" id="Admin_Name" value="<%= Admin_Name %>" size="40" />
            </dd>
         </dl>
        
        <dl>
            <dt>初始密码</dt>
            <dd>
               <input   class="tinput"   type="password" size="42" name="PassWord" /> 
			
      <% if Request.QueryString("Action") = "Add" Then  echo "<font color=""red"">密码不能少于6位</font>" Else echo "<font color=""red"">密码不能少于6位,不修改请保持为空</font>" %>
             </dd>
         </dl>
        <dl>
            <dt>重复密码</dt>
            <dd>
               <input  class="tinput"  name="RPassWord" type="password" id="RPassWord" size="42" maxlength="40" />
             </dd>
         </dl>
        <dl>
            <dt>是否锁定</dt>
            <dd>
               <label for="locked1"><input <%if Locked = 0 then echo("Checked")%>  type="radio" checked="checked" value="0" id="Locked1" name="Locked" />&nbsp;&nbsp;正常&nbsp;&nbsp;</label>
      <label for="locked2"><input <%if Locked = 1 then echo("Checked")%> type="radio" value="1" id="Locked2" name="Locked" />&nbsp;&nbsp;锁定&nbsp;&nbsp;</label>
<font color="red"> 锁定的用户不能登录后台管理</font>
             </dd>
         </dl>
        <dl>
            <dt>真实姓名</dt>
            <dd>
               <input  class="Ainput"  name="RealName" type="text" id="RealName" value="<%= RealName %>" size="40" />
             </dd>
         </dl>
        <dl>
            <dt>性 别</dt>
            <dd>
               <label for="Sex1"><input <%if Sex = 0 then echo("Checked")%> type="radio" checked="checked" value="0" id="Sex1" name="Sex" />&nbsp;男 &nbsp;&nbsp;</label>
        <label for="Sex2"><input <%if Sex = 1 then echo("Checked")%> type="radio" value="1" id="Sex2" name="Sex" /> &nbsp; 女 &nbsp;&nbsp;</label> 
             </dd>
         </dl>
        <dl>
            <dt>联系电话</dt>
            <dd>
               <input  class="Ainput"  name="Tel" type="text" id="Tel" value="<%= Tel %>" size="40" />
             </dd>
         </dl>
        <dl>
            <dt>电子信箱</dt>
            <dd>
               <input  class="Ainput"  name="Email" type="text" id="Email" value="<%= Email %>" size="40" />
             </dd>
         </dl>
        <dl>
            <dt>简要说明</dt>
            <dd>
               <textarea name="Description" cols="50%" rows="6" id="Description"><%= Description %></textarea>
             </dd>
         </dl>
  
            <dl>
            <dt class="vhid">提交：</dt>
            <dd>
                <a class="btn btn_primary" href="javascript:void(0);" onclick="CheckForm()">提交</a>
                <a class="btn" href="javascript:void(0);" onclick="CheckForm()">重置</a>
            </dd>
         </dl>
        
    </div>
    </form>


</div>

<SCRIPT language=javascript>
<!--
function CheckForm()
{ var form=document.HFCMS;
   if (form.Admin_Name.value=='')
    { alert("请输入管理员名称!");   
	  form.Admin_Name.focus();    
	   return false;
    }
  <% if Request.QueryString("Action") = "Add" then %>
    if (form.PassWord.value=='')  
	  {     alert("请输入初始密码!");   
	    form.PassWord.focus();   
		  return false;   
		 }   else if (form.PassWord.value.length<6)  
		   {  alert("初始密码不能少于6位!");   
		     form.PassWord.focus();   
			   return false;   
	}   if (form.RPassWord.value=='')  
	  {     alert("请输入确定密码!");   
	    form.RPassWord.focus();    
		 return false;    
		 }  
		  else if(form.RPassWord.value.length<6) 
		   {    
		    alert("确定密码不能少于6位!");    
			 form.RPassWord.focus(); 
			 return false;    } 
		<%end if%>  
	 if (form.PassWord.value!=form.RPassWord.value)   
	   {    
	    alert("两次输入的密码不一致!");   
		  form.PassWord.focus();   
		  return false;    
		  }
		   if (form.RealName.value=='')
			{
			 alert("请输入真实姓名");
			 form.RealName.focus();
			 return false;
			}
   if (form.Email.value!='')
   if(check(form.Email.value)==false)
      { alert('非法电子邮箱!');
        form.Email.focus();
        return false;
     }  
 	    form.submit();
        return true;
}

function check(str)
{ if((str.indexOf("@")==-1)||(str.indexOf(".")==-1)){
	
	return false;
	}
	return true;
}
//-->
</SCRIPT>
</body>
</html>
