actualExam.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. $root = $_SERVER['DOCUMENT_ROOT'];
  3. include($root . "/util/session.php");//checks that the user is logged in
  4. include($root . "/util/privilege_check.php");
  5. checkPrivilege("student");
  6. #print_r($_POST);
  7. if (isset($_POST['actualChapter'])) {
  8. #echo $_POST['actualSubject'];
  9. $actualSubject = $_POST['actualSubject'];
  10. $actualChapter = $_POST['actualChapter'];
  11. $query = "SELECT * FROM questions WHERE subjectID = '$actualSubject' AND chapterID = '$actualChapter'";
  12. $result = mysqli_query($db,$query);
  13. if (mysqli_num_rows($result) > 0) {
  14. $start = 0;
  15. while($row = mysqli_fetch_assoc($result)){
  16. $startingQuestionsVector[$start] = $row["questionID"];
  17. $start++;
  18. }
  19. }else{
  20. echo 'Unexistant questions for this chapter';
  21. }
  22. #print_r($startingQuestionsVector);
  23. echo "<br>";
  24. shuffle($startingQuestionsVector);
  25. for($i = 0; $i < $_POST['questionNumber']; $i++){
  26. $selectedQuestions[$i] = $startingQuestionsVector[$i];
  27. }
  28. #print_r($selectedQuestions);
  29. }else{
  30. echo 'No exam exists for this chapter. How did you get here?';
  31. }
  32. #$row=mysqli_fetch_assoc($result);
  33. #echo $row['subjectID'];
  34. ?>
  35. <html>
  36. <head>
  37. <title>Exam</title>
  38. <link rel="stylesheet" type="text/css" href="studentStyle.css">
  39. </head>
  40. <body>
  41. <?php
  42. include($root . "/student/header.php")
  43. ?>
  44. <h1><?php echo $_POST['actualSubject'] . ': Exam Chapter ' . $_POST['actualChapter']; echo "<br>";?></h1>
  45. <?php
  46. echo '<form action="/student/sendExam.php" method=POST>';
  47. for($i = 0; $i < $_POST['questionNumber']; $i++){
  48. $questionIndex = $i+1;
  49. ?>
  50. <b><?php echo 'Question ' . $questionIndex;?></b>
  51. <?php
  52. $query = "SELECT * FROM questions WHERE questionID = '$selectedQuestions[$i]'";
  53. $result = mysqli_query($db,$query);
  54. $row = mysqli_fetch_assoc($result);
  55. echo '<br>' . $row['questionDescription'] . '<br>';
  56. if($row['questionType'] == "ABCD"){
  57. echo
  58. '<input type="radio" id="A" " name="studentAnswer'.$questionIndex.'" value="A" checked ="checked">' .
  59. '<label for="A">'. $row["descriptionAnswerA"] . '</label><br>' .
  60. '<input type="radio" id="B" " name="studentAnswer'.$questionIndex.'" value="B">' .
  61. '<label for="B">'. $row["descriptionAnswerB"] . '</label><br>' .
  62. '<input type="radio" id="C" " name="studentAnswer'.$questionIndex.'" value="C">' .
  63. '<label for="C">'. $row["descriptionAnswerC"] . '</label><br>' .
  64. '<input type="radio" id="D" " name="studentAnswer'.$questionIndex.'" value="D">' .
  65. '<label for="D">'. $row["descriptionAnswerD"] . '</label><br>';
  66. }else{
  67. echo
  68. '<input type="radio" id="T" name="studentAnswer'.$questionIndex.'" value="T" checked = "checked">' .
  69. '<label for="T">True</label><br>' .
  70. '<input type="radio" id="F" name="studentAnswer'.$questionIndex.'" value="F">' .
  71. '<label for="F">False</label><br>';
  72. }
  73. }
  74. echo '<input type="hidden" value="' . $_POST['actualSubject'] . '" name="actualSubject">' .
  75. '<input type="hidden" value="' . $_POST['actualChapter'] . '" name="actualChapter">' .
  76. '<input type="hidden" value="' . $_POST['questionNumber'] . '" name="questionNumber">' .
  77. '<input type="hidden" value="' . base64_encode(serialize($selectedQuestions)) . '" name="selectedQuestions">' .
  78. '<input type="submit" value="Submit"><br><br><br></form>';
  79. ?>
  80. <?php
  81. include($root . "/student/footer.php")
  82. ?>
  83. </body>
  84. </html>