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

<? 

$read_db_id=$_GET["id"];
$read_answer=$_GET["answer"];
$read_database_name=$_SESSION["database_name"];

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

//--------------------------------------------------------------读页号，隐藏域

$next_page_int=$getcur_pageint+1;
$next_page_str=($next_page_int);

//-----------------------------------------------------------------------
if ($read_answer!='')
{

  if (strlen($read_answer)==1)
  {
    $read_answer="000".$read_answer;
  } 
  if (strlen($read_answer)==2)
  {
    $read_answer="00".$read_answer;
  } 
  if (strlen($read_answer)==3)
  {
    $read_answer="0".$read_answer;
  } 
  if (strlen($read_answer)==4)
  {
    $read_answer=$read_answer;
  } 
}
  else
{

  $read_answer="0000";
} 


//-----------保存试题答案-------------------------------------------------

if ($read_answer!='' || $read_answer!="")
{


  $read_stu_idid=$_SESSION["studentid"];
  $read_juan_id=$_SESSION["juan_id"];

  $sql="select  *  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_dsele"];
    $tempstr="";

    for ($yy=1; $yy<=strlen($read_database); $yy=$yy+1)
    {
      $find_position=($getcur_pageint-1)*5+1;
      if ($yy==$find_position+1)
      {
        $tempstr=$tempstr.substr($read_answer,0,1);
      }
      
	  else
      if ($yy==$find_position+2)
      {
        $tempstr=$tempstr.substr($read_answer,1,1);
      }
       else
      if ($yy==$find_position+3)
      {
        $tempstr=$tempstr.substr($read_answer,2,1);
      }
        else
      if ($yy==$find_position+4)
      {
        $tempstr=$tempstr.substr($read_answer,3,1);
      }
        else
      {
        $tempstr=$tempstr.substr($read_database,$yy-1,1);
      } 
    }


    $newanswer=$tempstr;
    $rs->close;
  
    //------------------------------------------------------
    $sql="update  studentanswer  set test_dsele='".$newanswer."'";
    $sql=$sql."  where   stuid='".$read_stu_idid."'";
    $sql=$sql."   and   juan_id=".$read_juan_id;

    $rs=$conn->execute($sql);
    $rs->close;
    $conn->close;
	//echo $newanswer;


  } 

} 

//查询试题答案-------------------------------------------------

$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);
  } 
} 


$cc="";

$cc=$db_answer;


if ($get_mode=='0')
{
if ((trim($db_answer)==trim($read_answer)))
{

  print "1".$cc;
}
  else
{

  print "0".$cc;
}
}
if ($get_mode=='1')
{
 print "3";
}

$rs->close;
$conn->close;

$objcode=null;

?>
