<%page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>
<%
@ include file="../Connections/cnJP.jsp" %>
<html>
<head>
<title>Select Quiz</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<% 
  
// p2.jsp by John Phillips on 9/13/2003
  // This jsp script is called from p2form.html. Its purpose is to validate the user 
  // and to present a list of available quizzes for the user to take.

  // Retrieve the params passed from p2form.html.
  
String uid = new Stringrequest.getParameter("userId") );
  
String password = new Stringrequest.getParameter("password") );

  
// commect to the database  
  
Driver driverRS = (Driver)Class.forName(MM_cnJP_DRIVER).newInstance();
  
Connection connRS DriverManager.getConnection(MM_cnJP_STRING,MM_cnJP_USERNAME,MM_cnJP_PASSWORD);
  
  
// look up user in the user table and validate the password
  
String q = new String"SELECT cuid, password FROM JPuser WHERE userId = '" uid "'" );
  
PreparedStatement ps connRS.prepareStatement);
  
ResultSet rs ps.executeQuery();
  if( 
rs.next() && rs.getString("password").compareTo(password) == ) {
  
    
// the user is valid; get their cuid for later use (computer user id)
    
int cuid rs.getInt("cuid");

    
// let user select the quiz they want to take
    
"SELECT cqid, qname FROM JPquizzes";
    
ps connRS.prepareStatement);
    
rs ps.executeQuery();
    
%>
      <form name="form1" method="post" action="showquiz.jsp">
      <p>
      <% while( rs.next() ) { %>
        <label>
        <input type="radio" name="cqid" value="<%= rs.getInt("cqid"%>">
        <%= rs.getString("qname"%>
        </label>
        <br>
      <% %>
      </p>
      <p><input type="hidden" name="cuid" value="<%= cuid %>">
      <input type="submit" name="Submit"  value="Take Quiz"></p>
    </form>    
  <% 
  else { 
    
// invalid user; print error message with link back to log in screen
    
%>
    Either your user ID or password were not entered correctly. 
    <a href="p2form.html">Click here to try again.</a>
    <%
  
}
  
  
rs.close();
  
ps.close();
  
connRS.close();
  
%>
</body>
</html>