Ejemplo n.º 1
0
  websheets.authinfo = <?php 
echo json_encode($GLOBALS['WS_AUTHINFO']);
?>
;

<?php 
//if (!$GLOBALS['WS_AUTHINFO']['logged_in'])
//echo "websheets.initialize_error = 'You must log in to use the editor.';";
//else
if (!array_key_exists('edit', $_REQUEST)) {
    echo "websheets.initialize_error = 'Please use one of the buttons above to start editing.';";
} else {
    require_once 'edit.php';
    $_REQUEST['action'] = 'load';
    $_REQUEST['problem'] = $_REQUEST['edit'];
    $result = json_decode(run_edit_py(), true);
    $author = '';
    $readonly = false;
    if (is_string($result)) {
        echo "websheets.initialize_error = " . json_encode($result) . ";";
    } else {
        if ($result['success']) {
            echo "websheets.initialize_editor = " . json_encode($result) . ";";
            $author = $result['author'];
            if ($author != $GLOBALS['WS_AUTHINFO']['username']) {
                echo "websheets.editor_readonly = true;";
            }
            echo "websheets.author = " . json_encode($author) . ";";
        } else {
            echo "websheets.initialize_error = " . json_encode($result['message']) . ";";
        }
Ejemplo n.º 2
0
</head>
<body>
<div id='info'><?php 
echo $GLOBALS['WS_AUTHINFO']['info_span'];
?>
 </div>
<div>
<a href='#' onclick='window.list.className="hidenotmine"'>Show only my websheets</a>
<a href='#' onclick='window.list.className="hidemine"'>Show only other authors' websheets</a>
<a href='#' onclick='window.list.className=""'>Show all websheets</a>
</div>
<table id='list'>
<?php 
require_once 'edit.php';
$_REQUEST['action'] = 'listmine';
$editout = run_edit_py();
//  echo $editout;
$result = json_decode($editout, true);
$author = '';
$readonly = false;
if (is_string($result)) {
    echo $result;
} else {
    foreach ($result['problems'] as $probleminfo) {
        $name = $probleminfo[0];
        $i = strrpos($name, '/');
        if ($i == -1) {
            $folder = "";
        } else {
            $folder = substr($name, 0, $i);
        }
Ejemplo n.º 3
0
require_once 'auth.php';
# for internal errors, it will print a json-encoded string
# otherwise (including some errors), it will print a json-encoded object
function run_edit_py()
{
    global $WS_AUTHINFO;
    if ($WS_AUTHINFO["error_span"] != "") {
        return json_encode($WS_AUTHINFO);
    }
    $_REQUEST['authinfo'] = $WS_AUTHINFO;
    $package = json_encode($_REQUEST);
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $process = proc_open("python3 ./edit.py", $descriptorspec, $pipes);
    if (!is_resource($process)) {
        return json_encode("Internal error, could not run Websheet program");
    }
    fwrite($pipes[0], $package);
    fclose($pipes[0]);
    $stdout = stream_get_contents($pipes[1]);
    fclose($pipes[1]);
    $stderr = stream_get_contents($pipes[2]);
    fclose($pipes[2]);
    $return_value = proc_close($process);
    if ($stderr != "" || $return_value != 0) {
        return json_encode("Internal error: <pre>{$stdout}{$stderr}\nReturned {$return_value}</pre>");
    }
    return $stdout;
}
if ($edit_is_main) {
    echo run_edit_py();
}