Example #1
0
        }
    }
    jsdie("questionSaved", $question->id, $is_new);
}
if ($is_new) {
    $title = "Новый вопрос";
    $question = new Question();
    $question->id = 'new';
    $question->test_id = $_REQUEST['test_id'];
    $question->wakeup();
    $answers = array();
} else {
    if (!($question = Question::get("WHERE id = %s", $id))) {
        redirect("/", "Извините, этот вопрос уже удален.");
    }
    $title = "{$question->text}";
    $answers = Answer::query("WHERE question_id = %s ORDER BY `order`", $question->id);
}
$max_answer_order = 0;
foreach ($answers as $answer) {
    $max_answer_order = max($max_answer_order, $answer->order);
}
$to_add = max(3, 5 - count($answers));
for ($i = 1; $i <= $to_add; $i++) {
    $answer = new Answer();
    $answer->order = $max_answer_order + $i;
    $answer->id = "new" . $i;
    $answer->wakeup();
    $answers[] = $answer;
}
echo render_partial('question_editor.haml', array('question' => $question, 'answers' => $answers));
Example #2
0
    include $test->handler_file();
    if (!function_exists('next_action')) {
        die("Invalid handler {$handler_file}: a handler must define function next_action(\$RES, \$question_count)");
    }
    // if the handler finishes the test right away, the statistics will end up incorrect
    $question = run_handler($RES, $test, null, null);
    $RES->session_id = stat_test_started($test->id, $RES->partner_id, $RES->day, $question->id, $RES->paid);
} else {
    if ($RES->finished) {
        if ($RES->paid) {
            if ($RES->sms_password_entered) {
                $full = true;
            } else {
                $full = false;
                ob_start();
                include 'templates/sms-info.inc.php';
                $sms_info = ob_get_clean();
            }
        } else {
            $full = true;
        }
        include $test->finisher_file();
        exit;
    } else {
        // we always pick a question by id in GET request, so that pressing F5 will render the same
        // question over and over again
        $question = Question::get("WHERE `id` = %d AND `test_id` = %d", $RES->question_id, $test_id);
    }
}
$answers = Answer::query("WHERE `question_id` = %d ORDER BY `order`", $question->id);
include $test->design_file();