<jsp:useBean id="db" scope="page" class="chatweb.conn" />
<%@ page import="java.sql.*"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.*"%>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ include file="../Common.jsp" %>
<html>
<head>
<title>登陆界面</title>
<style type="text/css">
<!--
.f {
	font-size: 12px;
}
-->
</style>
<link href="../chat.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body bgcolor="#FFF7DD">
<%! String logname,logpass;
    int times; %>
<div align="center">
  <p>&nbsp;</p>
  <p>&nbsp; </p>
  <font color="#FF0000">
  <%

  if(request.getParameterValues("login") != null){
    logname=request.getParameter("username");
    logpass=request.getParameter("password");
    //logname=getStr(logname);
    //logpass=getStr(logpass);
    int islogin=db.login(logname,logpass);
    switch(islogin){
    	case 0:case 1:
		session.setAttribute("username",logname);
           	session.setAttribute("grade",Integer.toString(islogin));
		Calendar ca = Calendar.getInstance();
		int m=ca.get(Calendar.MINUTE);//得到用户登陆的分钟数，用以判断超作是否超时
                if(getServletContext().getAttribute(logname)==null){
			if(getServletContext().getAttribute("chatUser")==null){//初始化用户列表
				Vector chatUser=new Vector();
				chatUser.addElement(logname);
				getServletContext().setAttribute("chatUser",chatUser);
			}
			else{
				Vector tempVector=(Vector)getServletContext().getAttribute("chatUser");
				tempVector.addElement(logname);
				getServletContext().setAttribute("chatUser",tempVector);
			}
		String msg="[系统消息]"+getStr(logname)+"来了";
		addToChatmsg(msg);
                }
		getServletContext().setAttribute(logname,Integer.toString(m));
		break;
        case -2:
		out.println("用户不存在!<br>");
		break;
	case -1:
		out.println("密码错误！<br>");
		break;
        default:
		break;
    }
  }
  if(session.getAttribute("username")!=null){%>
  <script language="JavaScript" type="text/JavaScript">
  parent.location.href="../index.htm";
  </script>
  <%}

  %>

  </font>
  <p>&nbsp;</p>
  <form name="form1" method="post" action="">
    <table width="200" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>&nbsp;</td>
        <td><div align="right"><span class="f">还没注册?请点<a href="reg.jsp">这里</a></span></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="right">User:</div></td>
        <td><input name="username" type="text" id="username"></td>
      </tr>
      <tr>
        <td><div align="right">Password:</div></td>
        <td><input name="password" type="password" id="password"></td>
      </tr>
      <tr valign="bottom">
        <td height="40" colspan="2"> <div align="center">
            <input name="login" type="submit" id="login2" value="提交">
            <input type="reset" name="Submit" value="重置">
            <input type="button" name="Submit2" value="离开" onClick="MM_openBrWindow('../enter.htm','','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');parent.window.close()">
          </div></td>
      </tr>
    </table>
<%
%>
  </form>
</div>
</body>
</html>