subjectExams.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (isset($_POST['actualSubject']) or isset($_SESSION['actualSubject'])) {
  7. if(isset($_SESSION['actualSubject']) == false){
  8. $_SESSION['actualSubject'] = $_POST['actualSubject'];
  9. }
  10. $actualSubject = $_SESSION['actualSubject'];
  11. $query = "SELECT * FROM tests WHERE subjectID = '$actualSubject'";
  12. $result = mysqli_query($db,$query);
  13. #echo $_POST['actualSubject'];
  14. #$row = mysqli_fetch_assoc($result);
  15. }else{
  16. echo 'No subject exist. How did you get here?';
  17. }
  18. #$row=mysqli_fetch_assoc($result);
  19. #echo $row['subjectID'];
  20. ?>
  21. <html>
  22. <head>
  23. <title>Possible exams: <?php echo $_SESSION['actualSubject']?></title>
  24. <link rel="stylesheet" type="text/css" href="studentStyle.css">
  25. </head>
  26. <body>
  27. <?php
  28. include($root . "/student/header.php")
  29. ?>
  30. <li><a href="/student/checkExams.php">Back</a></li>
  31. <div id="menu">
  32. <ul>
  33. <b>Available chapters</b>
  34. <?php
  35. date_default_timezone_set('Europe/Madrid');
  36. $today = date("Y-m-d H:i:s");
  37. $username = $_SESSION['login_user'];
  38. $query2 = "SELECT chapterID FROM results WHERE subjectID = '$actualSubject' and studentUser = '$username'";
  39. $result2 = mysqli_query($db,$query2);
  40. $chaptersDone = array(); # dodging repeating that tedious exam again
  41. while($res = mysqli_fetch_assoc($result2)){
  42. $chaptersDone[] = $res['chapterID'];
  43. }
  44. #echo $today;
  45. while($row = mysqli_fetch_assoc($result)){
  46. $startDate = $row["startDate"];
  47. $endDate = $row["endDate"];
  48. if($today >= $startDate and $today < $endDate and (!in_array($row["chapterID"], $chaptersDone))){ #control if the exam is available or not
  49. echo 'for ' . $row["subjectID"];
  50. echo '<form action="/student/actualExam.php" method="POST">' .
  51. '<input type="hidden" value="' . $row["subjectID"] . '" name="actualSubject">' .
  52. '<input type="hidden" value="' . $row["numQuestions"] . '" name="questionNumber">' .
  53. '<input type="submit" value="' . $row["chapterID"] . '" name="actualChapter"></form>';
  54. }
  55. }
  56. ?>
  57. </ul>
  58. </div>
  59. <?php
  60. include($root . "/student/footer.php")
  61. ?>
  62. </body>
  63. </html>