<!--#include file="../../conn/conn.asp" -->
<!--#include file="../../Inc/Commoncode.asp" -->
<!--#include file="../checkvalid.asp" -->
<!--#include file="../../inc/md5.asp"-->
<!--#include file="../../API/API_Config.asp"-->
<!--#include file="../../API/API_Function.asp"-->
<%If Not FRAdminLevel(201) Then Call ErrorMsg()%>
<html>
<head>
<title>添加通行证会员</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../css/style<%=sk%>.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../inc/input.js"></script>
</script><script language="JavaScript">
<!--
//功能：去掉字符串前后空格
//返回值：去掉空格后的字符串
function fnRemoveBrank(strSource)
{
 return strSource.replace(/^\s*/,'').replace(/\s*$/,'');
}
function String.prototype.lenB()
{
return this.replace(/[^\x00-\xff]/g,"**").length;
}
function Juge(theForm)
{
if(theForm.login.value=="")
{
alert('请输入用户名');
theForm.login.focus();
return false;
}
var objv = theForm.login.value;
var pattern = /^[A-Za-z0-9_@.-]{4,20}$/;
flag = pattern.test(objv);
if(!flag) 
{alert("用户名：要求为4-20个字母或数字以及“_”“@”“-”的组合！请重新输入。");
this.theForm.login.focus();
return(false);
}
if(theForm.pwd.value=="")
{alert('请输入密码');
theForm.pwd.focus();
return false;
}
else
{
if(theForm.pwd.value.length<4||theForm.pwd.value.length>20)
{alert('密码长度必须在4~20个字符');
theForm.pwd.focus();
return false;
}
}
var objv = fnRemoveBrank(theForm.email.value);
var pattern = /^([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)*@([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)+$/;
flag = pattern.test(objv);
if(!flag)
{
alert("电子邮件：格式不正确！请重新输入。");
theForm.email.focus();
return (false); 
}
if(theForm.name.value=="")
{
alert('请输入用户全称');
theForm.name.focus();
return false;
}
}
-->
</script></head>
<body>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder">
  <tr class="title">
    <th height="22" align="center" >用户资料管理</th>
  </tr>
  <tr>
    <td height="20"><b class="style1">　管理选项：</b><a href="Admin_Member.asp">管理首页</a> | <a href="Admin_AddMember.asp">添加用户</a> | <a href="Admin_Member.asp?show=all">用户管理</a>&nbsp;| <a href="Admin_Member.asp?operate=0">审核新用户</a> |&nbsp;[<a href="javascript:location.reload()">刷新页面</a>]</td>
  </tr>
  <tr>
    <td height="20"> 　用户类型：
      <%for m=0 to ubound(Groupid)%><a href="Admin_Member.asp?operate=<%=operate%>&typeid=<%=m+1%>"><%=Grouptype(m)%></a> | <%next%></td>
  </tr>
</table>
<%
Action=trim(Request("Action"))
select case Action
	Case "Add"
		Call ShowData()
	Case "Modify"
		Call ShowData()
	Case "SaveData"
		Call SaveData()
	Case Else
		Call ShowData()
end select
%>
<%Sub ShowData()
MemberID=trim(request("member"))
If MemberID<>"" Then
	sql="select * from JOB_Member where Member_login='"&MemberID&"'"
	set rs=server.CreateObject (FR_HR_RS)
	rs.open sql,conn,1,1
	if not rs.eof then
		Member_login=Rs("Member_login")
		Member_pwd=Rs("Member_pwd")
		Member_Auditing=Rs("Member_Auditing")
		Member_email=Rs("Member_email")
		Member_typeid=Rs("Member_typeid")
		Member_name=Rs("Member_name")
		Member_balance=Rs("Member_balance")
		Member_integral=Rs("Member_integral")
		Member_consumenums=Rs("Member_consumenums")
		Member_flag=Rs("Member_flag")
	end if
	rs.Close
	Set rs=Nothing
Else
Member_Auditing=1
Member_typeid=1
Member_balance=0
Member_integral=0
Member_consumenums=0
Member_flag=1
End If%>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="1" class="tableBorder mt10">
  <tr>
    <th height="25" class="tableHeaderText" colspan="2"> 添加通行证会员 </th>
  </tr>
  <form action="?Action=SaveData&MemberID=<%=MemberID%>" method="post" name="form1" onSubmit="return Juge(this)">
  <tr>
    <td width="160" align="right">通行证帐号：</td>
    <td><input name="login" type="text" id="login" value="<%=Member_login%>" size="20" maxlength="20">      会员名须4-20位之间</td>
  </tr>
  <tr>
    <td align="right">通行证密码：</td>
    <td><input name="pwd" type="password" id="pwd" size="20" maxlength="20" value="<%=left(Member_pwd,20)%>"><input name="repwd" type="hidden" value="<%=left(Member_pwd,20)%>">
    不修改请保留</td>
  </tr>
  <tr>
    <td align="right">通行证状态：</td>
    <td><input name="Auditing" type="radio" class="checkbox" value="0" <%if Member_Auditing=0 then Response.Write("checked")%>>
未审核
  <input name="Auditing" type="radio" class="checkbox" value="1" <%if Member_Auditing=1 then Response.Write("checked")%>>
已审核</td>
  </tr>
  <tr>
    <td align="right">电子邮箱：</td>
    <td><input name="email" type="text" id="email" value="<%=Member_email%>" size="30">
    请填写有效的E-mail地址</td>
  </tr>
  <tr>
    <td align="right">帐户类型：</td>
    <td><select name="typeid" id="typeid">
      <option value="1" <%if Member_typeid=1 then Response.Write("selected")%>>个人会员</option>
	  <option value="2" <%if Member_typeid=2 then Response.Write("selected")%>>企业会员</option>
	  <option value="3" <%if Member_typeid=3 then Response.Write("selected")%>>院校会员</option>
	  <option value="4" <%if Member_typeid=4 then Response.Write("selected")%>>培训机构</option>
      </select></td>
  </tr>
  <tr>
    <td align="right">会员名称：</td>
    <td><input name="name" type="text" id="name" value="<%=Member_name%>" size="30">
    个人会员请输入真实姓名,企业会员请输入单位名称</td>
  </tr>
  
  <tr>
    <td align="right">帐户余额：</td>
    <td><input name="balance" type="text" id="balance" value="<%=Member_balance%>" size="6">
    元</td>
  </tr>
  <tr>
    <td align="right">积分：</td>
    <td><input name="integral" type="text" id="integral" value="<%=Member_integral%>" size="6">
    分</td>
  </tr>
  <tr>
    <td align="right">可消费点数：</td>
    <td><input name="consumenums" type="text" id="consumenums" value="<%=Member_consumenums%>" size="6">
    点</td>
  </tr>
  <tr>
    <td align="right">账户状态：</td>
    <td>
      <input name="flag" type="radio" class="checkbox" value="0" <%if Member_flag=0 then Response.Write("checked")%>>
    未审核
    <input name="flag" type="radio" class="checkbox" value="1" <%if Member_flag=1 then Response.Write("checked")%>>
    已审核</td>
  </tr>
  
  
  <tr>
    <td colspan="2" align="center"><input name="Submit" type="submit" class="inputs" value="<%if MemberID<>"" then%>修 改<%else%>添 加<%end if%>"> <input name="Submit3" type="reset" class="inputs" id="Submit3" style="cursor:hand" value="重 置" /> <input name="Submit2" type="button" class="inputs" value="返 回" onClick="history.back();"></td>
  </tr>
  </form>
</table>
<%End Sub%>
</body>
</html>
<%Sub SaveData()
	MemberID=trim(request.QueryString("MemberID"))
	Memberlogin=Trim(Request.Form("login"))
	Memberpwd=Trim(Request.Form("pwd"))
	
	Memberrepwd=Trim(Request.Form("repwd"))
	MemberAuditing=Trim(Request.Form("Auditing"))
	Memberemail=Trim(Request.Form("email"))
	Membertypeid=Trim(Request.Form("typeid"))
	Membername=Trim(Request.Form("name"))
	Memberbalance=Trim(Request.Form("balance"))
	Memberintegral=Trim(Request.Form("integral"))
	Memberconsumenums=Trim(Request.Form("consumenums"))
	Memberflag=Trim(Request.Form("flag"))
	If Memberlogin="" Then
		Response.Write ("<script language=JavaScript>{alert('请输入通行证帐号！');history.back();}</script>")
		Response.End 
	End If
	RegDisabled=split(UserName_RegDisabled,"|")
	for i=0 to Ubound(RegDisabled)
	if Memberlogin=RegDisabled(i) then
	response.write ("<script language=JavaScript>{alert('此用户名已被禁用,重新输入！');location.href = 'javascript:history.back()';}</script>")
	Response.end()
	end if
	next
	'默认会员组
	If Membertypeid<>"" and IsNumeric(Membertypeid) then
		set mrs=Server.CreateObject("ADODB.RecordSet")
		msql="select * from JOB_Group where Group_membertype="&Membertypeid&" and Group_IsDefault=1"
		mrs.open msql,conn,1,1
		Group_id=mrs("Group_id")
		Group_term=mrs("Group_term")
		Group_unit=mrs("Group_unit")
		mrs.close
		set mrs=nothing
		Memberstartdate=date()
		Select Case Group_unit
			case "日"
			Memberenddate=DateAdd("d",Group_term,Memberstartdate)
			case "月"
			Memberenddate=DateAdd("m",Group_term,Memberstartdate)
			case "季"
			Memberenddate=DateAdd("q",Group_term,Memberstartdate)
			case "年"
			Memberenddate=DateAdd("yyyy",Group_term,Memberstartdate)
		end select
	end if
	set rs=Server.CreateObject(FR_HR_RS)
	if MemberID<>"" then
	sql="select * from JOB_Member where Member_login='"&MemberID&"'"
	rs.open sql,conn,1,3
	else
	sql="select * from JOB_Member where Member_login='"&Memberlogin&"' or Member_email='"&Memberemail&"'"
		rs.open sql,conn,1,3
		if not rs.eof  then
		response.write ("<script language=JavaScript>{alert('用户名或邮箱存在！');location.href = 'javascript:history.back()';}</script>")
		Response.End()
		end if
	end if
	if MemberID="" then
	rs.AddNew
	rs("Member_login")=Memberlogin
	rs("Member_sendemail")=1
	rs("Member_regdate")=Now()
	Rs("Member_startdate")=date()
	end if
	if Memberpwd<>"" and Memberpwd<>Memberrepwd then
	rs("Member_pwd")=md5(Memberpwd,32)
	end if
	Rs("Member_groupid")=Group_id
	Rs("Member_startdate")=Memberstartdate
	Rs("Member_enddate")=Memberenddate
	Rs("Member_Auditing")=MemberAuditing
	Rs("Member_email")=Memberemail
	Rs("Member_typeid")=Membertypeid
	Rs("Member_name")=Membername
	Rs("Member_balance")=Memberbalance
	Rs("Member_integral")=Memberintegral
	Rs("Member_consumenums")=Memberconsumenums
	Rs("Member_flag")=Memberflag
	rs.update
	rs.close
	set rs=nothing
	'添加对整合接口的支持
	If API_Enable Then
		'重置错误状态和信息
		FoundErr = False
		ErrMsg = ""
		set sMyXmlHTTP=server.createobject("MSXML2.ServerXMLHTTP")
		sMyXmlHTTP.setTimeouts API_Timeout, API_Timeout, API_Timeout * 6, API_Timeout * 6
		Dim intIndex
			For intIndex = 0 To UBound(ArrUrls)
			sMyXmlHTTP.open "POST",ArrUrls(intIndex),false
			sMyXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=gb2312"
			if MemberID="" then
			sMyXmlHTTP.Send "<root><appid>finereason</appid><action>reguser</action><syskey>"&MD5(Memberlogin & API_SysKey, 16)&"</syskey><username>"&Memberlogin&"</username><password>"&Memberpwd&"</password><email>"&Memberemail&"</email><question>默认问题</question><answer>默认答案</answer><userip>"&trueIP&"</userip><jointime>"&Now()&"</jointime><userstatus>0</userstatus></root>"
			else
				if Memberpwd<>"" and Memberpwd<>Memberrepwd then
				sMyXmlHTTP.Send "<root><appid>finereason</appid><action>update</action><syskey>"&MD5(Memberlogin & API_SysKey, 16)&"</syskey><username>"&Memberlogin&"</username><password>"&Memberpwd&"</password><email>"&Memberemail&"</email><question></question><answer></answer></root>"
				else
				sMyXmlHTTP.Send "<root><appid>finereason</appid><action>update</action><syskey>"&MD5(Memberlogin & API_SysKey, 16)&"</syskey><username>"&Memberlogin&"</username><password></password><email>"&Memberemail&"</email><question></question><answer></answer></root>"
				end if
			end if
			If sMyXmlHTTP.readyState = 4 And sMyXmlHTTP.Status = 200 Then
				Dim objRecXml
				Set objRecXml = Server.CreateObject("Microsoft.XMLDOM")
				objRecXml.Async = False
				objRecXml.Load (sMyXmlHTTP.ResponseXML)
				If objRecXml.documentElement.selectSingleNode("//status").Text <> "0" Then
					FoundErr = True
					ErrMsg = objRecXml.documentElement.selectSingleNode("//message").Text & " [APIError-API-" & intIndex & "]"
				End If
			End If
			If FoundErr Then
				call Show_Err()
				Exit For
			End If
			Next
	End If
	if MemberID<>"" then
	response.write ("<script language=JavaScript>{alert('会员资料修改成功！');location.href='Admin_Member.asp';}</script>")
	else
	response.write ("<script language=JavaScript>if (confirm('会员添加成功！继续添加会员吗？')){location.href='Admin_AddMember.asp'}else{location.href='Admin_Member.asp'}</script>")
	end if
	Response.End
end sub
%>