<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/check.asp"-->
<!--#include file="inc/md5.asp"-->
<!--#include file="inc/chkinput.asp"-->
<!--#include file="inc/cls_email.asp"-->
<%
Dim HtmlContent,XMLDom,HeadTitle

If Newasp.CheckStr(LCase(Request("action"))) = "save" Then
	Call saveUserinfo()
Else
	HeadTitle = "个人设置"
	HtmlContent = NewAsp.LoadTemplate("userinfoset")
	HtmlContent = Replace(HtmlContent, "{$HeadTitle}", HeadTitle)
	HtmlContent = Replace(HtmlContent, "{$UserName}", NewAsp.UserName)
	HtmlContent = Replace(HtmlContent, "{$UserSex}", NewAsp.UserSex)
	If NewAsp.UserSex = 0 Then
		HtmlContent = Replace(HtmlContent, "{$CheckedSex0}", " checked=""checked""")
		HtmlContent = Replace(HtmlContent, "{$CheckedSex1}", "")
	Else
		HtmlContent = Replace(HtmlContent, "{$CheckedSex0}", "")
		HtmlContent = Replace(HtmlContent, "{$CheckedSex1}", " checked=""checked""")
	End If
	HtmlContent = Replace(HtmlContent, "{$UserEmail}", NewAsp.UserSession.documentElement.selectSingleNode("userinfo/@useremail").text & "")
	HtmlContent = Replace(HtmlContent, "{$MyQQ}", NewAsp.UserSession.documentElement.selectSingleNode("userinfo/@qq").text & "")
	HtmlContent = Replace(HtmlContent, "{$MyMsn}", NewAsp.UserSession.documentElement.selectSingleNode("userinfo/@msn").text & "")
	HtmlContent = Replace(HtmlContent, "{$MyHomePage}", NewAsp.UserSession.documentElement.selectSingleNode("userinfo/@homepage").text & "")
	HtmlContent = Replace(HtmlContent, "{$UserIntro}", Server.HTMLEncode(NewAsp.UserSession.documentElement.selectSingleNode("userinfo/@intro").text & ""))
	Response.Write NewAsp.ArchiveHtml(HtmlContent)
End If
NewAsp.CloseConn()

Sub saveUserinfo()
	Dim username,loginpass,UserPassword,verifypass,useremail
	Dim usersex,question,answer,strIntro,Homepage,qq,msn
	Dim Rs,SQL,i
	Response.Write "<script language=""JavaScript"">function resetcode(){try{var obj=top.document.getElementById('verifycodeimg');obj.src='inc/getcode.asp?t='+Math.random();}catch(e){}}</script>"
	loginpass = Trim(Request.Form("loginpass"))
	verifypass = Trim(Request.Form("verifypass"))
	If loginpass <> "" Then
		If loginpass <> verifypass Then
			Response.Write "<script>alert('友情提示!\n\n两次输入的密码不同,请重新输入密码!');resetcode();</script>"
			Exit Sub
		End If
		If Len(loginpass) < 6 Then
			Response.Write "<script>alert('友情提示!\n\n密码不能小于6位,请重新输入密码!');resetcode();</script>"
			Exit Sub
		End If
		UserPassword = Md5(loginpass,16)
	End If
	useremail = NewAsp.RequestForm("useremail",45)
	If Not IsValidEmail(useremail) Then
		Response.Write "<script>alert('友情提示!\n\n邮件地址格式不正确!');resetcode();</script>"
		Exit Sub
	End If
	If Not NewAsp.CodeIsTrue() Then
		Response.Write "<script>alert('友情提示!\n\n您的验证码输入错误!');resetcode();</script>"
		Exit Sub
	End If
	usersex = NewAsp.ChkNumeric(Request.Form("sex"))
	question = NewAsp.RequestForm("question",45)
	answer = NewAsp.RequestForm("answer",45)
	strIntro = NewAsp.RequestForm("Intro",251)
	Homepage = NewAsp.RequestForm("Homepage",150)
	qq = NewAsp.ChkNumeric(Request.Form("qq"))
	msn = NewAsp.RequestForm("msn",45)
	If msn <> "" Then
		If Not IsValidEmail(msn) Then
			Response.Write "<script>alert('友情提示!\n\您的MSN输入错误!');resetcode();</script>"
			Exit Sub
		End If
	End If
	If Len(Homepage) > 8 Then
		If CheckeIsURL(Homepage) = False Then
			Response.Write "<script>alert('友情提示!\n\n您输入的个人主页地址不合法!');resetcode();</script>"
			Exit Sub
		End If
	End If
	If Not IsObject(Conn) Then ConnectionDatabase
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM NC_Ask_Users WHERE userid=" & NewAsp.UserID
	Rs.Open SQL,Conn,1,3
	If Rs.BOF And Rs.EOF Then
		Set Rs = Nothing
		Exit Sub
	Else
		If loginpass <> "" Then Rs("password") = UserPassword
		'Rs("nickname") = username
		'Rs("UserTitle") = ""
		Rs("Useremail") = Useremail
		Rs("Usersex") = Usersex
		'Rs("Photo") = ""
		If qq > 3 Then Rs("qq") = qq
		If Len(msn) > 5 Then Rs("msn") = msn
		If Len(Homepage) > 10 Then Rs("Homepage") = Homepage
		If question <> "" Then Rs("question") = question
		If answer <> "" Then Rs("answer") = md5(answer,16)
		If strIntro <> "" Then Rs("Intro") = strIntro
		Rs.Update
	End If
	Rs.Close : Set Rs = Nothing
	If loginpass <> "" Then
		Response.Cookies(NewAsp.Asked_sn)("password") = UserPassword
	End If
	Response.Cookies(NewAsp.Asked_sn)("usersex") = Usersex
	Response.Write "<script language='JavaScript'>alert('恭喜您!修改个人信息成功');try{"
	Response.Write "top.location.replace(document.referrer);"
	Response.Write "}catch(e){}"
	Response.Write "</script>"
End Sub

%>