-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessfile.php~
138 lines (113 loc) · 2.9 KB
/
processfile.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
<?php
/*
* @copyright (c) 2008 Nicolo John Davis
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
session_start();
if(!isset($_SESSION['isloggedin']))
{
echo "<meta http-equiv='Refresh' content='0; URL=login.php' />";
exit(0);
}
else
{
$username = $_SESSION['username'];
$userid = $_SESSION['userid'];
}
include('settings.php');
?>
<?php
/*
#define RIGHT 0
#define COMPILE_ERROR 1
#define WRONG 2
#define TIME_EXCEEDED 3
#define ILLEGAL_FILE 4
*/
if($running == true)
{
$isUpload = false;
$problemid = -1;
$file = -1;
for($i=1 ; $i<=count($points) ; $i++)
{
if(isset($_FILES[$i]))
{
$isUpload = true;
$file = $i;
$problemid = $i;
}
}
$timeLimit=$time_limit[$problemid-1];
if($isUpload == true)
{
$cn = mysql_connect('localhost', $DBUSER, $DBPASS);
mysql_select_db($DBNAME, $cn);
$status = 0;
$query = "select problemid, status from submissions where userid=$userid and problemid=$problemid order by time desc";
$result = mysql_query($query);
if($result)
{
$result = mysql_fetch_array($result);
}
if(isset($result['status']))
$status = $result['status'];
else
$status = -1;
$status++;
$statString = array('-', 'Accepted', 'Compile Error','Wrong Answer', 'Time Limit','Invalid File' );
mysql_close($cn);
if($statString[$status] != "Accepted")
{
$userDir = "$CODEDIR/".$username."/";
$uploadDir = $userDir . $file . "/";
if(!file_exists("$CODEDIR/"))
{
mkdir("$CODEDIR/") or die("Could not create upload directory");
}
if(!file_exists($userDir))
{
mkdir($userDir);
chmod($userDir, 0777);
}
if(!file_exists($uploadDir))
{
mkdir($uploadDir);
chmod($uploadDir, 0777);
}
$destFile = $uploadDir . $_FILES[$file]["name"];
if($_FILES[$file]["error"] > 0)
{
echo $_FILES[$file]["error"];
}
else if ($_FILES[$file]["size"] > 50000)
{
die("too large file "); /*file greater than 500 kb won't be uploaded*/
}
else
{
move_uploaded_file($_FILES[$file]["tmp_name"], $destFile);
// sleep(5);
//----Invoke online judge-----------
exec("./onj $destFile $file $timeLimit $username", $output, $verdict);
$cn = mysql_connect('localhost', $DBUSER, $DBPASS);
mysql_select_db($DBNAME, $cn);
$t = time();
$query = "insert into `submissions` (userid, problemid, status, time) values($userid, $file, $verdict, $t)";
mysql_query($query);
if($verdict == 0)
{
$score=0;
if($file>=1 && $file<=count($points));
$score = $points[$file-1];
$query = "update `users` set score = score + $score where `id` = $userid";
mysql_query($query);
}
$verdict = array('verdict' => $verdict, 'problemid' => $problemid);
echo json_encode($verdict);
mysql_close($cn);
}
}
}
}
?>