[PHP] 在线考试系统 →→→→→进入此内容的聊天室

来自 , 2020-04-08, 写在 PHP, 查看 96 次.
URL http://www.code666.cn/view/14e422f0
  1. <?php
  2. set_include_path('.' . PATH_SEPARATOR . './admin'. PATH_SEPARATOR . get_include_path());
  3.  
  4. include("global.php");
  5.  
  6. $threadid  = intval($_REQUEST[threadid]);
  7.  
  8.  
  9. if($_POST["action"]=="dotest"){
  10.    $_POST[radio]     = $_POST[radio]    ? $_POST[radio]    : array();
  11.    $_POST[checkbox]  = $_POST[checkbox] ? $_POST[checkbox] : array();
  12.    
  13.    //取得单选和多选分值
  14.    $getsetmark = $db->query_first("SELECT radio,checkbox FROM ".$db_prefix."setmark");
  15.    
  16.    //缓存所有正确答案
  17.    $answers = $db->query("SELECT id,title,choicetype,answer FROM ".$db_prefix."title WHERE 1");
  18.    $answer_array = array();
  19.    $titles       = array();
  20.    $error        = array();
  21.    $tmark = 0;
  22.    while($row = $db->fetch_array($answers)){
  23.          $answer_array[$row[id]] = $row[answer];
  24.          $titles[$row[id]]       = $row[title];
  25.          if($row[choicetype]=="radio"){
  26.             $tmark += $getsetmark[radio];
  27.          }elseif($row[choicetype]=="checkbox"){
  28.             $tmark += $getsetmark[checkbox];
  29.          }
  30.    }
  31.    $mark = 0;
  32.    foreach($_POST[radio] as $titleid=>$choice){
  33.                
  34.            if($choice == $answer_array[$titleid]){
  35.               $mark += $getsetmark[radio];
  36.            }else{
  37.               $error[] = array($titleid,$choice,$answer_array[$titleid]);
  38.            }
  39.            
  40.    
  41.    }
  42.    
  43.  
  44.    foreach($_POST[checkbox] as $titleid=>$choice){
  45.    
  46.           $c_answers = explode(",",$answer_array[$titleid]);
  47.           $flag = false;
  48.            
  49.           foreach($c_answers as $answer){
  50.                   if(!in_array($answer,$choice)){
  51.                      $flag = true;
  52.                   }
  53.           }
  54.           foreach($choice as $answer){
  55.                   if(!in_array($answer,$c_answers)){
  56.                      $flag = true;
  57.                   }
  58.           }
  59.            
  60.           if($flag){
  61.              $error[] = array($titleid,implode(",",$choice),$answer_array[$titleid]);
  62.              continue;
  63.           }
  64.           $mark += $getsetmark[checkbox];
  65.    
  66.    }
  67.    
  68.    
  69.    
  70.    
  71.    
  72.    $msg = "本次考试总分{$tmark}\\n你的得分{$mark}\\n";
  73.    if($error){
  74.       $msg .= "以下题目你回答错误:\\n";
  75.       foreach($error as $v){
  76.               $msg .= "{$titles[$v[0]]}\\n你的答案:{$v[1]}\\n正确答案:{$v[2]}\\n\\n";
  77.       }
  78.    }
  79.    echo "<script>alert('$msg');document.location.href='index.php'</script>";
  80.    exit;
  81. }
  82. if(!$threadid){
  83.    echo "参数错误";
  84.    echo '<meta http-equiv="refresh" content="2; url=index.php">';
  85.    exit;
  86.  
  87. }
  88. //考试名称
  89. $threads = $db->query_first("SELECT name FROM ".$db_prefix."thread WHERE id=$threadid");
  90. $threadtitle = $threads[name];
  91.  
  92.  
  93. //题目表单
  94. $conditions = $threadid ? "threadid='$threadid'" : 1;
  95.  
  96.  
  97. $titles = $db->query("SELECT * FROM ".$db_prefix."title WHERE $conditions ORDER BY id ASC");
  98. $titlelist = false;
  99. $int = 0;
  100. while($title = $db->fetch_array($titles)){
  101.       $int++;
  102.       $choices = false;
  103.       $tests = $db->query("SELECT * FROM ".$db_prefix."choice WHERE extends=$title[id] ORDER BY id ASC");
  104.       $i=0;
  105.       while($test=$db->fetch_array($tests)) {
  106.             $i++;
  107.             $checked = $test["IsDefault"] ? "checked" : false;  
  108.                
  109.             if($title[choicetype]=="radio"){
  110.                $choices .=  "<input name=\"radio[$title[id]]\" type=\"radio\" value=\"$test[choice]\" $checked check=\"^0$\" warning=\"$title[title]\"> $test[choice]";  //
  111.             }else{
  112.                $choices .=  "<input name=\"checkbox[$title[id]][]\" type=\"checkbox\" value=\"$test[choice]\" $checked check=\"^0{1,}$\" warning=\"$title[title]\"> $test[choice]";//
  113.             }
  114.       }
  115.       eval("\$titlelist .= \"".gettemplate("test_title_list")."\";");  
  116. }
  117.  
  118. eval("\$header = \"".gettemplate("test_header")."\";");
  119. eval("\$footer = \"".gettemplate("test_footer")."\";");
  120.  
  121. eval("dooutput(\"".gettemplate("test_test")."\");");
  122.  
  123. ?>
  124.  

回复 "在线考试系统"

这儿你可以回复上面这条便签

captcha