<!--#include file=conn.asp-->
<!--#include file=const.asp -->
<!--#include file=md5.asp -->
<% dim rs , exec %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=sitetitle%></title>
<link rel="stylesheet" href="style/<%=skin%>.css" type="text/css">
</head>

<body>
<!--#include file="head.asp"-->
<br>
<table border="0" width="400" cellspacing="0" cellpadding="10" bordercolorlight="#000000" bordercolordark="#FFFFFF" align="center" class="table004">
 <tr> 
  <td class=table003 align=center>注册用户资料修改
  </td>
  </tr>
  <tr>
  
  <td class="table001" align="center"> 
<%
main()
connclose()

sub main()
	dim backInput, homeInput

	backInput= "<br><br><input type=button value=返回前页 onClick=history.back() class=input2 name=button ><br>"
	homeInput="<br><br><input type=button value=进入留言本首页 onClick=""location.href='index.asp' "" class=input2><br>"

	if request.form="" then
%>

   <form name="form1" method="post">
	<table width="80%" border="0">
	 <tr> 
	  <td width="30%">用 户 名：</td>
	  <td width="70%"> 
	   <input type="text" name="name" size="20" class="input1" value="<%=theUser.name%>" <%if not theUser.admin then response.write "readonly" end if%> maxlength="20">
	  </td>
	</tr>
	 <tr> 
	  <td>旧 密 码：</td>
	  <td> 
	   <input type="password" name="pass" size="20" class="input1" value="" maxlength="20" >
	  </td>
	 </tr>
	<tr> 
	 <td>新 密 码：</td>
	 <td>
	   <input type="password" name="npass1" size="20" class="input1" maxlength="20" >
	  </td>
	</tr>
	<tr> 
	 <td>密码确认：</td>
	 <td>
	   <input type="password" name="npass2" size="20" class="input1" maxlength="20" >
	  </td>
	</tr>
	<tr>
	  <td>性　　别：</td>
	  <td >
	   <input type="radio" name="male" value="1" <% if theUser.male then response.write "checked" %>>男
	   <input type="radio" name="male" value="0" <% if not theUser.male then response.write "checked" %> >女
	 （已注册用户不用填）
	  </td>
	 </tr>
	 <tr> 
	  <td>头　　像：</td>
	  <td >
	   <a href=### onclick=window.open("face.asp","face","width=400,height=400,resizable=1,scrollbars=1") title=点击选择头像>
	   <img src="<%if theUser.face<>"" then response.write theUser.face else response.write "face/m01.gif"%>" border=0 id="faceImg"></a>
	   <input class="input1" <%if theUser.master then response.write "type=text onchange=document.all.faceImg.src=this.value" else response.write "type=hidden"%> name="face" value="<%if theUser.face<>"" then response.write theUser.face else response.write "face/m01.gif"%>">
	  </td>
	 </tr>
	 <tr> 
	  <td>电子邮件：</td>
	  <td> 
	   <input type="text" name="email" size="20" class="input1" value="<%=theUser.email%>">
	  </td>
	 </tr>
	 <tr> 
	  <td>　 QQ 　：</td>
	  <td>
	   <input type="text" name="qq" size="20" class="input1" value="<%=theUser.qq%>">
	  </td>
	 </tr>
	 <tr> 
	  <td>　 ICQ &nbsp;：</td>
	  <td>
	   <input type="text" name="icq" size="20" class="input1" value="<%=theUser.icq%>">
	  </td>
	 </tr>
	 <tr> 
	  <td>　 MSN &nbsp;：</td>
	  <td>
	   <input type="text" name="msn" size="20" class="input1" value="<%=theUser.msn%>">
	  </td>
	 </tr>
	 <tr> 
	  <td>主页地址：</td>
	  <td> 
	   <input type="text" name="url" size="30" value="<% if theUser.url="" then response.write "http://" else response.write theUser.url%>" class="input1">
	  </td>
	 </tr>
	 <tr align="center"> 
	  <td colspan="2" height="40"> 
	   <input type="submit" value=" 更 改 " class="input2" name="Submit" >
	  </td>
	</tr>
   </table>
   </form>
