<?php
- require 'nav.inc';
+ require 'include/head.inc';
+ require 'include/session.inc';
+ require 'include/common.inc';
- $lines = file('var/sessions.txt');
-
- foreach ($lines as $line_num => $line) {
- $sessions[$line_num] = explode("\t",$line);
- }
-
- if ( strtotime("now") > strtotime(end($sessions)[0]) ) {
- print '<table bgcolor="red">';
- print '<tr><th><b><font color="white">submission closed</font></b></th><tr>';
- print '</table>';
- break;
+ if ( ! isset($SESSIONS_next) ) {
+ block("red", "submission closed");
+ exit;
}
if(isset($_POST['submit']) && $_POST['mnumber']!="") {
- require 'usercheck.inc';
-
+ require 'include/usercheck.inc';
+
$exchecked = $_POST['exchecked'];
$mnumber = $_POST['mnumber'];
- $sessionid = strtotime(end($sessions)[0]);
+ $sessionid = $SESSIONS[$SESSIONS_next]['id'];
if($db->query("SELECT COUNT(*) FROM workdone WHERE mnumber = $mnumber AND session = $sessionid")->fetch(PDO::FETCH_NUM)[0] == 1) {
- print '<table bgcolor="red">';
- print '<tr><th><b><font color="white">You already submitted results for this session</font></b></th><tr>';
+ $db->query("DELETE FROM workdone WHERE mnumber = $mnumber AND session = $sessionid");
+ print '<table bgcolor="lightgreen">';
+ print '<tr><th><b><font color="white">deleted old submission</font></b></th><tr>';
print '</table>';
- print "You can only submit your calculated examples once!";
- break;
}
$excount = count($exchecked);
- $donestring = implode(', ', $exchecked);
+ $donestring = implode(',', $exchecked);
$db->query("INSERT INTO workdone (mnumber,session,manydone,thisdone)
VALUES (\"$mnumber\", \"$sessionid\", \"$excount\", \"$donestring\")");
print '<table bgcolor="lightgreen">';
print '<tr><th><b><font color="white">submitted</font></b></th><tr>';
print '</table>';
- break;
- }
-
- if(trim(end($sessions)[0]) == "") {
- print '<table bgcolor="red">';
- print '<tr><th><b><font color="white">no exercises defined</font></b></th><tr>';
- print '</table>';
- break;
+ exit;
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table bgcolor="black">
- <tr><th><b><font color="white">submit examples for <?php echo end($sessions)[0]; ?></font></b></th><tr>
+ <tr><th><b><font color="white">submit examples for <?php echo $SESSIONS[$SESSIONS_next]['timestr']; ?></font></b></th><tr>
</table>
<table>
<?php
$exnum=0;
- foreach (explode(",",end($sessions)[1]) as $exid) {
+ foreach (explode(",",$SESSIONS[$SESSIONS_next]['examples']) as $exid) {
print " <input type='checkbox' name='exchecked[]' value=$exid>$exid ";
$exnum++;
if ($exnum%3 == 0) { print ""; }