aboutsummaryrefslogtreecommitdiff
path: root/src/judge/team.php
blob: 745380af53e52890e304ecc8cd2ee8e4d58445eb (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
////////////////////////////////////////////////////////////////////////////////
//BOCA Online Contest Administrator
//    Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com)
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////
// Last modified 21/jul/2012 by cassio@ime.usp.br
require('header.php');

if (isset($_FILES["sourcefile"]) && isset($_POST["problem"]) && isset($_POST["Submit"]) && isset($_POST["language"]) &&
    is_numeric($_POST["problem"]) && is_numeric($_POST["language"]) && $_FILES["sourcefile"]["name"]!="") {
	if ($_POST["confirmation"] == "confirm") {
		if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null)
			ForceLoad("../index.php");

		$prob = myhtmlspecialchars($_POST["problem"]);
		$lang = myhtmlspecialchars($_POST["language"]);

		$type=myhtmlspecialchars($_FILES["sourcefile"]["type"]);
		$size=myhtmlspecialchars($_FILES["sourcefile"]["size"]);
		$name=myhtmlspecialchars($_FILES["sourcefile"]["name"]);
		$temp=myhtmlspecialchars($_FILES["sourcefile"]["tmp_name"]);

		if ($size > $ct["contestmaxfilesize"]) {
	                LOGLevel("User {$_SESSION["usertable"]["username"]} tried to submit file " .
			"$name with $size bytes ({$ct["contestmaxfilesize"]} max allowed).", 1);
			MSGError("File size exceeds the limit allowed.");
			ForceLoad($runteam);
		}
		if(strpos($name,' ') === true || strpos($temp,' ') === true) {
			MSGError("File name cannot contain spaces.");
			ForceLoad($runteam);		
		}
		if (!is_uploaded_file($temp) || strlen($name)>100) {
			IntrusionNotify("file upload problem.");
			ForceLoad("../index.php");
		}


		//		$ac=array('contest','site','user','problem','lang','filename','filepath');
		//		$ac1=array('runnumber','rundate','rundatediff','rundatediffans','runanswer','runstatus','runjudge','runjudgesite',
		//			   'runjudge1','runjudgesite1','runanswer1','runjudge2','runjudgesite2','runanswer2',
		//			   'autoip','autobegindate','autoenddate','autoanswer','autostdout','autostderr','updatetime');
		$param = array('contest'=>$_SESSION["usertable"]["contestnumber"],
					   'site'=>$_SESSION["usertable"]["usersitenumber"],
					   'user'=>  $_SESSION["usertable"]["usernumber"],
					   'problem'=>$prob,
					   'lang'=>$lang,
					   'filename'=>$name,
					   'filepath'=>$temp);
		if($runteam=='team.php') $param['allowneg']=1;
		DBNewRun ($param);
		$_SESSION['forceredo']=true;
	}
	ForceLoad($runteam);
}

$ds = DIRECTORY_SEPARATOR;
if($ds=="") $ds = "/";

$runtmp = $_SESSION["locr"] . $ds . "private" . $ds . "runtmp" . $ds . "run-contest" . $_SESSION["usertable"]["contestnumber"] . 
	"-site". $_SESSION["usertable"]["usersitenumber"] . "-user" . $_SESSION["usertable"]["usernumber"] . ".php";
