<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="java.sql.*"%>
<%@ page import="java.lang.Math.*" %>
<%@ page import="java.util.*" %>
<jsp:useBean id="conn" scope="page" class="test.ConnOracle"/>
<%@ include file="/public/checkvalidadmin.jsp"%>
<%@ include file="/public/checkvalidadmin8.jsp"%>

<%!
String id = "";
String sql = "";
ResultSet rs = null;
ResultSet rs1 = null;


String tmpquestionid = "";
String currpage = "1";            // 在连续的几个页面中，一直保存当前页面，便于用户操作
%>
<html>

<head>
<title>题目信息修改</title>
    <link rel="stylesheet" href="../public/style.css">
	<script language="javascript">
	// 函数mycheck()的作用是验证用户修改题库信息的正确性
	function mycheck() {
		var tmp_selectid = document.myform.selectid.selectedIndex;
		var tmp_answer   = document.myform.answer.value;
        var tmp_choice1  = document.myform.choice1.value;
        var tmp_choice2  = document.myform.choice2.value;
        var tmp_choice3  = document.myform.choice3.value;
        var tmp_choice4  = document.myform.choice4.value;

        if(document.myform.qname.value == "") {
		    alert("请输入题目！");
			return;
		}
        if(tmp_choice1.length==0 || tmp_choice2.length==0 || tmp_choice3.length==0 || tmp_choice4.length==0 ) {
		    alert("请输入各个选项！");
			return;
		}
        if(tmp_answer.length == 0) {
		    alert("请选择题目答案！");
			return;
		}
		if(tmp_selectid==0 && tmp_answer.length>1) {
		    alert("单选题的答案应该唯一！");
			return;
		}
        if(tmp_answer.length > 4) {
		    alert("多选题最多4个答案！");
			return;
		}
		document.myform.submit();
	}
	</script>
</head>
<%
currpage   = request.getParameter("Page");

sql = "select * from test_classinfo";
try {
   rs1 = conn.executeQuery( sql );
}catch(Exception e) {
   out.println("访问课程信息数据出错！");
   return;
}
if(!rs1.next()) {
   out.println("系统数据库中无课程信息数据！");
   return;
}


id = request.getParameter("id");
sql="SELECT * from test_question_lib where questionid=" + id;

try {
   rs = conn.executeQuery( sql );
}catch(Exception ee) {
   out.println("访问数据库错误！");
   return;
}

if(!rs.next()) {
	out.println("错误的ID号");
	return;
}else {
%>
<center>
<form name="myform" action="questionsavemodify.jsp" method="post">
	<input type="hidden" name="Page" value="<%=currpage%>">
	<table width="90%" HEIGHT=100% border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
	  <tr bgcolor="#FAD185"> 
		<%
		tmpquestionid = rs.getString("questionid");
	    %>
		<td colspan=6 height=20 align=center><b>题目信息修改==>题目编号：<%=tmpquestionid%></b></td>
		<input type="hidden" name="questionid" value="<%=tmpquestionid%>">
	  </tr>
      
	  <tr> 
		<td colspan=6 valign=top>
		<textarea name="qname" rows=20 cols=150><%=rs.getString("qname")%></textarea></td>
	  </tr>
      <tr>
		  <td width=10%>选项A</td>
		  <td colspan=5><textarea name="choice1" rows=2 cols=135><%=rs.getString("choice1")%></textarea></td>
	  </tr>
      <tr>
		  <td>选项B</td>
		  <td colspan=5><textarea name="choice2" rows=2 cols=135><%=rs.getString("choice2")%></textarea></td>
	  </tr>
      <tr>
		  <td>选项C</td>
		  <td colspan=5><textarea name="choice3" rows=2 cols=135><%=rs.getString("choice3")%></textarea></td>
	  </tr>
      <tr>
		  <td>选项D</td>
		  <td colspan=5><textarea name="choice4" rows=2 cols=135><%=rs.getString("choice4")%></textarea></td>
	  </tr>
      <tr>
		  <td>题目类别</td>
		  <td>
		  <select name="selectid">
		  <%
		     int tmpselectid = rs.getInt("selectid");
	         if(tmpselectid==1) {
		        out.println("<option value=1 selected>单选题</option>");
		        out.println("<option value=2>多选题</option>");
			 }else {
		        out.println("<option value=1>单选题</option>");
		        out.println("<option value=2 selected>多选题</option>");
			 }
	      %>
          </selectid>
		  </td>
		  <td>对应班级</td>
		  <td>
		  <select name="classid">
				
				    <%
				        String currClassId = rs.getString("classid");
				        do{
				            
				        	String classname = rs1.getString("classname");
				        	String classid = rs1.getString("classid");
				    %>  	
				        	<option value=<%=classid%>   <%if(classid.equals(currClassId))   out.println("selected");%> ><%=classname%> </option>
				    <%
				        }while(rs1.next());
				    %> 
				
          </select>
		  </td>
		  <td>答案</td>
		  <td><input type=text title="输入答案时请按照字母次序进行输入,例如：AB / ABD" name=answer value="<%=rs.getString("answer")%>"></td>
	  </tr>
      <tr>
		  <td align=center colspan=6>
		      <input type="button" value="保存所做修改" onclick="mycheck()">&nbsp;&nbsp;&nbsp;
	          <input type="button" value="返回上一页面" onclick=javascript:history.back()>
		  </td>
	  </tr>
	</table>
<%
}
%>
</form>
</center>
</html>