]> git.treefish.org Git - banana.git/blob - admin/examoverview.php
forgot some files.
[banana.git] / admin / examoverview.php
1 <?php
2   require 'include/head.inc';
3   require 'include/db.inc';
4   require 'include/exams.inc';
5   require 'include/common.inc';
6
7   if ( isset($EXAMS_actual) ) {
8     $showexam = $EXAMS_actual;
9   }
10   else if ( isset($EXAMS_last) ) {
11     block("red", "no next exam");
12     $showexam = $EXAMS_last;
13   }
14   else {
15     block("red", "no exams defined");
16     exit;
17   }
18
19   if( isset($_GET['examselected']) ) { $showexam = trim($_GET['examselected']); }
20
21   if( isset($_GET['examid']) && isset($_GET['mnumber']) && isset($_GET['tstamp']) && isset($_GET['scorestr']) ) {
22      $up_examid = trim($_GET['examid']);
23      $up_mnumber = trim($_GET['mnumber']);
24      $up_tstamp = trim($_GET['tstamp']);
25      $up_scorestr = trim($_GET['scorestr']);
26
27      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 ) {
28        $db->query("DELETE FROM examscore WHERE mnumber=$up_mnumber AND exam=$up_examid");
29        $db->query("INSERT INTO examscore (exam,mnumber,scorestr,tstamp) values ($up_examid,$up_mnumber,\"$up_scorestr\",$up_tstamp)");
30        block("lightgreen", "modified submit");
31      }
32   }
33
34   print "<form action='examoverview.php'>";
35   print "<select name='examselected' onchange='this.form.submit()'>";
36   foreach($EXAMS as $exam) {
37     $note = "";
38     if( isset($EXAMS_actual) && $exam['id'] == $EXAMS_actual ) { $note = "(next)"; }
39     if( isset($EXAMS_last) && $exam['id'] == $EXAMS_last ) { $note = "(last)"; }
40     if( $showexam != $exam['id'] ) {
41       print "<option value=" . $exam['id'] . ">" . $exam['timestr'] . " " . $note . "</option>";
42     }
43     else {
44       print "<option value=" . $exam['id'] . " selected='selected'>" . $exam['timestr'] . " " . $note . "</option>";
45     }
46   } 
47   print "</select>";
48   print "</form>";
49
50   block("black", "summary for exam " . $EXAMS[$showexam]['timestr'] . " (" . $EXAMS[$showexam]['scorestr'] . ")");
51
52   $result = $db->query("SELECT firstname, lastname, mnumber FROM students ORDER BY LOWER(lastname)");
53
54   print "<table>";
55   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>";
56
57   # if( isset($EXAMS_actual) && $showexam == $EXAMS_actual ) {
58   #   print "<td><b>Blackboard&nbsp;</b></td>";
59   # }
60   # else {
61   #   print "<td><b>Modify&nbsp;</b></td>";
62   # }
63
64   while ($student = $result->fetch(PDO::FETCH_ASSOC)) {
65     $result2 = $db->query("SELECT scorestr FROM examscore WHERE mnumber=" . $student['mnumber'] . " AND exam=" . $showexam)->fetch(PDO::FETCH_NUM);
66
67     $exdone = $result2[0];
68     if ($exdone == "") { $exdone=0; }
69
70     $scorestr = $result2[0];
71
72     $totscore = 0;
73     foreach (explode(',',$scorestr) as $points) {
74       $totscore = $totscore + $points;
75     }
76
77     print "<tr>";
78     print "<td>" . $student['firstname'] . "</td>";
79     print "<td>" . $student['lastname'] . "</td>";
80     print "<td>" . $student['mnumber'] . "</td>";
81     print "<td>" . $totscore . "/" . $EXAMS[$showexam]['totscore'] . "</td>";
82
83     print "<td><form style='margin: 0; padding: 0' action='examoverview.php'>";
84     if( isset($_GET['examselected']) ) { print "<input type='hidden' name='examselected' value='" . $_GET['examselected'] . "' />"; } 
85     print "<input type='hidden' name='examid' value='" . $showexam . "' />";
86     print "<input type='hidden' name='mnumber' value='" . $student['mnumber'] . "' />";
87     print "<input type='hidden' name='tstamp' value='" . time() . "' />";
88     print "<input size='10' name='scorestr' type='text' value='" . $scorestr . "'>";
89     print "</form></td>";
90
91     print "</tr>";
92   }
93   print "</table>";
94 ?>