Example #1
0
    exit;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo "<form method='post'><input class='btn btn-warning' type='submit'></input></form>";
    exit;
}
$losts = array_filter(scandir('log'), function ($f) {
    return preg_match('/^lost-.*\\.json/', $f);
});
foreach ($losts as $lost) {
    $file = "log/{$lost}";
    echo "<h2>{$lost}</h2>";
    $jsons = file($file);
    foreach ($jsons as $json) {
        echo "<div><code>{$json}</code></div>";
        $result = omnivore($json);
        if ($result === false) {
            echo "<h3>failed</h3>";
            continue 2;
            // skip remaining and renaming
        } else {
            echo "<h4>OK</h4>";
        }
    }
    // success on all lost records
    echo "<h3>done</h3>";
    rename($file, str_replace('/lost-', '/found-', str_replace('.json', '-' . date('YmdHis') . '.json', $file)));
}
echo "<h1>... done</h1>";
// TODO eliminate duplication from submit.php
function omnivore($json)
Example #2
0
// find the matching exercise...
foreach ($config->exercises as $exercise) {
    if ($exercise->id !== $student->id) {
        continue;
    }
    // ... score the exercise and exit
    $result = score_exercise($exercise, $student);
    $json = json_encode(array('result' => $result) + (array_key_exists('reveal', $_POST) || $result['correct'] ? array('exercise' => $exercise) : []));
    header('Content-Type: application/json');
    print $json;
    // done talking to the client
    //header('Content-Length: ' . ob_get_length());
    //ob_end_flush();
    // record submissions from logged-in users
    if ($username) {
        omnivore(COURSE, SEMESTER, $config, $username, $student, $result);
    }
    exit;
}
// ... no matching exercise
error('unknown exercise');
function handle_error($level, $message, $file, $line)
{
    if (error_reporting() === 0) {
        return false;
    }
    $description = "Handout exercise submit error ({$level})\n{$message}\nin {$file} on line {$line}";
    $context = print_r(array('session' => $_SESSION, 'post' => $_POST), true);
    @mail(OWNER, '[handx] Error report', "{$description}\n\n----\n\n{$context}");
    @log_error(array('message' => $message, 'file' => $file, 'line' => $line));
    return false;