-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathruncontest.php
327 lines (207 loc) · 6.96 KB
/
runcontest.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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
session_start();
require_once("config.php");
if(!isset($_SESSION['un']))
{
header("Location:login.php");
}
if(isset($_SESSION['un']))
{
$username=$_SESSION['un'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Run Code</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/vendor/modernizr-2.8.3.min.js"></script>
</head>
<body>
<div class="main">
<div class="row">
<div class="col-sm-12">
<nav class="navbar navbar-inverse navbar-fixed-top nbar">
<div class="navbar-header">
<a class="navbar-brand lspace" href="#">Home</a>
</div>
<ul class="nav navbar-nav">
<li class="space"><a href="#"><i class="fa fa-code ispace"></i>Compiler</a></li>
<li class="space"><a href="archive.php"><i class="fa fa-archive ispace"></i>Problem Archive</a></li>
<li class="space"><a href="#"><i class="fa fa-cogs ispace"></i>Contests</a></li>
<li class="space"><a href="#"><i class="fa fa-check-square ispace"></i>Debug</a></li>
<li class="lgspace space"><a href="profile.php?user=<?php echo("$username"); ?>"><i class="fa fa-user ispace"></i><?php echo("$username"); ?></a></li>
<li class="space"><a href="logout.php"><i class="fa fa-power-off ispace"></i>Logout</a></li>
</ul>
</nav>
</div>
</div>
<div class="row log">
<div class="col-sm-10">
<div class=""><h3 style="text-align:center;">Code Compiler</h3></div>
</div>
<div class="col-sm-1">
</div>
<div class="col-sm-1">
</div>
</div>
<div class="row cspace">
<div class="col-sm-8">
<?php
//Import the SDK
require("connection.php");
require_once("/path/sdk/index.php");
//Setting up the Hackerearth API
$hackerearth = Array(
'client_secret' => '16a9520253721a46a15f22e083abe1274762020d', //(REQUIRED) Obtain this by registering your app at http://www.hackerearth.com/api/register/
'time_limit' => '5', //(OPTIONAL) Time Limit (MAX = 5 seconds )
'memory_limit' => '262144' //(OPTIONAL) Memory Limit (MAX = 262144 [256 MB])
);
//Feeding Data Into Hackerearth API
$lang=$_POST['lan'];
$source=$_POST['src'];
//$input=$_POST['in'];
$pb=$_POST['pbn'];
$pid=$_POST['id'];
$us=$_SESSION['un'];
$isql="SELECT tc FROM element WHERE pbid='$pid'";
$si=mysqli_query($con,$isql);
$r4=mysqli_fetch_array($si);
$input=$r4['tc'];
$config = Array();
$config['time']='5'; //(OPTIONAL) Your time limit in integer and in unit seconds
$config['memory']='262144'; //(OPTIONAL) Your memory limit in integer and in unit kb
$config['source']=$source; //(REQUIRED) Your formatted source code for which you want to use hackerEarth api, leave this empty if you are using file
$config['input']=$input; //(OPTIONAL) formatted input against which you have to test your source code
$config['language']=$lang; //(REQUIRED) Choose any one of the below
// C, CPP, CPP11, CLOJURE, CSHARP, JAVA, JAVASCRIPT, HASKELL, PERL, PHP, PYTHON, RUBY
//Sending request to the API to compile and run and record JSON responses
$response = run($hackerearth,$config); // Use this $response the way you want , it consists data in PHP Array
//Printing the response
//echo"<pre>".print_r($response,1)."</pre>";
$sql="SELECT output FROM element WHERE pbid='$pid'";
$sq=mysqli_query($con,$sql);
$row=mysqli_fetch_array($sq);
$str="";
$ch=1;
if($response)
{
foreach($response as $value){
$w=$value['status'];
$tl=$value['time_limit'];
//echo "$w";
if(isset($value['output']))
{
$str=$value['output'];
//echo "Your Code has Been Submitted.Click Below To Show Result<br><br>";
// echo "<div style=\"margin-left:300px;\"><form action=\"submission.php\" method=\"POST\"><textarea style=\"display:none\" name=\"result\" rows=\"10\" cols=\"10\">$value[output]</textarea><textarea style=\"display:none\" name=\"ac\" rows=\"10\" cols=\"10\">$row[output]</textarea><input type=\"hidden\" name=\"pb\" value=\"$pb\"><input class=\"btn btn-success tm\" type=\"submit\" value=\"Show Result\"> </div>";
if(error_reporting(1))
{
break;
}
}
else
{
echo "<div style=\"margin-left:250px;\" class=\"alert alert-danger\">
<strong>Compilation Error Or Submit Failed!</strong> Back To Problem Description And Submit Code Again.
</div><br>";
$ch=0;
//error_reporting(0);
break;
}
}
if(error_reporting(0))
{
$nsql="INSERT into code VALUES('$us','$source','')";
$usql="UPDATE element SET uoutput='$str' WHERE pbid='$pid'";
$csql="SELECT uoutput FROM element WHERE pbid='$pid'";
$q3="SELECT id FROM code ORDER BY id DESC ";
$snq=mysqli_query($con,$nsql);
$snd=mysqli_query($con,$usql);
$cnd=mysqli_query($con,$csql);
$sq3=mysqli_query($con,$q3);
$r2=mysqli_fetch_array($cnd);
$r4=mysqli_fetch_array($sq3);
$uo=$r2['uoutput'];
$ac=$row['output'];
$nid=$r4['id'];
//var_dump($uo);
//echo "<br><br>";
//var_dump($ac);
//echo "$uo<br>";
if(strcmp($uo,$ac)==0)
{
$fr="Accepted";
}
else
{
$fr="Wrong Answer";
}
//echo "$fr<br>";
if($ch==1)
{
echo "<div style=\"margin-left:250px;\" class=\"alert alert-success\">
<strong>Successfully Compiled!</strong> Click Below Submit Button To Submit.
</div><br>";
}
echo "<div style=\"margin-left:300px;\"><form action=\"contestsubmission.php\" method=\"POST\"><input type=\"hidden\" name=\"pb\" value=\"$pb\"><input type=\"hidden\" name=\"id\" value=\"$pid\"><input type=\"hidden\" name=\"mid\" value=\"$nid\"><textarea style=\"display:none\" name=\"result\" rows=\"10\" cols=\"10\">$value[output]</textarea><input class=\"btn btn-success tm\" type=\"submit\" value=\"Submit Code\"> </div>";
}
else
{
echo "<div style=\"margin-left:250px;\" class=\"alert alert-danger\">
<strong>Compilation Error Or Submit Failed!</strong> Back To Problem Description And Submit Code Again.
</div><br>";
}
}
else
{
echo "<div style=\"margin-left:250px;\" class=\"alert alert-danger\">
<strong>There is No Internet Connection!</strong> Check Your Connection And Fix It.
</div><br>";
}
/*var_dump($str);
$out=$row['output'];
$m=strlen($out);
var_dump($out);
if(strcmp($str,$out)==0)
{
echo "Accepted";
}
else
{
echo "Wrong Answer";
}
*/
?>
</div>
<div class="col-sm-4">
</div>
</div>
</div>
</div><br><br><br>
<div class="area">
<div class="well foot">
<div class="row area">
<div class="col-sm-3">
</div>
<div class="col-sm-5">
<div class="fm">
<b>Beta Version-2016</b><br>
<b>Developed By Ashadullah Shawon</b>
</div>
</div>
<div class="col-sm-4">
</div>
</div>
</div>
</div>
</body>
</html>