]> git.treefish.org Git - banana.git/blobdiff - admin/examoverview.php
forgot some files.
[banana.git] / admin / examoverview.php
diff --git a/admin/examoverview.php b/admin/examoverview.php
new file mode 100644 (file)
index 0000000..b82ff5c
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+  require 'include/head.inc';
+  require 'include/db.inc';
+  require 'include/exams.inc';
+  require 'include/common.inc';
+
+  if ( isset($EXAMS_actual) ) {
+    $showexam = $EXAMS_actual;
+  }
+  else if ( isset($EXAMS_last) ) {
+    block("red", "no next exam");
+    $showexam = $EXAMS_last;
+  }
+  else {
+    block("red", "no exams defined");
+    exit;
+  }
+
+  if( isset($_GET['examselected']) ) { $showexam = trim($_GET['examselected']); }
+
+  if( isset($_GET['examid']) && isset($_GET['mnumber']) && isset($_GET['tstamp']) && isset($_GET['scorestr']) ) {
+     $up_examid = trim($_GET['examid']);
+     $up_mnumber = trim($_GET['mnumber']);
+     $up_tstamp = trim($_GET['tstamp']);
+     $up_scorestr = trim($_GET['scorestr']);
+
+     if( $db->query("SELECT COUNT(*) FROM examscore WHERE mnumber=$up_mnumber AND exam=$up_examid AND tstamp=$up_tstamp")->fetch(PDO::FETCH_NUM)[0] == 0 ) {
+       $db->query("DELETE FROM examscore WHERE mnumber=$up_mnumber AND exam=$up_examid");
+       $db->query("INSERT INTO examscore (exam,mnumber,scorestr,tstamp) values ($up_examid,$up_mnumber,\"$up_scorestr\",$up_tstamp)");
+       block("lightgreen", "modified submit");
+     }
+  }
+
+  print "<form action='examoverview.php'>";
+  print "<select name='examselected' onchange='this.form.submit()'>";
+  foreach($EXAMS as $exam) {
+    $note = "";
+    if( isset($EXAMS_actual) && $exam['id'] == $EXAMS_actual ) { $note = "(next)"; }
+    if( isset($EXAMS_last) && $exam['id'] == $EXAMS_last ) { $note = "(last)"; }
+    if( $showexam != $exam['id'] ) {
+      print "<option value=" . $exam['id'] . ">" . $exam['timestr'] . " " . $note . "</option>";
+    }
+    else {
+      print "<option value=" . $exam['id'] . " selected='selected'>" . $exam['timestr'] . " " . $note . "</option>";
+    }
+  } 
+  print "</select>";
+  print "</form>";
+
+  block("black", "summary for exam " . $EXAMS[$showexam]['timestr'] . " (" . $EXAMS[$showexam]['scorestr'] . ")");
+
+  $result = $db->query("SELECT firstname, lastname, mnumber FROM students ORDER BY LOWER(lastname)");
+
+  print "<table>";
+  print "<td><b>First name&nbsp;</b></td><td><b>Last name&nbsp;</b></td><td><b>Matr.nummer&nbsp;</b></td><td><b>Total Score&nbsp;</b></td>";
+
+  # if( isset($EXAMS_actual) && $showexam == $EXAMS_actual ) {
+  #   print "<td><b>Blackboard&nbsp;</b></td>";
+  # }
+  # else {
+  #   print "<td><b>Modify&nbsp;</b></td>";
+  # }
+
+  while ($student = $result->fetch(PDO::FETCH_ASSOC)) {
+    $result2 = $db->query("SELECT scorestr FROM examscore WHERE mnumber=" . $student['mnumber'] . " AND exam=" . $showexam)->fetch(PDO::FETCH_NUM);
+
+    $exdone = $result2[0];
+    if ($exdone == "") { $exdone=0; }
+
+    $scorestr = $result2[0];
+
+    $totscore = 0;
+    foreach (explode(',',$scorestr) as $points) {
+      $totscore = $totscore + $points;
+    }
+
+    print "<tr>";
+    print "<td>" . $student['firstname'] . "</td>";
+    print "<td>" . $student['lastname'] . "</td>";
+    print "<td>" . $student['mnumber'] . "</td>";
+    print "<td>" . $totscore . "/" . $EXAMS[$showexam]['totscore'] . "</td>";
+
+    print "<td><form style='margin: 0; padding: 0' action='examoverview.php'>";
+    if( isset($_GET['examselected']) ) { print "<input type='hidden' name='examselected' value='" . $_GET['examselected'] . "' />"; } 
+    print "<input type='hidden' name='examid' value='" . $showexam . "' />";
+    print "<input type='hidden' name='mnumber' value='" . $student['mnumber'] . "' />";
+    print "<input type='hidden' name='tstamp' value='" . time() . "' />";
+    print "<input size='10' name='scorestr' type='text' value='" . $scorestr . "'>";
+    print "</form></td>";
+
+    print "</tr>";
+  }
+  print "</table>";
+?>