<?php

$postData = file_get_contents("php://input");
$postData = json_decode($postData, true);

$uname = $postData['username'];
$filename = $postData['filename'];
$language = $postData['language'];

$ret_stat = 0;

if(strcmp($language, "cpp") == 0)
{
    $base = basename($filename, ".cpp");
    system("g++ ../users/" . $uname . "/" . $filename . " -o ../users/" . $uname . "/" . $base , $ret_stat);

    if($ret_stat != 0)
    {
        unlink("../users/" . $uname . "/" . $base);
    }
}

else if(strcmp($language, "java") == 0)
{
    $base = basename($filename, ".java");
    system("javac ../users/" . $uname . "/" . $filename , $ret_stat);

    if($ret_stat != 0)
    {
        unlink("../users/" . $uname . "/" . $base . ".class");
    }
}

echo $ret_stat;
?>