-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinsert.php
More file actions
executable file
·99 lines (75 loc) · 2.27 KB
/
insert.php
File metadata and controls
executable file
·99 lines (75 loc) · 2.27 KB
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
<?php
session_start();
if(!isset($_SESSION['isloggedin']))
{
echo "Please login first";
echo "<meta http-equiv='Refresh' content='3; URL=index.php' />";
exit(0);
}
else
{
$username = $_SESSION['username'];
$userid = $_SESSION['userid'];
}
if(!isset($_POST['problemID'])||!isset($_FILES["file"]["name"]))
{
echo "No problem selected";
echo "<meta http-equiv='Refresh' content='3; URL=problem.php' />";
exit(0);
}
if($_FILES["file"]["size"]>50000)
{
echo"Too large file";
echo "<meta http-equiv='Refresh' content='3; URL=problem.php' />";
exit(0);
}
include('settings.php');
$cn = mysql_connect('localhost', $DBUSER, $DBPASS);
mysql_select_db($DBNAME, $cn);
$query="SELECT * from problems where problemID= ".$_POST['problemID'];
$logged=mysql_query($query);
$logg=mysql_fetch_array($logged);
$contestID=$logg['contestID'];
$score=$logg['score'];
$problemName=$logg['problemName'];
$runtimelimit=$logg['timeLimit'];
$runmemlimit=$logg['memoryLimit'];
/*
#define RIGHT 0
#define COMPILE_ERROR 1
#define WRONG 2
#define TIME_EXCEEDED 3
#define ILLEGAL_FILE 4
#define Runtime error 5
#define Waiting 6
*/
$lang=array(
"c"=>"C",
"cpp"=>"C++",
"java"=>"JAVA",
"py"=>"python"
);
$problemID=$_POST['problemID'];
$username=$_SESSION['username'];
//$logged = mysql_query($query);
$fileinfo=pathinfo($_FILES["file"]["name"]);
$ext=strtolower($fileinfo['extension']);
$ext=$_POST['language'];
if(!isset($lang[$ext])){
$ext="unknown";
$query ="INSERT INTO submissions(problemID,problemName,userID,username,runtime,submlang,status )VALUES($problemID,'$problemName',$userid,'$username',0.0,'$ext',4) ";
mysql_query($query);
mysql_close($cn);
echo "<meta http-equiv='Refresh' content='0; URL=status.php' /> ";
exit(0);
}
$query="INSERT INTO submissions(problemID,problemName,userID,username,runtime,submlang,status )VALUES($problemID,'$problemName',$userid,'$username',0.0,'".$lang[$ext]."',6) ";
mysql_query($query);
$query="select last_insert_id() AS subID";
$logged = mysql_query($query);
$logg = mysql_fetch_array($logged);
$submID=$logg['subID'];
mkdir("/var/www/newonj/submissions/".$userid, 0700);
move_uploaded_file($_FILES["file"]["tmp_name"],"/var/www/newonj/submissions/$userid/$submID".".".$ext);
?>
<meta http-equiv='Refresh' content='0; URL=status.php' />