<?  session_start();?>
<?php include("conn.php") ?>
<? 
$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"];
//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=='' || $read_answer=="")
{
  $read_answer="000000";
}
  else
{

  $read_answer=$read_answer;
} 

//一定要在此转换---------------------
$read_answer=iconv("gb2312","utf-8",$read_answer);

//--------------------------读数据库已有的答案信息
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_lunshu"];
    $pos=0;
    $flag=0;
    $first_pos=1;
    $second_pos=1;
	//$read_database_len=(strlen($read_database)+mb_strlen($read_database,'UTF8'))/2;
	$read_database_len=strlen($read_database);
	
    for ($u=1; $u<=$read_database_len;$u=$u+1)
    {
      $get_user_tiankong=substr($read_database,$u-1,11);
      if ($get_user_tiankong=="[AABBCCDDEE")
      {
        $first_pos=$u;
        //-------------------------------------------------
        $f=$first_pos+1;
        while($f<$read_database_len)
        {
          $next_position=substr($read_database,$f-1,11);
          if ($next_position=="[AABBCCDDEE")
          {
            $second_pos=$f;
            $pos=$pos+1;
            $flag=1;
            break;
          } 
          $f=$f+1;
        } 
           //-------------------------------------------------
      } 
      if ($flag==1)
      {
        $myanswer[$pos]=substr($read_database,$first_pos+11-1,$second_pos-$first_pos-11);
		
        $flag=0;
      } 
	  
    }
   
    for ($k=1; $k<=$pos+1; $k=$k+1)
    {
      if ($k==$getcur_pageint)
      {
        $myanswer[$k]=$read_answer;
      } 
	  
    }

    //----------------------------------------------重新合并
    $newanswer="";
    for ($n=1;$n<=$allpageint;$n=$n+1)
    {
      $newanswer=$newanswer."[AABBCCDDEE".$myanswer[$n];
    }
	
	$newanswer=$newanswer."[AABBCCDDEEpppppp";
	
  }
  
  $rs->close;
  
  //echo $newanswer;
  
  //------------------------------------------------------
  $sql="update  studentanswer  set test_lunshu='".$newanswer."'";
  $sql=$sql."  where   stuid='".$read_stu_idid."'";
  $sql=$sql."   and   juan_id=".$read_juan_id;
  $rs=$conn->execute($sql);
  $conn->close;
  
} 

?>