<%
	else
		dim name, pass, npass1, npass2,male,face,email,qq,url,icq,msn
		name=Encodestr(request.form("name"))
		pass=Encodestr(request.form("pass"))
		npass1=Encodestr(request.form("npass1"))
		npass2=Encodestr(request.form("npass2"))
		male=Encodestr(request.form("male"))
		face=Encodestr(request.form("face"))
		email=Encodestr(request.form("email"))
		qq=Encodestr(request.form("qq"))
		url=Encodestr(request.form("url"))
		icq=Encodestr(request.form("icq"))
		msn=Encodestr(request.form("msn"))
		
		if not theUser.reged then
			response.write "<font color=red>发生错误</font><br><br>你还没有登陆，不能修改资料！"
			response.write backinput
			exit sub	
		end if
		
		if name="" or pass="" then
			response.write "<font color=red>发生错误</font><br><br>请输入用户名和密码！！！"
			response.write backInput
			exit sub
		end if
		if npass1<>npass2 then
			response.write "<font color=red>发生错误</font><br><br>新密码和确认密码要相同！！！"
			response.write backInput
			exit sub
		end if
		
		pass=MD5(pass)
		set rs=server.createobject("adodb.recordset")
		
		if theUser.admin and theUser.name<>name then
			exec="select userid from [user] where username='"& replace(name,"'","") &"' and userid<>"& theUser.id
			rs.open exec,conn,1,1
			if not rs.eof then
				response.write "<font color=red>发生错误</font><br><br>新用户名已经有人使用！！！"
				response.write backInput
				exit sub
			end if
			rs.close
		end if
		
		exec="select * from [user] where userid="&theUser.id
		rs.open exec,conn,1,3
		if rs.eof then
			rsclose()
			response.write "<font color=red>发生错误</font><br><br>用户名不存在或密码错误！！！"
			response.write backInput
			exit sub
		end if
		if name<>theUser.name then
			rs("username")=name
		end if
		if npass1<>"" then
			pass=MD5(npass1)
			rs("userpassword")=pass
		end if
		if rs("sex")="1" and male="0" or rs("sex")<>"1" and male="1" then
			rs("sex")=male
			exec="update ly set male='"&male&"' where bl=1 and name='"&name&"'"
			conn.execute(exec)
		end if
		if rs("GBface")="" or rs("GBface")<>face then
			rs("GBface")=face
			exec="update ly set face='"&face&"' where bl=1 and name='"&name&"'"
			conn.execute(exec)
		end if
		if isNull(rs("useremail")) or rs("useremail")<>email then
			if email="" then
				rs("useremail")=null
				exec="update ly set email=null where bl=1 and name='"&name&"'"
			else
				rs("useremail")=email
				exec="update ly set email='"&email&"' where bl=1 and name='"&name&"'"
			end if
			conn.execute(exec)
		end if
		if isNull(rs("oicq")) or rs("oicq")<>qq then
			if qq="" then
				rs("oicq")=null
				exec="update ly set qq=null where bl=1 and name='"&name&"'"
			else
				rs("oicq")=qq
				exec="update ly set qq='"&qq&"' where bl=1 and name='"&name&"'"
			end if
			conn.execute(exec)
		end if
		if isNull(rs("homepage")) or rs("homepage")<>url then
			if url="" then
				rs("homepage")=null
				exec="update ly set url=null where bl=1 and name='"&name&"'"
			else
				rs("homepage")=url
				exec="update ly set url='"&url&"' where bl=1 and name='"&name&"'"
			end if
			conn.execute(exec)
		end if
		if isNull(rs("icq")) or rs("icq")<>icq then
			if icq="" then
				rs("icq")=null
				exec="update ly set icq=null where bl=1 and name='"&name&"'"
			else
				rs("icq")=icq
				exec="update ly set icq='"&icq&"' where bl=1 and name='"&name&"'"
			end if
			conn.execute(exec)
		end if
		if isNull(rs("msn")) or rs("msn")<>msn then
			if msn="" then
				rs("msn")=null
				exec="update ly set msn=null where bl=1 and name='"&name&"'"
			else
				rs("msn")=msn
				exec="update ly set msn='"&msn&"' where bl=1 and name='"&name&"'"
			end if
			conn.execute(exec)
		end if
		
		rs.update
		rsclose()
		response.write "<font color=red>修改成功！！！</font>"
		response.write homeInput

		if cookiePath<>"" then
			response.cookies("gbook").Path=cookiePath
		end if
		response.cookies("gbook")("username")=vbescape(name)
		response.cookies("gbook")("password")=pass

	end if
end sub %>
   </td>
 </tr>
</table>
<!--#include file="foot.asp"-->

</body>

</html>
