<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<%@ page import="java.sql.*"%> 
<%@ page import="java.util.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%@ include file="../inc/conn.jsp"%>
<%!String regurl,msg,sign;%>
<%
String img;
String bbsuser=new String(request.getParameter("bbsuser").getBytes("iso-8859-1"));
String name=new String(request.getParameter("name").getBytes("iso-8859-1"));
String clubuser_sex=new String(request.getParameter("clubuser_sex").getBytes("iso-8859-1"));
String password=new String(request.getParameter("password").getBytes("iso-8859-1"));
String question=new String(request.getParameter("question").getBytes("iso-8859-1"));
String answer=new String(request.getParameter("answer").getBytes("iso-8859-1"));
String email=new String(request.getParameter("email").getBytes("iso-8859-1"));
String IP=request.getRemoteAddr();

Date currTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss",Locale.US);
String ftime=new String(formatter.format(currTime).getBytes("iso-8859-1"));

if(clubuser_sex=="男")
{
img="cache37.gif";
}
else {
img="cache41.gif";
}

String sql="select * from clubuser where clubuser_name='"+name+"'";
ResultSet rs=stmt.executeQuery(sql); 

if (rs.next()){
	out.println("<p>此用户名已存在,请选择其他的用户名!</p>");
	out.println("<A HREF=javascript:window.history.back()>[重新注册]</A>");
	out.close();
		}
else {
    sql="insert into clubuser(clubuser_name,clubuser_nickname,clubuser_password,clubuser_question,clubuser_answer,clubuser_sex,clubuser_email,clubuser_reg_date,clubuser_lasttime,clubuser_ip,userimg)";
    sql=sql+" values('"+name+"','"+bbsuser+"','"+password+"','"+question+"','"+answer+"','"+clubuser_sex+"','"+email+"','"+ftime+"','"+ftime+"','"+IP+"','"+img+"')";

	stmt.executeUpdate(sql);
	
     //Cookie c=new Cookie("clubusername",name);
     //response.addCookie(c);
	 //Cookie d=new Cookie("pass",password);
     //response.addCookie(d);
     //Cookie e=new Cookie("bbsuser",bbsuser);
     //response.addCookie(e);
	 //Cookie f=new Cookie("bz","0");
     //response.addCookie(f);
     //Cookie g=new Cookie("bbsadmin","0");
     //response.addCookie(g);
	 //Cookie h=new Cookie("payuser","0");
     //response.addCookie(h);
	 	 	 
	session.setAttribute("bbsuser",bbsuser);
	session.setAttribute("name",name);
	session.setAttribute("bz","0");
	session.setAttribute("bbsadmin","0");
	session.setAttribute("payuser","0");
	
    msg="恭喜你，注册成功！";
    sign="y";
    String smscontent="欢迎您加入本站点参加交流和讨论，本站点为公共论坛，为维护网上公共秩序和社会稳定，请您自觉遵守我们的条款";
    String str="insert into sms(title,content,accepter,bbssystem) values('"+msg+"','"+smscontent+"','"+name+"',2)";
	stmt.executeUpdate(str);
    regurl="main.jsp";
	}
%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="refresh" content="3;URL=<%=regurl%>">
<BR><BR><BR>
<TABLE border=0 align=center>
<TR>
	<TD align=center>
	<%=msg%><BR><BR>
	<A HREF="javascript:window.history.back()">[重新注册]</A>
	系统将在3秒钟后自动返回，您也可以直接手工点击<A HREF="<%=regurl%>"><FONT  COLOR="blue">[返 回]</FONT></A><BR>
	</TD>
</TR>
</TABLE>