<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<jsp:useBean id="conn" scope="page" class="test.ConnOracle"/>
<%@ include file="/public/checkvalidstudent.jsp"%>
<%!
    ResultSet rs     = null;                 // 执行Sql语句返回的结果集
	String sql = "";
	String classid = "";
	String classname = "";                   // 测试班级名称
	int examtime = 0;              // 考试时间
	int total_question_in_paper;   // 每份试卷中的考题数目
	int total_paper_num=0;         // 试卷总数
	int paper_array[];
    int curr_paperid=0;            // 当前命中的试卷号
%>

<%
classid = request.getParameter("classid");

if(classid == null) {
    out.println("系统错误, 无正确的班级ID号！");
	return;
}

sql = "select * from test_classinfo where classid='" + classid + "'";
try {
    rs  = conn.executeQuery( sql );
}catch(Exception ee) {
    out.println("<center>");
	out.println("访问课程信息出错！请将以下信息告知系统管理员。<br>");
	out.println(ee.toString() + "<br>");
	out.println("<a href=javascript:history.back()>单击这里返回</a>");
    out.println("</center>");
}
if(!rs.next()) {
    out.println("数据库中没有课程信息，无法进行考试！");
    return;
}
classname = rs.getString("classname");
examtime  = rs.getInt("totaltime");
total_question_in_paper = rs.getInt("totalques");
total_paper_num = rs.getInt("totalpaper");

// 下面从班级代码为classid的试卷中随机抽取一套，进行考试
sql = "select distinct paper_id from test_paper_info where classid='" + classid + "'";
rs  = conn.executeQuery( sql );
if(!rs.next()) {
       out.println("还没有班级代号为 " +  classid + " 的试题，请联系管理员！");
	   return;
}

paper_array = new int[total_paper_num];
int index=0;
do{
    paper_array[index++] = rs.getInt("paper_id");
}while(rs.next());
curr_paperid = paper_array[(int)Math.floor(Math.random()*total_paper_num)];
session.setAttribute("paperid",""+curr_paperid);
session.setAttribute("classid",""+classid);

sql = "select * from TEST_PAPER_INFO where paper_id=" + curr_paperid;
rs  = conn.executeQuery( sql );
%>

<html>
<head>
<script language="JavaScript">
 var hours
 hours=0
 var minutes
 minutes=0
 var seconds
 seconds=1
 function show1(){
 var Digital=new Date()
 var shours=Digital.getHours()
 var sminutes=Digital.getMinutes()
 var sseconds=Digital.getSeconds()
 var dn="AM" 
 if (shours>12){
 	dn="PM"
 	shours=shours-12
 }
 if (shours==0)
 	shours=12
 if (sminutes<=9)
 	sminutes="0"+sminutes
 if (sseconds<=9)
 	sseconds="0"+sseconds
 var sctime="<b><font face='Verdana' color='#8000FF'>"+shours+":"+sminutes+":"+sseconds+" "+dn+"</font></b>"
 if (!document.all)
 	document.write(sctime)
 else
 	tick1.innerHTML=sctime
 }
 
 function show2(){

 seconds=parseInt(seconds)+1
 minutes=parseInt(minutes)+0
 hours=parseInt(hours)+0
 
 if (parseInt(seconds)==60){
 	minutes=parseInt(minutes)+1
 	seconds=0
 	}
 if (parseInt(minutes)==<%=examtime%>){
 	alert("考试时间到!")
 	document.form1.submit()
 	return;
 	}

  if (parseInt(minutes)==60){
 	hours=parseInt(hours)+1
 	minutes=0
 	}
 if (minutes<=9){ 	
 	if (seconds<=9){
 	var ctime="<b><font face='Verdana' color='#8000FF'>0"+hours+":0"+minutes+":0"+seconds+"</font></b>"	
 	}else{
 	var ctime="<b><font face='Verdana' color='#8000FF'>0"+hours+":0"+minutes+":"+seconds+"</font></b>"
 	}
 }else{
 	if (seconds<=9){
 	var ctime="<b><font face='Verdana' color='#8000FF'>0"+hours+":"+minutes+":0"+seconds+"</font></b>"
 	}else{
 	var ctime="<b><font face='Verdana' color='#8000FF'>0"+hours+":"+minutes+":"+seconds+"</font></b>"
 	}
 }
 
 if (!document.all)
	 document.write(ctime)
 else
 	tick2.innerHTML=ctime
 }
 
 function loadclock(){
 if (document.all)
 	show1()
 	setInterval("show2()",1000)
 }
 if (!document.all)
 	show2()
 </script>

 <Script Language=javascript >
     function Click(){
     if(event.button==2){alert
     ('您不需要使用右键！');
     }}
     document.onmousedown=Click;
     </Script>
