]> git.treefish.org Git - banana.git/blobdiff - include/exams.inc
forgot some files.
[banana.git] / include / exams.inc
diff --git a/include/exams.inc b/include/exams.inc
new file mode 100644 (file)
index 0000000..1e3f9a0
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+  require 'db.inc';
+
+  if ( ! isset($EXAMS) ) {
+    $result=$db->query("SELECT id,score FROM exams ORDER BY id");
+    $EXAMS_next = -1;
+    $EXAMS_actual = -1;
+    $EXAMS_n = 0;
+  
+    while ($exam = $result->fetch(PDO::FETCH_ASSOC)) {
+       $totpoints = 0;
+       foreach (explode(',',$exam['score']) as $points) {
+         $totpoints = $totpoints + $points;
+       }
+       $EXAMS[$exam['id']] = array("id" => $exam['id'], 
+         "timestr" => date("d.m.Y H:i", $exam['id']),
+         "scorestr" => $exam['score'],
+        "totscore" => $totpoints,
+        "nresults" => $db->query("SELECT COUNT(*) FROM examscore WHERE exam=" . $exam['id'])->fetch(PDO::FETCH_NUM)[0],
+        "nquests" => count(explode(',',$exam['score'])));
+       if ( strtotime("now") < $exam['id'] && ( $EXAMS_next==-1 || $EXAMS_next > $exam['id'] )  ) {
+         $EXAMS_next = $exam['id'];
+       }
+       if ( strtotime("now") < $exam['id'] + 3600  && ( $EXAMS_actual==-1 || $EXAMS_actual > $exam['id'] )  ) {
+         $EXAMS_actual = $exam['id'];
+       }
+       $EXAMS_n++;
+     }
+     if($EXAMS_next == -1) unset($EXAMS_next);
+     if($EXAMS_actual == -1) unset($EXAMS_actual);
+
+    $EXAMS_totscore = 0;
+    $EXAMS_totscore_nextinc = 0;
+    if(isset($EXAMS)) {
+      foreach ($EXAMS as $exam) {
+        if( (! isset($EXAMS_next)) || $exam['id'] < $EXAMS_next ) { $EXAMS_totscore += $exam['totscore']; }
+       if( (! isset($EXAMS_actual)) || $exam['id'] != $EXAMS_actual ) { $EXAMS_last = $exam['id']; }
+       if( (! isset($EXAMS_next)) || $exam['id'] <= $EXAMS_next ) { $EXAMS_totscore_nextinc += $exam['totscore']; }
+      }
+    }
+
+  }
+?>