Ejemplo n.º 1
0
$result['status'] = 1;
try {
    if (!isset($_POST['id']) || !isset($_POST['answer']) && !isset($_POST['status'])) {
        throw new UnexpectedValueException();
    }
    $id = (int) $_POST['id'];
    $answer = isset($_POST['answer']) ? (int) $_POST['answer'] : (int) $_POST['status'];
    if (isset($_POST['mw']) && $_POST['mw'] == 1) {
        require_once '../lib/lib_multiwords.php';
        check_permission(PERM_MULTITOKENS);
        MultiWordTask::register_answer($id, $_SESSION['user_id'], $answer);
    } else {
        if (isset($_POST['moder'])) {
            if (isset($_POST['status'])) {
                $result['status'] = save_moderated_status($id, $answer);
            } else {
                $result['status'] = save_moderated_answer($id, $answer, (int) $_POST['manual']);
            }
        } else {
            check_logged();
            update_annot_instance($id, $answer);
            $am = new AchievementsManager((int) $_SESSION['user_id']);
            $am->emit(EventTypes::TASK_DONE);
        }
    }
} catch (Exception $e) {
    $result['status'] = $e->getMessage();
    $result['error'] = 1;
}
log_timing(true);
die(json_encode($result));
Ejemplo n.º 2
0
function update_annot_instances($user_id, $answers)
{
    // $answers should be: array(array($instance_id, $answer), array($instance_id, $answer), ...)
    $accepted = 0;
    sql_begin();
    foreach ($answers as $a) {
        try {
            update_annot_instance($a[0], $a[1], $user_id);
            ++$accepted;
        } catch (Exception $e) {
            // currently do nothing
        }
    }
    sql_commit();
    return $accepted;
}