chapterPage.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <main>
  2. <?php
  3. if (!isset($_SESSION['chapterPanel']) && isset($_SESSION['subjectPanel'])) {
  4. header("location: ../logic/goBack.php");
  5. }
  6. $chapterID = $_SESSION['chapterPanel'];
  7. $subjectID = $_SESSION['subjectPanel'];
  8. $sql_query = "SELECT chapterID, subjectID, startDate, endDate, revisionAllowed, numQuestions FROM tests WHERE chapterID = $chapterID AND subjectID = '$subjectID'";
  9. $result = mysqli_query($db, $sql_query);
  10. $row = mysqli_fetch_assoc($result);
  11. if ($row) {
  12. $startDate = $row['startDate'];
  13. $endDate = $row['endDate'];
  14. date_default_timezone_set('Europe/Madrid');
  15. if (new DateTime() > new DateTime($row['endDate'])) {
  16. echo "<center>Exam time ended <b>(from $startDate to $endDate)</b>, now you can see the results";
  17. showResults($db);
  18. echo '<a href="/teacher/logic/resetExam.php">Reset this exam</a>';
  19. echo "</center>";
  20. } else if (new DateTime() > new DateTime($row['startDate'])) {
  21. echo "<center>Exam is taking place right now <b>(from $startDate to $endDate)</b>, you will see the results after finishing";
  22. echo "</center>";
  23. } else {
  24. echo '<center>';
  25. echo "Exam was set between $startDate and $endDate with revision ";
  26. if ($row['revisionAllowed'] == 1) {
  27. echo "<b>allowed</b> ";
  28. } else {
  29. echo "<b>not allowed</b> ";
  30. }
  31. $num = $row['numQuestions'];
  32. echo "with $num questions";
  33. showError();
  34. echo "</center>";
  35. showExamForm();
  36. }
  37. } else {
  38. echo '<center><h1>Exam date was not set</h1>';
  39. showError();
  40. echo "</center>";
  41. showExamForm();
  42. }
  43. unset($_SESSION['error']);
  44. function showResults($db)
  45. {
  46. $chapter = $_SESSION['chapterPanel'];
  47. $subject = $_SESSION['subjectPanel'];
  48. $query_result = "SELECT * FROM (SELECT * FROM results WHERE chapterID = '$chapter') AS results RIGHT JOIN students_subjects ON results.studentUser = students_subjects.studentID WHERE students_subjects.subjectID = (SELECT subjects.subjectID from subjects where subjects.subjectName='$subject')";
  49. $result_first = mysqli_query($db, $query_result);
  50. $result_second = mysqli_query($db, $query_result);
  51. echo '<table border="1px" id="users">
  52. <thead>
  53. <tr>
  54. <th>Student</th>
  55. <th>Grade</th>
  56. </tr>
  57. </thead>
  58. <tbody>';
  59. while ($row = mysqli_fetch_assoc($result_first)) {
  60. if ($chapter == $row['chapterID'] || !isset($row['chapterID'])) {
  61. if ($row['score'] == 0) {
  62. $grade = 0.0;
  63. } else {
  64. $grade = round($row['score'] / $row['maxPoints'] * 10, 1);
  65. }
  66. echo '<tr>
  67. <td>' . $row['studentID'] . '</td>
  68. <td>' . $grade . '</td>
  69. </tr>';
  70. }
  71. }
  72. echo '</tbody>
  73. </table>';
  74. echo '<table border="1px" id="users">
  75. <thead>
  76. <tr>
  77. <th>Numero de suspensos</th>
  78. <th>Numero de aprobados</th>
  79. <th>Numero de notables</th>
  80. <th>Numero de sobresalientes</th>
  81. <th>Nota media de la clase</th>
  82. </tr>
  83. </thead>
  84. <tbody>';
  85. $suspensos = 0;
  86. $aprobados = 0;
  87. $notables = 0;
  88. $sobresalientes = 0;
  89. $students = 0;
  90. $sumGrade = 0;
  91. while ($row = mysqli_fetch_assoc($result_second)) {
  92. if (isset($row['score'])) {
  93. $grade = round($row['score'] / $row['maxPoints'] * 10, 1);
  94. if ($grade < 5) {
  95. $suspensos = $suspensos + 1;
  96. } else if ($grade < 7) {
  97. $aprobados = $aprobados + 1;
  98. } else if ($grade < 9) {
  99. $notables = $notables + 1;
  100. } else {
  101. $sobresalientes = $sobresalientes + 1;
  102. }
  103. $students = $students + 1;
  104. $sumGrade = $sumGrade + $grade;
  105. } else {
  106. $suspensos = $suspensos + 1;
  107. $students = $students + 1;
  108. }
  109. }
  110. if ($sumGrade == 0) {
  111. $notaMedia = 0;
  112. } else {
  113. $notaMedia = round($sumGrade / $students, 1);
  114. }
  115. echo '<tr>
  116. <td>' . $suspensos . '</td>
  117. <td>' . $aprobados . '</td>
  118. <td>' . $notables . '</td>
  119. <td>' . $sobresalientes . '</td>
  120. <td>' . $notaMedia . '</td>
  121. </tr>';
  122. echo '</tbody>
  123. </table>';
  124. }
  125. function showExamForm()
  126. {
  127. echo '<div class="form">
  128. <form action="logic/examLogic.php" method="POST">
  129. <label for="startDate">Start time</label><br>
  130. <input type="date" id="startDate" name="startDate" required>
  131. <input type="time" id="startTime" name="startTime" required><br><br>
  132. <label for="endDate">End time</label><br>
  133. <input type="date" id="endDate" name="endDate" required>
  134. <input type="time" id="endTime" name="endTime" required><br><br>
  135. <label for="revision">Revision allowed</label><br>
  136. <input type="checkbox" id="revision" name="revision"><br><br>
  137. <label for="questionNumber">Amount of questions (0-100)</label><br>
  138. <input type="number" id="questionNumber" name="questionNumber" step="1" min="0" max="100" required>
  139. <input type="submit" value="Set exams">
  140. </form>
  141. </div>';
  142. }
  143. function showError()
  144. {
  145. if (isset($_SESSION['error'])) {
  146. if ($_SESSION['error'] == 1) {
  147. echo '<p style="color:red"> You can not set exam end date before starting date</p>';
  148. } else {
  149. echo '<p style="color:red"> You can not set exam start date in the past</p>';
  150. }
  151. }
  152. }
  153. ?>
  154. </main>