<title>入学测试试题</title>
<link rel="stylesheet" href="../public/style.css">
</head>

<body bgcolor="#FFFFFF" onload="Javascript:loadclock()" background="../images/bg3.gif">
<center>
  <table width="756" border="0">
    <tr> 
      <td rowspan="2" valign="bottom"><b><font size="4" color="#FF0000"><%=classname%>入学测试</font></b> 
       
      </td>
      <td width="125"> 
        <div align="left"><b>考试时间</b>：<br>
          <b><font face="Verdana" color="#8000FF" size="2"><%=examtime%> </font></b><font face="Verdana" color="#8000FF"><b>minutes</b></font></div>
      </td>

      <td width="125"> <b>开始时间</b>：<br>
        <span id=tick1></span> </td>
      <td width="125"> <b>使用时间:</b><br>
        <span id=tick2></span> </td>
    </tr>
  </table>
<hr size="1">

<form name="form1" method="post" action="getscore.jsp" target="_top">
<table width="400" border="0" align="center">
  <tr>
    <td><%=classname%>入学测试</td>
  </tr>
</table>


<%
int question_index=1;
int tmp_questionid=0;
while(rs.next()) {
tmp_questionid=rs.getInt("QUESTIONID");
%>
	<table width="75%" border="0">
    <%
	if(rs.getInt("selectid")==1) {
    %>
	<tr> 
      <td width="15%" align="left" valign="top">答案</td>
      <td width="85%"><%="<font color=blue>(" + question_index + ")</font> " + rs.getString("qname")%>(单选题)</td>
    </tr>
	<tr>
          <td> <input type="radio" name="<%=tmp_questionid%>" value="A">A</td><td><%=rs.getString("choice1")%></td></tr>
 	<tr>
          <td> <input type="radio" name="<%=tmp_questionid%>" value="B">B</td><td><%=rs.getString("choice2")%></td></tr>
	<tr>
          <td> <input type="radio" name="<%=tmp_questionid%>" value="C">C</td><td><%=rs.getString("choice3")%></td></tr>
	<tr>
          <td> <input type="radio" name="<%=tmp_questionid%>" value="D">D</td><td><%=rs.getString("choice4")%></td></tr>
    <%
    }else {	
	%>
	<tr> 
      <td width="15%" align="left" valign="top">答案</td>
      <td width="85%"><%="<font color=blue>(" + question_index + ")</font> " + rs.getString("qname")%><font color=red>(多选题)</font></td>
    </tr>
	<tr>
          <td> <input type="checkbox" name="<%=tmp_questionid%>" value="A">A</td><td><%=rs.getString("choice1")%></td></tr>
 	<tr>
          <td> <input type="checkbox" name="<%=tmp_questionid%>" value="B">B</td><td><%=rs.getString("choice2")%></td></tr>
	<tr>
          <td> <input type="checkbox" name="<%=tmp_questionid%>" value="C">C</td><td><%=rs.getString("choice3")%></td></tr>
	<tr>
          <td> <input type="checkbox" name="<%=tmp_questionid%>" value="D">D</td><td><%=rs.getString("choice4")%></td></tr>
    <%}%>
    </table><p></p>
<%
question_index++;
}			 
%>	
<p align="center"> 
    <input type="hidden" name="totaltime" value="0">
    <input type="button" name="submita" value="提交答卷"  onclick="JavaScript:subit()">
  </p>
</form>
</center>
</body>
</html>
<script language="JavaScript">
function subit(){
if ((confirm("你确定提交试卷吗？\n点“确定”提交，点“取消”返回检查"))==true){
	document.form1.totaltime.value = minutes;
	document.form1.submit();
	}
}
</script>