<!DOCTYPE html>
<?php session_start(); ?>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="msapplication-tap-highlight" content="no" />
  <!--Let browser know website is optimized for mobile-->
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>礼敬中华 知识答题</title>
  <meta name="description" content="北京邮电大学学生会网络部网页答题" />
  <meta name="author" content="flyto.cc/lenny" />
  <!-- Favicons-->
  <link rel="icon" href="p/bupt_logo.png" />
  <!-- Import Google Icon Font -->
  <link href="css/icon.css" rel="stylesheet" />
  <!-- CSS-->
  <!-- Compiled and minified CSS -->
  <link rel="stylesheet" href="css/materialize.css" />
  <!-- Import Jq CSS -->
  <script src="js/jquery-2.1.4.min.js"></script>
  <!-- IMPORT EXTRA JS/CSS -->
  <!-- ####################################################### -->
  <script src="js/form.js"></script>
  <link rel="stylesheet" href="css/biankuang.css" />
  <link rel="stylesheet" type="text/css" href="css/header.css">
  <style type="text/css">
      label {
        width:100%
      }
  </style>
  <!-- ####################################################### -->
  <!-- END IMPORT EXTRA JS/CSS -->
</head>

<body>
  <div style="box-sizing:content-box;font-family:Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Noto Sans CJK SC,WenQuanYi Micro Hei,Arial,sans-serif;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default;" onclick="$('body,html').animate({scrollTop:0},500);">
    <header class="Sticky AppHeader is-fixed" style="width:100%;top:0px;left:0px;">
      <div class="AppHeader-inner" style="box-sizing:content-box;padding:0;width:100%;">
        <nav role="navigation" style="height:60px;line-height:60px;">
          <div class="nav-wrapper container">
            <a id="logo-container" href="#" class="brand-logo" style="font-size:1.6rem;">
              <img src="p/bupt_logo.png" alt="bupt" height="30px" style="vertical-align:middle;margin:0 10px 0 0;">礼敬中华 知识答题
            </a>
          </div>
        </nav>
      </div>
      <div class="PageHeader">
        <nav role="navigation" style="height:60px;">
          <div class="nav-wrapper container">
            <div style="text-align:center;display:inline-block;padding:5px 0;width:100%;float:left;">本次答题限时15分钟&nbsp;&nbsp;&nbsp;&nbsp;剩余时间&nbsp;&nbsp;<span name="remtime">15:00</span></div>
          </div>
        </nav>
      </div>
    </header>
    <div class="progress" style="margin:0;position:fixed;top:60px;height:3px;z-index:999">
      <div class="determinate" style="width:0%"></div>
    </div>
    <div class="Sticky--holder" style="position:relative;top:0px;right:0px;bottom:0px;left:0px;display:block;float:none;margin:0px;height:60.8px;visibility:hidden;font-size:15px;">
    </div>
  </div>
  <main>
    <div class="container">
      <div class="row">
        <form action="test.php" method="post" id="form1">
          <div class="section" id="information" style="width:100%;">
            <div class="input-field col s6">
              <input id="user_name" type="text" class="validate" name="user_name" onblur="checkInfo(this,0);" value="">
              <label for="user_name" id="user_name_label">姓名</label>
            </div>
            <div class="input-field col s6">
              <input id="student_id" type="tel" class="validate" name="student_id" onblur="checkInfo(this,1);" value="">
              <label for="student_id" id="student_id_label">学号</label>
            </div>
            <div class="input-field col s6">
              <input id="school" name="school" type="text" class="validate" onblur="checkInfo(this,2);" value="">
              <label for="school" id="school_label">学院</label>
            </div>
            <div class="input-field col s6">
              <!--<select id="userclass" name="userclass" onchange="checkSexInfo(this)">
                <option value="西土城" selected>西土城</option>
                <option value="沙河">沙河</option>
                <option value="宏福">宏福</option>
              </select>
              <label for="userclass" id="userclass_label">校区</label>
              -->
              <input id="userclass" name="userclass" type="text" class="validate" onblur="checkInfo(this,3);" value="">
              <label for="userclass" id="userclass_label">校区</label>

            </div>
            <div class="input-field col s12">
              <input id="telephone" name="telephone" type="tel" class="validate" onblur="checkInfo(this,4);" value="">
              <label for="telephone" id="telephone_label">手机</label>
            </div>
          </div>
          <div class="section" id="aboutTime" style="padding-top:0;width:100%;">
            <!-- 倒计时器 -->
            <div class="input-field col s12" style="height:1px;overflow:hidden">
              <input value="<?php $timestart = date(" H:i:s ");$_SESSION['timestart'] = $timestart;echo $timestart;?>" type="text" class="validate" style="color:#fff" name="timestart">
            </div>
            <div style="text-align:center;display:inline-block;padding:5px 0;width:100%;float:left;">本次答题限时15分钟&nbsp;&nbsp;&nbsp;&nbsp;剩余时间&nbsp;&nbsp;<span name="remtime">15:00</span></div>
          </div>
          <div style="margin:0 auto;text-align:center;">
            <div class="btn waves-effect waves-light" id="hiddenDisplay" onclick="requestFirst()">开始</div>
          </div>
          <?php
            //link to mysql
            $con=mysqli_connect("localhost","buptStudent","buptStudentlx","buptStudentdb");
            if (!$con){die('Could not connect:' . mysql_error());};
            //mysql_select_db("my_db_test", $con);
            $p = 20;
            $pp = 0;
            $ppp = $p + $pp;//the number of questions
            echo "<div id=\"ppp\" ppp=\"".$ppp."\"></div>\n<div class=\"section\" id=\"hiddenBefore\" style=\"display:none\"><h5>&nbsp;&nbsp;单选题</h5>\n";
            //创建随机数组
            $randomArray = array_rand(range(1,60),$p + 1);
            shuffle($randomArray);
            for($i = 1;$i <= $p;$i++){
              $random = $randomArray[$i];
              $result = mysqli_query($con,"SELECT * FROM Persons WHERE num='$random'");
              while($row = mysqli_fetch_array($result)){
              //html
                echo "<div class=\"spbq\" name=\"div_e\"><div class=\"biankuang biankuang_1\"></div><div class=\"biankuang biankuang_2\"></div><div class=\"biankuang biankuang_3\"></div><div class=\"biankuang biankuang_4\"></div><h6 id=\"question_".$i."\">". $i. ".". $row['q'] ."</h6>\n<p><input class=\"with-gap\" type=\"radio\" name=\"answer_". $i. "\" value=\"1\" id=\"test". $i. "1\" onclick=\"addOne(this)\"/>\n<label for=\"test". $i. "1\">". $row['A'] ."</label>\n<input class=\"with-gap\" type=\"radio\" name=\"answer_". $i. "\" value=\"2\" id=\"test". $i. "2\" onclick=\"addOne(this)\"/>\n<label for=\"test". $i. "2\">". $row['B'] ."</label>\n<input class=\"with-gap\" type=\"radio\" name=\"answer_". $i. "\" value=\"3\" id=\"test". $i. "3\" onclick=\"addOne(this)\"/>\n<label for=\"test". $i. "3\">". $row['C'] ."</label>\n<input class=\"with-gap\" type=\"radio\" name=\"answer_". $i. "\" value=\"4\" id=\"test". $i. "4\" onclick=\"addOne(this)\"/>\n<label for=\"test". $i. "4\">". $row['D'] ."</label>\n</p></div>\n";
                echo "<div class=\"input-field col s12\" style=\"height:1px;overflow:hidden\"><input value=\"".$random."\" type=\"text\" class=\"validate\" style=\"color:#fff\" name=\"question_".$i."\"></div>\n";
              }
            }

            // echo "<!-- </div><div class=\"section\"> --><h5>&nbsp;&nbsp;二、判断题</h5>";
            // $randomArray = range(1,10);
            // shuffle($randomArray);
            // for($i = 1;$i <= $pp;$i++){
            //   $random = $randomArray[$i] + 60;
            //   $result = mysqli_query($con,"SELECT q FROM Persons WHERE num='$random'");
            //   while($row = mysqli_fetch_array($result)){
            //     $j = $i + $p;
            //     //echo "<p>".$row."</p>";
            //     echo "<div class=\"spbq\" name=\"div_e\"><div class=\"biankuang biankuang_1\"></div><div class=\"biankuang biankuang_2\"></div><div class=\"biankuang biankuang_3\"></div><div class=\"biankuang biankuang_4\"></div><h6 id=\"question_".$j."\">". $j. ".". $row['q'] ."</h6>\n<p><input class=\"with-gap\" type=\"radio\" name=\"answer_". $j. "\" value=\"1\" id=\"test". $j. "1\" onclick=\"addOne(this)\"/>\n<label for=\"test". $j. "1\">正确</label>\n<input class=\"with-gap\" type=\"radio\" name=\"answer_". $j. "\" value=\"2\" id=\"test". $j. "2\" onclick=\"addOne(this)\"/>\n<label for=\"test". $j. "2\">错误</label>\n</p></div>\n";
            //     echo "<div class=\"input-field col s12\" style=\"height:1px;overflow:hidden\"><input value=\"".$random."\" type=\"text\" class=\"validate\" style=\"color:#fff\" name=\"question_".$j."\"></div>\n";
            //   }
            // }

            echo "</div>";
            //close linking
            mysqli_close($con);
            ?>
            <div style="margin:0 auto;text-align:center;">
              <button class="btn waves-effect waves-light" type="submit" name="action" id="submit" style="display:none">提交</button>
            </div>
        </form>
      </div>
    </div>
  </main>
  <footer class="page-footer" style="padding-top:0;margin-top:30px;display: none;" id="theFooter">
    <div class="footer-copyright" style="text-align:center;">
      <div class="container">&copy;2018 Bupt-Web.
        <a class="grey-text text-lighten-4" href="mailto:lenny.n@outlook.com">Mail Us</a>
      </div>
    </div>
  </footer>
  <!--  Scripts-->
  <script src="js/materialize.js"></script>
  <!-- Init JS -->
  <script src="js/init.js"></script>
  <!-- IMPORT EXTRA JS/CSS -->
  <!-- ####################################################### -->
  <script src="js/questionnaire.js"></script>
  <!-- ####################################################### -->
  <!-- END IMPORT EXTRA JS/CSS -->
</body>

</html>
