-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsubmit.php
161 lines (134 loc) · 3.79 KB
/
submit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
include("config.php");
include("common.php");
?>
<html>
<head>
<?php print "<title>$g_pagetitle - Submit</title>\n"; ?>
</head>
<body>
<div align="center">
<h1>Submissions</h1>
</div>
<?php
navigation("submit");
$contest = new Contest($g_configfile, $g_problempath);
?>
<hr>
<div align="center">
<?php
// check if they're logged in
if (empty($_SESSION["teamid"]))
print "<p><i>You must be logged in to submit and view runs.</i></p>\n";
// re-authenticate the team, in case the password changed or they have been deleted
else if ($_SESSION["password"] != $g_teams[$_SESSION["teamid"]])
{
print "<p><i>Team configuration has changed. Please log in again.</i></p>\n";
unset($_SESSION["teamid"]);
unset($_SESSION["password"]);
}
else
{
// check that the contest is still running
if ($contest->tnow < $contest->tstart)
{
print "<p><i>Waiting for contest to start.</i></p>\n";
}
else if ($contest->tnow >= $contest->tend)
{
print "<p><i>Contest is over.</i></p>\n";
}
else
{
// ----- HTML -----
print <<<END
<p><b><big>Submit Solution</big></b></p>
<form name="submit" method="post" action="confirm.php" enctype="multipart/form-data">
<table border="0" width="400">
<tr>
<td>Problem:</td>
<td><select name="problem">
END;
// ----- END -----
foreach ($contest->pnames as $name)
{
$letter = $name{0};
print "<option value=\"$letter\">$name</option>";
}
$nlanguages = count($g_extension);
// ----- HTML -----
print <<<END
</select></td>
</tr>
<tr>
<td>Language:</td>
<td><select name="language" size = "$nlanguages">
END;
// ----- END -----
foreach (array_keys($g_extension) as $value) {
$selected = $_SESSION["language"] == $value ? "selected" : "";
print " <option $selected value=\"$value\">$value</option>\n";
}
// ----- HTML -----
print <<<END
</select></td>
</tr>
<tr><td>Source:</td><td><input type="file" name="source"></td></tr>
<tr align="center"><td colspan="2"><input type="submit" value="Submit!!!"></td></tr>
</table>
</form>
END;
// ----- END -----
}
print "<hr>\n";
$team = $_SESSION["teamid"];
$runs = array();
if ($fp = fopen($g_submitfile, "r"))
{
flock($fp, LOCK_SH);
while ($line = fgets($fp))
{
if (trim($line) == "FINAL") continue;
$run = new Run($line);
if ($team == $run->team) $runs[trim($line)] = $run;
}
fclose($fp);
}
else
{
print "<p>Unable to locate submissions.</p>\n";
}
if ($fp = fopen($g_judgefile, "r"))
{
flock($fp, LOCK_SH);
while ($line = fgets($fp))
{
list($key, $verdict) = explode(";", trim($line));
$run = new Run($key);
if ($team == $run->team && array_key_exists($key, $runs))
$runs[$key]->verdict = $verdict;
}
fclose($fp);
}
print "<p><b><big>Runs received from team $team</big></b></p>\n";
print "<table border=\"1\" width=\"480\" cellspacing=\"0\">\n";
print "<tr bgcolor=\"#EEEEEE\"><th>Time</th><th>Problem</th><th>Language</th><th>Verdict</th></tr>\n";
foreach ($runs as $run)
{
$verdict = array_key_exists($run->verdict, $g_verdicts) ?
$g_verdicts[$run->verdict] : "Unknown";
if ($run->verdict == "E")
$verdict = $verdict . " <i>(Please contact judge!)</i>";
// colour code the results
if ($run->verdict == "U") print "<tr>";
else if ($run->verdict == "A") print "<tr bgcolor=\"#CCFFCC\">";
else print "<tr bgcolor=\"#FFCCCC\">";
print "<td>$run->time</td><td>$run->problem</td><td>$run->language</td><td>$verdict</td></tr>\n";
}
print "</table><br>\n";
}
?>
</div>
<?php footer(); ?>
</body>
</html>