Ejemplo n.º 1
0
    redirect($returnurl);
}
if ($id) {
    if (!($question = $DB->get_record('question', array('id' => $id)))) {
        print_error('questiondoesnotexist', 'question', $returnurl);
    }
    get_question_options($question, true);
} else {
    if ($categoryid && $qtype) {
        // only for creating new questions
        $question = new stdClass();
        $question->category = $categoryid;
        $question->qtype = $qtype;
        $question->createdby = $USER->id;
        // Check that users are allowed to create this question type at the moment.
        if (!question_bank::qtype_enabled($qtype)) {
            print_error('cannotenable', 'question', $returnurl, $qtype);
        }
    } else {
        if ($categoryid) {
            // Category, but no qtype. They probably came from the addquestion.php
            // script without choosing a question type. Send them back.
            $addurl = new moodle_url('/question/addquestion.php', $url->params());
            $addurl->param('validationerror', 1);
            redirect($addurl);
        } else {
            print_error('notenoughdatatoeditaquestion', 'question', $returnurl);
        }
    }
}
$qtypeobj = question_bank::get_qtype($question->qtype);