--- /dev/null
+<?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 </b></td><td><b>Last name </b></td><td><b>Matr.nummer </b></td><td><b>Total Score </b></td>";
+
+ # if( isset($EXAMS_actual) && $showexam == $EXAMS_actual ) {
+ # print "<td><b>Blackboard </b></td>";
+ # }
+ # else {
+ # print "<td><b>Modify </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>";
+?>
--- /dev/null
+<?php
+ require 'include/head.inc';
+ require 'include/db.inc';
+ require 'include/common.inc';
+
+ if(isset($_POST['submit']) && $_POST['stime']!="" && $_POST['score']!="") {
+ $db->query("INSERT INTO exams (id,score) VALUES (" . strtotime(trim($_POST['stime'])) . ",'" . $_POST['score'] . "')");
+ block("lightgreen", "added exam");
+ }
+
+ if(isset($_GET['delete'])) {
+ $db->query("DELETE FROM exams WHERE id=" . $_GET['delete']);
+ block("red", "deleted exam");
+ }
+
+ require 'include/exams.inc';
+
+ block("black", "add exam");
+?>
+
+<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
+ <table>
+ <tr>
+ <th align="left">Time:</th> <th><input type="text" name="stime"></th><th></th><th>(e.g. 10.9.2012 10:30)</th>
+ </tr>
+ <tr>
+ <th align="left">Score:</th> <th><input type="text" name="score"></th>
+ <th><input type="submit" name="submit" value="Add"></th><th>(e.g. 4,5,5)</th>
+ </tr>
+ </table>
+</form>
+
+<?php
+ if ( $EXAMS_n == 0 ) {
+ block("red", "no exams defined");
+ exit;
+ }
+
+ block("black", "exam overview");
+
+ print "<table>";
+ foreach ($EXAMS as $exam) {
+ print "<tr>";
+ print "<td>" . $exam['id'] . " </td>";
+ print "<td>" . $exam['timestr'] . " </td>";
+ print "<td>" . $exam['scorestr'] . "(" . $exam['nquests'] . ")" . " </td>";
+ print "<td>" . $exam['totscore'] . " </td>";
+ if ($exam['nresults'] == 0) {
+ print "<td><a href='exams.php?delete=" . $exam['id'] . "'>delete</a></td>";
+ }
+ else { print "<td>locked</td>"; }
+ print "</tr>";
+ }
+ print "</table>";
+
+?>
\ No newline at end of file
--- /dev/null
+<?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']; }
+ }
+ }
+
+ }
+?>