<!--#include file="../fy_inc/fy.User.asp"-->
<!--#include file="../fy_inc/fy.U_M.ASP"-->
<!--#include file="../Field.asp"-->
 <!--#include file="../editor/user.asp"-->
<%			

 		Dim Rs,ModeID,i,TableName,CheckMode,ACTCode,wid,AllianceUser
		Set ACTCode =New ACT_Code
		if fycms.fycms_Sys(12) = "1" or fycms.fycms_Sys(13) = "1"  Then
			Call fycms.Alert("系统关闭注册或会员系统已经关闭",fycms.fycms_Sys(3))		
			Response.End
		End If
    wid=ChkNumeric(request("wid"))
    AllianceUser=ChkNumeric(request("AllianceUser"))
	
	If wid<>0 Then 
		Dim wrs:Set wrs=fycms.actexe("select username from user_fy where userid="&wid)
		If Not wrs.eof Then session("wusername")=wrs("username")
		session("wid")=wid
 	End If 
	ModeID=ChkNumeric(request("ModeID"))
	Select Case Request.QueryString("action")	
			   Case "save" 
			   		Call SaveUser()
					Response.End
			   Case "RegM"
			   		call regok()
			   Case else
					Call main()
					Response.End
		End Select
		Sub SaveUser()
		Dim UserName ,Codes,PassWord,RPassWord,Email,TempRs,AdminRS,AdminSql,Regrz,CheckNum,Question,Answer
		if fycms.actexe("select RegCode from ModeUser_fy where ModeID="&ModeID&"")(0) = 0 Then
		 Codes = Request.Form("Code")
			If CStr(Codes) <>CStr(Session("GetCode")) then
				Call fycms.Alert("验证码有误，重新输入","")		
				Response.End
			End if
		End  If 
			 Dim rs1
	  	     Set Rs1=fycms.actexe("select ModeTable from ModeUser_fy where ModeID="&ModeID&" ")
			 If Not Rs1.eof Then
				TableName=Rs1("ModeTable")
			 Else 
				Call fycms.alert("未定义操作","")
				response.End 
			 End if	
			UserName = fycms.S("UserName")
			PassWord = Request.Form("PassWord")
			RPassWord = Request.Form("RPassWord")	
			Email = fycms.S("Email")	
			Question = fycms.S("Question")
			Answer = fycms.S("Answer")
			IF Trim(PassWord) <> Trim(RPassWord) Then
				Call fycms.Alert("2次输入的密码不一致!","")		
				Response.end
			End IF
			
			IF UserName <> "" Then
				IF Len(UserName) >= 100 Then
				    Call fycms.Alert("用户名不能超过50个字符","")		
					Response.end
				End IF
			Else
				    Call fycms.Alert("请输入用户名","")		
					Response.end
			End if	
		
			if UserName="" then
			 Call fycms.Alert("请输入会员名","")	
			elseif InStr(UserName, "=") > 0 Or InStr(UserName, ".") > 0 Or InStr(UserName, "%") > 0 Or InStr(UserName, Chr(32)) > 0 Or InStr(UserName, "?") > 0 Or InStr(UserName, "&") > 0 Or InStr(UserName, ";") > 0 Or InStr(UserName, ",") > 0 Or InStr(UserName, "'") > 0 Or InStr(UserName, ",") > 0 Or InStr(UserName, Chr(34)) > 0 Or InStr(UserName, Chr(9)) > 0 Or InStr(UserName, "") > 0 Or InStr(UserName, "$") > 0 Or InStr(UserName, "*") Or InStr(UserName, "|") Or InStr(UserName, """") > 0 Then
			 Call fycms.Alert("用户名中含有非法字符","")	
			elseif len(UserName)<4 or len(UserName)>16 then
			 Call fycms.Alert("会员名长度应为4-16位!","")	
			elseif fycms.FoundInArr(fycms.fycms_Sys(16), UserName, "|") = True Then
			 Call fycms.Alert("您输入的用户名为系统禁止注册的用户名","")	
			end if
 		 if fycms.IsValidEmail(Email)=false then
			  Call fycms.Alert("请输入正确的电子邮箱!","")	
		 End if
 			Set CheckMode = fycms.ACTEXE("Select ModeTable from ModeUser_fy")
			If Not CheckMode.eof Then 
				Do While Not CheckMode.eof
					Set TempRs = Conn.Execute("Select UserName from User_fy where UserName='" & UserName & "'")
					IF Not TempRs.Eof Then
							Call fycms.Alert("数据库中已存在该用户名","")		
							Response.end
					End IF			
				 CheckMode.movenext
				 Loop
			End If 
				  Dim grs,GroupSettingSet,dianshu
				  Set grs = fycms.actexe("Select GroupSetting From Group_fy Where DefaultGroup=1 and ModeID=" & ModeID)
				  If  grs.eof Then response.End 
				  GroupSettingSet=Split(grs("GroupSetting"),"^@$@^")
				  Regrz=GroupSettingSet(12)
				  dianshu=GroupSettingSet(14)
				  Set AdminRS = Server.CreateObject("adodb.recordset")
				  AdminSql = "select * from User_fy"
				  AdminRS.Open AdminSql, Conn, 1, 3
				  AdminRS.AddNew
				  AdminRS("RegDate") = Now
				  AdminRS("GroupID") = fycms.actexe("Select GroupID From Group_fy Where DefaultGroup=1 and ModeID=" & ModeID)(0)
				  AdminRS("Loginip") = GetIP()
				  AdminRS("LoginTime") = Now
				  AdminRS("UserName") = UserName
				  AdminRS("templetsid") = 1
				  AdminRS("AllianceUser") = AllianceUser
				  AdminRS("UModeID") = ModeID
				  AdminRS("ChargeType") = 1
  				  If dianshu<>"0" Then AdminRS("Score") = dianshu
				  AdminRS("PassWord")=MD5(RPassWord,64)
				  AdminRS("Answer")=Answer
				  AdminRS("Question") = Question
				  Select Case Regrz
						Case "1"
							AdminRS("Locked") = 0
						Case "2"
							 if fycms.IsValidEmail(Email)=false then
								  Call fycms.Alert("请输入正确的电子邮箱!","")	
							 End if
							CheckNum=MD5(fycms.MakeRandom(10))
							AdminRS("Locked") = 1
							AdminRS("CheckNum") = CheckNum
						   Dim Errors,MailBodyStr
						   MailBodyStr="欢迎您注册成为本站会员！<BR><BR>验证码："&CheckNum&"<BR>请点击下面的地址，输入上面的验证码进行邮件验证。验证通过后，您就可以正式成为我们的会员，享受有关服务了！<BR><BR><A HREF="&fycms.Domain &"User/UserRegCheck.asp?UserName=" & UserName &"&CheckNum=" & CheckNum&" TARGET=_BLANK>"&fycms.Domain &"User/UserRegCheck.asp?UserName=" & UserName &"&CheckNum=" & CheckNum
						   Errors=fycms.SendMail(fycms.fycms_Other(3), fycms.fycms_Other(4), fycms.fycms_Other(5), fycms.fycms_Sys(0) & "-会员注册确认信", Email,UserName, MailBodyStr,fycms.fycms_Other(4))
						   IF Errors="OK" Then
								 Errors="注册成功，注册验证码已发送到您的信箱" &Email &"，只有激活后才可以正式成为本站会员!"
						   Else
								Call fycms.Alert("信件发送失败!失败原因:" & Errors & "，请联系网站管理员!","")
						   End if
						Case "3"
							AdminRS("Locked") = 1
				  End Select 
				  AdminRS("Email") = Email
			

				  AdminRS.Update
				  '自定义字段开始入库
			Dim UserID,FieldRS,FieldSql
			Set rs=fycms.actexe("Select top 1 UserID from User_fy  order by UserID desc")
			If Not rs.eof Then UserID = rs("UserID")

 
				  Set FieldRS = Server.CreateObject("adodb.recordset")
				  FieldSql = "select * from "&fycms.ACT_U(ModeID,2)&" where userid<>"&userid&""

 				  FieldRS.Open FieldSql, Conn, 1, 3
				  FieldRS.AddNew
				  FieldRS("UserID") = UserID
 

 				 Dim IF_NULL
				IF_NULL=ActUser_MX_Arr(ModeID)
				If IsArray(IF_NULL) Then
				For I=0 To Ubound(IF_NULL,2)
				 If IF_NULL(2,I)=0 And Trim(fycms.S(IF_NULL(0,I)))="" Then  Call  fycms.ALERT(IF_NULL(1,I)&"不能为空","")
				Next
				End If
				If IsArray(IF_NULL) Then
					For I=0 To Ubound(IF_NULL,2)
 						If IF_NULL(3,I)="NumberType" Then 
						   If fycms.regexField(fycms.S(IF_NULL(0,I)),"^\d+$")=True Then 
							   FieldRS("" & IF_NULL(0,I) & "" )= fycms.S(IF_NULL(0,I))
						   End If 
						ElseIf IF_NULL(3,I)="DateType" Then 
							If IsDate(fycms.S(IF_NULL(0,I)))=False Then 
								FieldRS("" & IF_NULL(0,I) & "")= Now()
							Else 
								FieldRS("" & IF_NULL(0,I) & "")=fycms.S(IF_NULL(0,I))
							End If
						ElseIf IF_NULL(4,I)="1" Then 
								 FieldRS("" & IF_NULL(0,I) & "")= fycms.AField(IF_NULL(5,I))
						ElseIf IF_NULL(4,I)="2" Then 
								If fycms.regexField(fycms.S(IF_NULL(0,I)),IF_NULL(5,I))=True Then 
									FieldRS("" & IF_NULL(0,I) & "")=fycms.S(IF_NULL(0,I))
								Else 
									Call fycms.Alert(IF_NULL(6,I),"")
								End If 
						Else 
							FieldRS("" & IF_NULL(0,I) & "")=fycms.S(IF_NULL(0,I))
						End If 
						actField=""
					Next
				End If
			'结束

				  FieldRS.Update
 				If Regrz="1" Then	
						  Response.Cookies(fycmsN)("UserName") = UserName
						  Response.Cookies(fycmsN)("GroupID") = AdminRS("GroupID")
						  Response.Cookies(fycmsN)("Password") = MD5(RPassWord,64)
						  
						Errors="注册成功!您的用户名:" & UserName & ",您已成为了本站的正式会员!"
				Else
					Errors="注册成功!您的用户名:" & UserName & ",您需要通过管理员的认证才能成为正式会员!"	
				End If 
				Call fycms.Alert(Errors,"index.asp")
			Response.end
		End Sub

   Function ActUser_MX_Arr(ModeID)'返回模型数组
	  Dim Rs
	  Set Rs=fycms.ACTEXE("Select FieldName,Title,IsNotNull,FieldType,[check],regex,regError from Table_fy  Where ModeID=" & ModeID & " and SearchIF=1 and fycms=2  order by OrderID desc,ID Desc")
	 If Not Rs.Eof Then
	  ActUser_MX_Arr=Rs.GetRows(-1)
	 Else
	  ActUser_MX_Arr=""
	 End If
	 Rs.Close:Set Rs=Nothing
   End Function

Sub main()
	Dim TemplateContent,content,RsU
	Application(fycmsN & "fycms_TCJ_Type")= "OTHER"
	Application(fycmsN & "fycmsTCJ")="用户注册协议"
	Application(fycmsN & "link")=fycms.actsys&"user/reg.asp"

	
	TemplateContent=LoadTemplate(fycms.fycms_Sys(17))
	If TemplateContent = "" Then TemplateContent = "模板不存在 by fycms"
	TemplateContent = ACTCode.LabelReplaceAll(TemplateContent)
	Set RsU=fycms.ACTEXE("Select ModeID, ModeName From ModeUser_fy order by ModeID asc")
	IF not Rsu.eof then 
		Do while Not Rsu.eof
		content=content& "<a href=""###""  class=""abtn""   onclick=""document.getElementById('readpact').checked ?window.location.href='?action=RegM&ModeID="&rsu("ModeID")&"' : alert('您必须同意本站注册协议才能进行注册！');"" />"&rsu("ModeName")&"</a>"
		Rsu.movenext
		loop	
	Else 
		echo "未定义操作"
		response.end
	End  if 
	TemplateContent=Replace(TemplateContent,"{$ModeName}",content)
	echo TemplateContent
	
	%>
<%End Sub


sub regok()
	Dim rss,Regrz
	Set Rss = fycms.ACTEXE("SELECT Groupid,GroupSetting FROM Group_fy Where DefaultGroup=1 and  ModeID=" & ModeID & " order by ModeID desc")
	 If rss.eof Then 
		echo "<font color=red>还未设置默认用户组</font>"
		response.end
	 End if	

	 Regrz= Split(Rss("GroupSetting"),"^@$@^")(12)



	Dim TemplateContent
	Application(fycmsN & "fycms_TCJ_Type")= "OTHER"
	Application(fycmsN & "fycmsTCJ")="用户注册"
	Application(fycmsN & "link")=fycms.actsys&"user/reg.asp?action=RegM&ModeID="&ModeID&""
	TemplateContent=LoadTemplate(fycms.fycms_Sys(18))
	If TemplateContent = "" Then TemplateContent = "模板不存在 by fycms"
	TemplateContent = ACTCode.LabelReplaceAll(TemplateContent)

	TemplateContent = Replace(TemplateContent, "{$ModeID}",ModeID)
	If InStr(TemplateContent, "{$regtitle}") > 0  And  regrz>1  Then
		TemplateContent = Replace(TemplateContent, "{$regtitle}", "<font color=red>该组注册需要经过管理员的认证才可以通过</font>")
	Else
		TemplateContent = Replace(TemplateContent, "{$regtitle}","")
	End If 

	If InStr(TemplateContent, "{$RegMode}") > 0   Then
		TemplateContent = Replace(TemplateContent, "{$RegMode}",  U_M.ACT_NoRormMXList(ModeID))
	Else
		TemplateContent = Replace(TemplateContent, "{$RegMode}","")
	End If 
	
		TemplateContent = Replace(TemplateContent, "{$Reg_editor_js}",checkeditpost(ModeID,2))
		TemplateContent = Replace(TemplateContent, "{$Reg_editor_includejs}",writejs("../"))
		TemplateContent = Replace(TemplateContent, "{$AllianceUser}",session("wid"))
		TemplateContent = Replace(TemplateContent, "{$UserName}",session("wusername"))
 

	
	if  fycms.actexe("select RegCode from ModeUser_fy where ModeID="&ModeID&"")(0)= 0 Then
	 TemplateContent=Replace(TemplateContent,"{$regcode}"," <p><label>验 证 码：</label><input type='text' size='10' name='Code'> <img style='cursor:hand;'  src='"&fycms.ActSys&"fy_inc/Code.asp?s=+Math.random();' id='IMG1' onclick=this.src='"&fycms.ActSys&"fy_inc/Code.asp?s=+Math.random();' alt='看不清楚? 换一张！'></p>")
	Else
	 TemplateContent=Replace(TemplateContent,"{$regcode}","")
	End If 

	if  fycms.actexe("select RegCode from ModeUser_fy where ModeID="&ModeID&"")(0)= 0 Then
	 TemplateContent=Replace(TemplateContent,"{$regjscode}","if (form.Code.value=='')"&vbCrLf&"{ alert(""请输入验证码!"");"&vbCrLf&"form.Code.focus(); "&vbCrLf&"return false;"&vbCrLf&"}")
	Else
	 TemplateContent=Replace(TemplateContent,"{$regjscode}","")
	End If 
	
	
	echo TemplateContent

	end sub%>
