-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompile.php
More file actions
63 lines (63 loc) · 1.71 KB
/
Copy pathcompile.php
File metadata and controls
63 lines (63 loc) · 1.71 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
<?php
require_once 'core.inc.php';
$code=$_POST["code"];
$input='["'.$_POST["input"].'"]';
$lang=0;
if($_SESSION['lang']=="c")
$lang=1;
else if($_SESSION['lang']=="cpp")
$lang=2;
else if($_SESSION['lang']=="java")
$lang=3;
else
$lang=5;
if($input=="")
{
$input="['1']";
}
$post=[
'source'=>$code,
'lang'=> 1,
'testcases'=>$input,
'api_key'=>"hackerrank|1571962-2213|c9bd1d8a2c8d21cc4244fb4d8b37080d0167ed5a",
];
$ch= curl_init("http://api.hackerrank.com/checker/submission.json");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
$json = json_decode($server_output, true);
if($json['result']['compilemessage']==""){
$target_dir = 'uploads/'.$_SESSION['sub'].'/';
$q=$_SESSION['sub'];
$name=getfield('USERNAME');
$filename_code1=$target_dir.$name.".txt";
$file_code=fopen($filename_code1,"w+");
$id="NAME:- ".getfield('NAME')."\n";
$id1="GR NO:-".$name."\n";
$id2="\n\nSOURCE CODE:-\n";
$id3="INPUT:-\n";
$id4="\nOUTPUT:-\n";
fwrite($file_code,$id);
fwrite($file_code,$id1);
fwrite($file_code,$id3);
fwrite($file_code,$_POST["input"]);
fwrite($file_code,$id2);
fwrite($file_code, $code);
fwrite($file_code, $id4);
fwrite($file_code, implode("",$json['result']['stdout']));
fclose($file_code);
$i=getfield('ID');
$q=$_SESSION['sub'];
$query="UPDATE `assignments` SET `$q` ='1' WHERE `ID` = '$i'";
echo "<div class='container' style='background:white;'>OUTPUT:_".implode("",$json['result']['stdout'])."</div>";
if(!mysql_query($query))echo mysql_error();
else
header("refresh:4 url=index.php");
}else
{
echo "ERROR:-";
print_r($json['result']['compilemessage']);
}
?>