<%page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"  %>
<%
@ include file="../Connections/cnJP.jsp" %>
<%
  
// showquiz.jsp by John Phillips on 9/13/2003
  // This jsp script is called from p2.jsp. Its purpose is to show the user
  // the quiz they selected and to allow them to take the quiz.

  // Retrieve the params passed from p2.jsp.
  // cqid is the primary key for the quizzes table (computer quiz id)
  // cuid is the primary key for the user table (computer user id)
  
String cqid request.getParameter("cqid");
  
String cuid request.getParameter("cuid");
  
  
// connect 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);

  
// get the appropriate quiz from the database
  
String q = new String"SELECT cqid, qname, quiz FROM JPquizzes WHERE cqid = '" cqid "'" );
  
PreparedStatement ps connRS.prepareStatement);
  
ResultSet rs ps.executeQuery();
  if( 
rs.next() ) {
    
String quiz rs.getString("quiz");

    
// create a new record in the results table with a start timestamp for this user
    // this tells the instructor that the student has seen this quiz at a certain time
    
"INSERT INTO JPresults (uid, qid, start) values (" cuid ", " cqid ", GETDATE() )";
    
ps connRS.prepareStatement);
    
ps.executeUpdate();

    
// Display the quiz to the student
    
%>
    <html><head><title>quiz</title>    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head><body>
    <form name="form1" method="post" action="gradeit.jsp">
    <%= quiz %>
    <p><input type="hidden" name="cuid" value="<%= cuid %>">
    <input type="hidden" name="cqid" value="<%= cqid %>"> 
    <input type="submit" name="Submit" value="Submit Quiz"></p> 
    </body></html>
    <%
  

  else {
    
out.print( "There was an error (showquiz) with this quiz. Please inform the instructor." );
  }
  
  
rs.close();
  
ps.close();
  
connRS.close();
%>