]> git.treefish.org Git - banana.git/blob - submit.php
added exams
[banana.git] / submit.php
1 <?php
2   require 'include/head.inc';
3   require 'include/session.inc';
4   require 'include/common.inc';
5
6   if ( ! isset($SESSIONS_next) ) {
7     block("red", "submission closed");
8     exit;
9   }
10
11   if(isset($_POST['submit']) && $_POST['mnumber']!="") {
12     require 'include/usercheck.inc';
13
14     $exchecked = $_POST['exchecked'];
15
16     $mnumber = $_POST['mnumber'];
17     $sessionid = $SESSIONS[$SESSIONS_next]['id'];
18
19     if($db->query("SELECT COUNT(*) FROM workdone WHERE mnumber = $mnumber AND session = $sessionid")->fetch(PDO::FETCH_NUM)[0] == 1) {
20       $db->query("DELETE FROM workdone WHERE mnumber = $mnumber AND session = $sessionid");
21       print '<table bgcolor="lightgreen">';
22         print '<tr><th><b><font color="white">deleted old submission</font></b></th><tr>';
23       print '</table>';
24     }
25
26     $excount = count($exchecked);
27     $donestring = implode(',', $exchecked);
28
29     $db->query("INSERT INTO workdone (mnumber,session,manydone,thisdone) 
30         VALUES (\"$mnumber\", \"$sessionid\", \"$excount\", \"$donestring\")");
31
32     print '<table bgcolor="lightgreen">';
33       print '<tr><th><b><font color="white">submitted</font></b></th><tr>';
34     print '</table>';
35     exit;
36   }
37
38 ?>
39
40   <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
41   <table bgcolor="black">
42     <tr><th><b><font color="white">submit examples for <?php echo $SESSIONS[$SESSIONS_next]['timestr']; ?></font></b></th><tr>
43   </table>
44
45   <table>
46     <tr>  
47       <th align="left">Mat.nummer:</th> <th align="left"><input type="text" name="mnumber"></th>
48     </tr>
49     <tr>  
50       <th align="left">Password:</th> <th align="left"><input type="text" name="password"></th>
51     </tr>
52  
53     <tr><th colspan=2></th></tr>
54
55     <tr>
56       <th align="left">Examples:</th>
57       <th>
58
59         <?php
60           $exnum=0;
61           foreach (explode(",",$SESSIONS[$SESSIONS_next]['examples']) as $exid) {
62             print " <input type='checkbox' name='exchecked[]' value=$exid>$exid ";
63             $exnum++;
64             if ($exnum%3 == 0) { print ""; }
65           }
66         ?>
67       </th>     
68     </tr>
69
70     <tr><th colspan=2></th></tr>
71
72     <tr>
73       <th align="left"><input type="submit" name="submit" value="Submit"></th> <th></th>
74     </tr>
75   </table>
76 </form>