<? session_start();?>
<?php include("anti_sql2.php") ?>
<?php include("conn.php") ?>
<? 

$read_db_id=$_GET["id"];
$read_answer=trim($_GET["answer"]);
$read_database_name=$_SESSION["database_name"];
?>

<?php  
//-------------------------------------------------------------读总页号，隐藏域
$read_allpage=$_GET["zong_sele_num"];
//response.Write "zong yehao is="&read_allpage&"<br>"
$allpageint=intval($read_allpage);
//--------------------------------------------------------------读页号，隐藏域
$getcur_page=$_GET["page"];
//response.Write "curent="&getcur_page&"<br>"
//response.Write "zongpage="&read_allpage&"<br>"
$getcur_pageint=intval($getcur_page);

?>
 
 
<?php  
 
   $codeobj=new com("datacode.dbcode"); 
  
?>

<? 

//------------------------------将EXAMINFO.----------

$sql="select  *  from  ".$read_database_name;
$sql=$sql."   where  id=".$read_db_id;
$rs=$conn->execute($sql);

if (!$rs->EOF)
{

  $read_an=$rs->fields["正确答案"];
  
  if ($read_an!='')
  {
    $db_answer=$codeobj->uncodetxt_data($read_an);
	//$db_answer=iconv("gb2312","utf-8",$db_answer);
  } 
} 

$db_answer=trim($db_answer);
$read_answer=trim($read_answer);
//-----------------答案一定要TR--M-----------------
if (($read_answer==$db_answer))
{
   $flag=1;   //答案正确----------------------------
}
  else
{
  $flag=0;   ///答案错误---------------------------
} 

 
?> 
 
 
 
<?php


//--------------------------------------------------------------读页号，隐藏域
$next_page_int=$getcur_pageint+1;
$next_page_str=$next_page_int;

//-----------------------------------------------------------------------
if ($read_answer=='' || $read_answer=="")
{
  $read_answer="0";
}
  else
{
  $read_answer=$read_answer;
} 

//----------------------------------------------------------------读数据库已有的答案信息
if ($read_answer!='' || $read_answer!="")
{

  $read_stu_idid=$_SESSION["studentid"];
  $read_juan_id=$_SESSION["juan_id"];
  $read_mode=$_SESSION['exam_mode'];

  $sql="select  stuid,juan_id,test_ssele  from    studentanswer    where   stuid='".$read_stu_idid."'";
  $sql=$sql."   and   juan_id=".$read_juan_id;
  $rs=$conn->execute($sql);
  $newanswer="";
  
  if (!$rs->EOF)
  {

    $read_database=$rs->fields["test_ssele"];

    for ($g=1; $g<=$allpageint; $g=$g+1)
    {
      if ($g==$getcur_pageint)
      {
        $newanswer=$newanswer.$read_answer;
      }
        else
      {
        $newanswer=$newanswer.substr($read_database,$g-1,1);
      } 
    }
  }
  $rs->close;
  
  //------------------------------------------------------
  $sql="update  studentanswer  set test_ssele='".$newanswer."'";
  $sql=$sql."  where   stuid='".$read_stu_idid."'";
  $sql=$sql."   and   juan_id=".$read_juan_id;

  $rs=$conn->execute($sql);
  $rs->close; 
  
} 




if  ($read_mode=='0')
{
  

    if ($flag==1)     
    { 
         //--------------------------------------------------------------读页号，隐藏域
         if ($getcur_pageint>=$allpageint)
        {
   		/*
   		$url="a0middle_s.php?page=1";
   		echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
   		echo "<body>";
   		echo "<script language=javascript>";
   		echo "window.location.href='$url';";
   		echo "</script>";
   		echo "</body>";
   		*/
  		 echo "1"; //正确已经是最后一题------------------------------------------
       }
       else        //正确 不到最后一题------------------------------------------
      {
	  	/*
   		$url="a0middle_s.php?page=".$next_page_str;
   		echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
   		echo "<body>";
   		echo "<script language=javascript>";
   		echo "window.location.href='$url';";
   		echo "</script>";
   		echo "</body>";
   		*/
  		echo "2";  
      }
     
  } 


  if ($flag==0)
    {
   /*
   $url="a0middle_s.php?page=".$read_allpage;
   echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
   echo "<body>";
   echo "<script language=javascript>";
   echo "window.location.href='$url';";
   echo "</script>";
   echo "</body>";
   */
     echo "3";
   
  } 

?>

<?php 
}
?>




<?php 
  
  //-------------正式考试模式-------------------------------------------
  if  ($read_mode=='1')
  {
     if ($getcur_pageint>=$allpageint)
     {
  		echo "4";
	 }
    else        //正确 不到最后一题------------------------------------------
     {
  	  echo "5";  
     }
  }
	
?>
  
 

<?php 

$rs->close;
$codeobj=null;

?>