$redo = TRUE;
if(!isset($_SESSION['forceredo']) || $_SESSION['forceredo']==false) {
	$actualdelay = 30;
	if(file_exists($runtmp)) {
		if(isset($strtmp) || (($strtmp = file_get_contents($runtmp,FALSE,NULL,-1,1000000)) !== FALSE)) {
			list($d) = sscanf($strtmp,"%*s %d");
			if($d > time() - $actualdelay) {
				$conf=globalconf();
				$strtmp = decryptData(substr($strtmp,strpos($strtmp,"\n")+1),$conf["key"],'runtmp');
				if($strtmp !== false)
					$redo = FALSE;
			}
		}
	}
}
if($redo) {
	$_SESSION['forceredo']=false;
	if(($st = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null)
        ForceLoad("../index.php");
	$strtmp="<br>\n<table width=\"100%\" border=1>\n <tr>\n  <td><b>Run #</b></td>\n<td><b>Time</b></td>\n".
		"  <td><b>Problem</b></td>\n  <td><b>Language</b></td>\n  <td><b>Answer</b></td>\n  <td><b>File</b></td>\n </tr>\n";
	$strcolors = "0";
	$run = DBUserRuns($_SESSION["usertable"]["contestnumber"],
					  $_SESSION["usertable"]["usersitenumber"],
					  $_SESSION["usertable"]["usernumber"]);
	for ($i=0; $i<count($run); $i++) {
		$strtmp .= " <tr>\n";
		$strtmp .= "  <td nowrap>" . $run[$i]["number"] . "</td>\n";
		$strtmp .= "  <td nowrap>" . dateconvminutes($run[$i]["timestamp"]) . "</td>\n";
		$strtmp .= "  <td nowrap>" . $run[$i]["problem"] . "</td>\n";
		$strtmp .= "  <td nowrap>" . $run[$i]["language"] . "</td>\n";
//  $strtmp .= "  <td nowrap>" . $run[$i]["status"] . "</td>\n";
		if (trim($run[$i]["answer"]) == "") { 
			$run[$i]["answer"] = "Not answered yet";
			$strtmp .= "  <td>Not answered yet"; 
		}
		else {
			$strtmp .= "  <td>" . $run[$i]["answer"]; 
			if(false) {
				if(strpos($run[$i]["autoanswer"],"OKs") > 0)
					$strtmp .= ' ' . substr($run[$i]["autoanswer"],strrpos($run[$i]["autoanswer"],'('));
			}
			if($run[$i]['yes']=='t') {
				$strtmp .= " <img alt=\"".$run[$i]["colorname"]."\" width=\"15\" ".
					"src=\"" . balloonurl($run[$i]["color"]) ."\" />";
				$strcolors .= "\t" . $run[$i]["colorname"] . "\t" . $run[$i]["color"];
			}
		}
		$strtmp .= "</td>\n";
		$strtmp .= "<td nowrap><a href=\"../filedownload.php?" . filedownload($run[$i]["oid"],$run[$i]["filename"]) . "\">";
		$strtmp .= $run[$i]["filename"] . "</a>";
		
		$strtmp .= "</td>\n";
		
		$strtmp .= " </tr>\n";
		
		if ($run[$i]["anstime"]>$_SESSION["usertable"]["userlastlogin"]-$st["sitestartdate"] && $run[$i]["anstime"] < $st['sitelastmileanswer'] &&
			$run[$i]["ansfake"]!="t" && !isset($_SESSION["popups"]['run' . $i . '-' . $run[$i]["anstime"]])) {
			$_SESSION["popups"]['run' . $i . '-' . $run[$i]["anstime"]] = "Run ".$run[$i]["number"]." result: ".$run[$i]["answer"]. "<br>";
		}
	}
$strtmp .= "</table>";
if (count($run) == 0) $strtmp .= "<br><center><b><font color=\"#ff0000\">NO RUNS AVAILABLE</font></b></center>";

$strtmp .= "<br><br><center><b>To submit a program, just fill in the following fields:</b></center>\n".
"<form name=\"form1\" enctype=\"multipart/form-data\" method=\"post\" action=\"". $runteam ."\">\n".
"  <input type=hidden name=\"confirmation\" value=\"noconfirm\" />\n".
"  <center>\n".
"    <table border=\"0\">\n".
"      <tr> \n".
"        <td width=\"25%\" align=right>Problem:</td>\n".
"        <td width=\"75%\">\n".
"          <select name=\"problem\" onclick=\"Arquivo()\">\n";
$prob = DBGetProblems($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usertype"]=='judge');
for ($i=0;$i<count($prob);$i++)
	$strtmp .= "<option value=\"" . $prob[$i]["number"] . "\">" . $prob[$i]["problem"] . "</option>\n";
$strtmp .= "	  </select>\n".
"        </td>\n".
"      </tr>\n".
"      <tr> \n".
"        <td width=\"25%\" align=right>Language:</td>\n".
"        <td width=\"75%\"> \n".
"          <select name=\"language\" onclick=\"Arquivo()\">\n";
$lang = DBGetLanguages($_SESSION["usertable"]["contestnumber"]);
for ($i=0;$i<count($lang);$i++)
	$strtmp .= "<option value=\"" . $lang[$i]["number"] . "\">" . $lang[$i]["name"] . "</option>\n";
$strtmp .= "	  </select>\n".
"        </td>\n".
"      </tr>\n".
"      <tr> \n".
"        <td width=\"25%\" align=right>Source code:</td>\n".
"        <td width=\"75%\">\n".
"	  <input type=\"file\" name=\"sourcefile\" size=\"40\" onclick=\"Arquivo()\">\n".
"        </td>\n".
"      </tr>\n".
"    </table>\n".
"  </center>\n".
"  <script language=\"javascript\">\n".
"    function conf() {\n".
"      if (confirm(\"Confirm submission?\")) {\n".
"        document.form1.confirmation.value='confirm';\n".
"      }\n".
"    }\n".
"  </script>\n".
"  <center>\n".
"      <input type=\"submit\" name=\"Submit\" value=\"Send\" onClick=\"conf()\">\n".
"      <input type=\"reset\" name=\"Submit2\" value=\"Clear\">\n".
"  </center>\n".
"</form>\n";
    $conf=globalconf();
    $strtmp1 = "<!-- " . time() . " --> <?php exit; ?>\t" . encryptData($strcolors,$conf["key"],false) . "\n" . encryptData($strtmp,$conf["key"],false);
	$randnum = session_id() . "_" . rand();
	if(file_put_contents($runtmp . "_" . $randnum, $strtmp1,LOCK_EX)===FALSE) {
		if(!isset($_SESSION['writewarn'])) {
			LOGError("Cannot write to the user-run cache file $runtmp -- performance might be compromised");
			$_SESSION['writewarn']=true;
		}
	}
	@rename($runtmp . "_" . $randnum, $runtmp);
}
echo $strtmp;
?>


</body>
</html>