<?php include("conn.php") ?>
<?php include("session.php");?>
<?php 
	  //---------只对正式考试有效------------------------
	  $read_studentid=trim($_GET["studentid"]);
	  $read_password=trim($_GET["password"]);
	  
?>
	 
	 <?php
		
		$read_juan_id=$_GET["juan_id"];
				 
        $sql="select  *  from  database_name  where   id=";
		$sql=$sql." (select  database_id  from  fenlei   where   id=".$read_juan_id.")";
		$rs=$conn->execute($sql);
		if(!$rs->EOF)
		{
		   $read_database_name=$rs->fields["database_name"];
		}
		$rs->close;
		
		$sql="select  *  from  fenlei  where   id=".$read_juan_id;
		$rs=$conn->execute('set names utf8');
		$rs=$conn->execute($sql);
		if(!$rs->EOF)
		{
		    $read_juan_name=trim($rs->fields["exam_juan_name"]);
		}
		
		$rs->close;
	?>
    
    
	 
	  <?php  
	               //'---------------------------------------------------
	               //'---------examinfo 'exam_mode=true 学习训练模式  exam_mode=false 正式考试模式---------------  
	                       $flag_value="999";
	                       $sql="select *  from  examinfo  where  flag='".$flag_value."'";
	                       $rs=$conn->execute($sql);
	                       if(!$rs->EOF)
		                   {
	                               $read_mode=$rs->fields["exam_mode"];
						   }	
						   $rs->close;
				         
					//'----------------------------------------------------------------------
	  
	   ?>
       
       
       <?   
	   
	 
	
	   //'--------------特别重要，多科目试卷只是在正式模式下有效-------------------
	   if ($read_mode==1)
	   {
	       //'---------如果是多科目试题，从此截断，直接赋值-------------------------
		   $duokemu_flag=0;
		
		   $sql="select  * from  random_shiti where  juan_id=0  ";
	       $rs=$conn->execute($sql);
		   if (!$rs->EOF)
		   {  
			  $duokemu_flag=1;
			  $read_database_name=$rs->fields["coursename"];
			  $read_juan_name=$read_database_name;
		      //'-----------特别重要，juan_id=0 ，直接读取studentanswer 中的试题-------------
			  $juan_id=0;
		   }
	   
		  $rs->close; 
		
		
		
		
	   }
		
	  
   ?>
    
  
      
       
       
       
	  <?php 
	 
	    $return_msg="z"."enter";
	    $flag=0;
		
	  ?>
     
      <?php  
	
      $sql="select * from studentinfo where studentid='".$read_studentid."'";
  	  $rs=$conn->execute($sql);
	  if($rs->EOF)
	  {    
	        $return_msg="a"."【软件提示】：准考证号【".$read_studentid."】没有注册，请询问考场教师.";
		    $flag=1;
	        $rs->close;
	  
			$cc=$return_msg;
	        echo ltrim($cc);
	        $rs->close;
	        $conn->close;
	        exit;
	  
	 }
	 
	 ?>
	 
      <?php 
	  
	  
	  if ($flag==0)
      {	
      
	  
	   $sql="select * from studentinfo where studentid='".$read_studentid."'";
  	   $rs=$conn->execute($sql);
	   if(!$rs->EOF)
	   {
	      $read_stu_name=$rs->fields["name"];
  		  $read_stu_class=$rs->fields["testclassname"];
		  $read_db_password=trim($rs->fields["password"]);
		  
	      if ($read_db_password!=$read_password) 
	      {
			   $return_msg="b"."【软件提示】：密码输入错误，请仔细检查.";
		       $flag=1;
	           $rs->close;
	           
			   $cc=$return_msg;
	           echo ltrim($cc);
	           $conn->close;
	           exit;
	      }
	  }
	  
	  }
	 
	 
	  ?>
	 
		  
       
      
       
       <?
	   
       
	    if  ($flag==0)
		{
				 $myflag=0;
		         $sql="select * from  studentanswer  where  stuid='".$read_studentid."'";
		         $rs=$conn->execute($sql);
		         if(!$rs->EOF)
		         {
					 $read_login_status=$rs->fields["login"];
					 $read_login_num=$rs->fields["login_num"];
					 $read_submit_status=$rs->fields["submit"];
					 
					 if  (($read_login_num<1)  and  ($read_login_status==1) and ($read_submit_status==0))  
			         {
					   $return_msg="d"."【软件提示】：准考证号:【 ".$read_studentid."】 正在使用中，询问考场教师才能二次登录。";
				       $flag=1;
					   $rs->close;
	                   
					   $cc=$return_msg;
	                   echo ltrim($cc);
	                   $conn->close;
	                   exit;
					 
				     }
		      
			     }
		         $rs->close;
			}
		 
		
	   ?>
       
       
       
	   <?php 
	     
	     if  ($flag==0)
		 {
			 $myflag=0;
		     $sql="select * from  classtable  where  classname='".$read_stu_class."'";
		     $sql=$sql."   and    course_sele_class=1 ";
		     $rs=$conn->execute($sql);
		     if($rs->EOF)
		     {
				  
			 $return_msg="e"."【软件提示】：准考证号 [ ".$read_studentid." ] 所在的场次：[ ".$read_stu_class." ]不在考场教师启动的场次范围内.请考场教师确认是否该场次参加考试.";
		      $flag=1;
			  $rs->close;
	          $cc=$return_msg;
	          echo ltrim($cc);
	          $conn->close;
	          exit;
			  
			 }
			 
		     $rs->close;
		 }
		 
	 ?>
     
     
     
     
	
	 
      
      
      
      
	  <?php 
	   
	     
		 //'---------------------相同的准考证号，登录已经交卷的试题----------------------------------
		 
	     if  ($flag==0)  
		 {
				 
		    $sql="select * from  studentanswer where  stuid='".$read_studentid."'";
		    $rs=$conn->execute($sql);
			if(!$rs->EOF)
		    {
		     
			   $read_login_status=$rs->fields["login"];
			   $read_submit_status=$rs->fields["submit"];
			   if  (($read_login_status==1)  and  ($read_submit_status==1))
			   {       
			       
				   $str1="g"."【软件提示】使用准考证号：[".$read_studentid."]"." 登录的试题[ ";
				   $str2=" ]已经交卷，不能再次登录! ";
				   
				   //$str1=iconv("gb2312","utf-8",$str1);
				   //$str2=iconv("gb2312","utf-8",$str2);
				   $return_msg=$str1.$read_juan_name.$str2;
				   $flag=1;
				   $rs->close;
	               $cc=$return_msg;
	               echo ltrim($cc);
	               $conn->close;
	               exit;
				   
			  }
		      
			}
		   $rs->close; 
		 
		 }
		 
		 
		
	   ?>
       
       
	 
     
      <?php 
	 
	  $cc="";
	  //'------------------将中文--编码----成%20%35--------------
	 
	  //$cc=urlencode(trim($return_msg));
	  $cc=$return_msg; 
	 	  
	  echo ltrim($cc);
	  
	  $rs->close;
	  $conn->close;
		
  ?>
  
  
  
  </body>
  </html>
	