$qtypenames= get_list_of_plugins('mod/quiz/questiontypes');
foreach($qtypenames as $qtypename) {
// Instanciates all plug-in question types
- $qtypefilepath= "questiontypes/$qtypename/questiontype.php";
+ $qtypefilepath= "$CFG->dirroot/mod/quiz/questiontypes/$qtypename/questiontype.php";
// echo "Loading $qtypename<br/>"; // Uncomment for debugging
if (is_readable($qtypefilepath)) {
error("Must specify question id or category");
}
+ if (empty($qtype)) {
+ error("No question type was specified!");
+ } else if (!isset($QUIZ_QTYPES[$qtype])) {
+ error("Could not find question type: '$qtype'");
+ }
+
require_login($course->id);
if (!isteacheredit($course->id)) {
}
if ($form = data_submitted()) {
- $question = $QUIZ_QTYPES[$qtype]->save_question($question,
- $form, $course);
+ $question = $QUIZ_QTYPES[$qtype]->save_question($question, $form, $course);
}
$grades = array(1,0.9,0.8,0.75,0.70,0.66666,0.60,0.50,0.40,0.33333,0.30,0.25,0.20,0.16666,0.10,0.05,0);
// Set up some Richtext editing if necessary
if ($usehtmleditor = can_use_richtext_editor()) {
$defaultformat = FORMAT_HTML;
- $onsubmit = "onsubmit=\"copyrichtext(theform.questiontext);\"";
} else {
$defaultformat = FORMAT_MOODLE;
- $onsubmit = "";
}
+ echo '<script lang="Javascript">';
+ echo 'function validatequestion() {';
+ echo ' if (document.theform.name.value == "") {';
+ echo ' alert("'.get_string('specifyname').'");';
+ echo ' focus(document.theform.name.value);';
+ echo ' return false;';
+ echo ' } else {';
+ echo ' return true; ';
+ echo ' }';
+ echo '}';
+ echo '</script>'."\n\n";
+
+ $onsubmit = ' onSubmit="return validatequestion();" ';
+
require('questiontypes/'.$QUIZ_QTYPES[$qtype]->name().'/editquestion.php');
+ if ($usehtmleditor) {
+ use_html_editor('questiontext');
+ }
+
print_footer($course);
\r
print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
\r
- if ($usehtmleditor) { /// Trying this out for a while\r
+ if ($usehtmleditor) {\r
echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
} else {\r
echo "<div align=right>";\r
\r
</CENTER>\r
</FORM>\r
-<?php \r
- if ($usehtmleditor) { \r
- print_richedit_javascript("theform", "questiontext", "no");\r
- }\r
-?>\r
<?PHP // $Id$
- print_heading_with_help(get_string("editingdescription", "quiz"), "description", "quiz");
- require("description.html");
+ print_heading_with_help(get_string("editingdescription", "quiz"), "description", "quiz");
+ require("description.html");
?>
<?PHP // $Id$
- if (!empty($question->id)) {
- $options = get_record("quiz_match", "question", $question->id);
- if (!empty($options->subquestions)) {
- $oldsubquestions = get_records_list("quiz_match_sub", "id", $options->subquestions);
- }
- }
- if (empty($subquestions) and empty($subanswers)) {
- for ($i=0; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
- $subquestions[] = ""; // Make question slots, default as blank
- $subanswers[] = ""; // Make answer slots, default as blank
- }
- if (!empty($oldsubquestions)) {
- $i=0;
- foreach ($oldsubquestions as $oldsubquestion) {
- $subquestions[$i] = $oldsubquestion->questiontext; // insert questions into slots
- $subanswers[$i] = $oldsubquestion->answertext; // insert answers into slots
- $i++;
- }
- }
+
+ if (!empty($question->id)) {
+ $options = get_record("quiz_match", "question", $question->id);
+ if (!empty($options->subquestions)) {
+ $oldsubquestions = get_records_list("quiz_match_sub", "id", $options->subquestions);
+ }
+ }
+ if (empty($subquestions) and empty($subanswers)) {
+ for ($i=0; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
+ $subquestions[] = ""; // Make question slots, default as blank
+ $subanswers[] = ""; // Make answer slots, default as blank
+ }
+ if (!empty($oldsubquestions)) {
+ $i=0;
+ foreach ($oldsubquestions as $oldsubquestion) {
+ $subquestions[$i] = $oldsubquestion->questiontext; // insert questions into slots
+ $subanswers[$i] = $oldsubquestion->answertext; // insert answers into slots
+ $i++;
}
- print_heading_with_help(get_string("editingmatch", "quiz"), "match", "quiz");
- require("match.html");
+ }
+ }
+ print_heading_with_help(get_string("editingmatch", "quiz"), "match", "quiz");
+ require("match.html");
?>
\r
print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
\r
- if ($usehtmleditor) { /// Trying this out for a while\r
+ if ($usehtmleditor) { \r
echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
} else {\r
echo "<div align=right>";\r
\r
</CENTER>\r
</FORM>\r
-<?php \r
- if ($usehtmleditor) { \r
- print_richedit_javascript("theform", "questiontext", "no");\r
- }\r
-?>\r
</CENTER>
</FORM>
-
-<?php
-
- if ($usehtmleditor) {
-
- print_richedit_javascript("theform", "questiontext", "no");
-
- }
-
-?>
-
-<?PHP // $Id$
- if (!empty($question->id)) {
- $options = get_record("quiz_multichoice", "question", $question->id);
- } else {
- $options->single = 1;
- }
- if (!empty($options->answers)) {
- $answersraw = get_records_list("quiz_answers", "id", $options->answers);
- }
- for ($i=0; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
- $answers[] = ""; // Make answer slots, default as blank
- }
- if (!empty($answersraw)) {
- $i=0;
- foreach ($answersraw as $answer) {
- $answers[$i] = $answer; // insert answers into slots
- $i++;
- }
- }
- print_heading_with_help(get_string("editingmultichoice", "quiz"), "multichoice", "quiz");
- require("multichoice.html");
+<?php // $Id$
+
+ if (!empty($question->id)) {
+ $options = get_record("quiz_multichoice", "question", $question->id);
+ } else {
+ $options->single = 1;
+ }
+ if (!empty($options->answers)) {
+ $answersraw = get_records_list("quiz_answers", "id", $options->answers);
+ }
+ for ($i=0; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
+ $answers[] = ""; // Make answer slots, default as blank
+ }
+ if (!empty($answersraw)) {
+ $i=0;
+ foreach ($answersraw as $answer) {
+ $answers[$i] = $answer; // insert answers into slots
+ $i++;
+ }
+ }
+ print_heading_with_help(get_string("editingmultichoice", "quiz"), "multichoice", "quiz");
+ require("multichoice.html");
?>
\r
print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
\r
- if ($usehtmleditor) { /// Trying this out for a while\r
+ if ($usehtmleditor) {\r
echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
} else {\r
echo "<div align=right>";\r
\r
</CENTER>\r
</FORM>\r
-<?php \r
- if ($usehtmleditor) { \r
- print_richedit_javascript("theform", "questiontext", "no");\r
- }\r
-?>\r
<?PHP // $Id$
- // This will only support one answer of the type NUMERICAL
- // However, lib.php has support for multiple answers
- if (!empty($question->id)) {
- $answersraw= quiz_get_answers($question);
- }
- $answers= array();
- for ($i=0; $i<6; $i++) {
- $answers[$i]->answer = ""; // Make answer slots, default as blank...
- $answers[$i]->min = "";
- $answers[$i]->max = "";
- $answers[$i]->feedback = "";
- }
- if (!empty($answersraw)) {
- $i=0;
- foreach ($answersraw as $answer) {
- $answers[$i] = $answer;
- $i++;
- }
- }
- print_heading_with_help(get_string("editingnumerical", "quiz"), "numerical", "quiz");
- require("numerical.html");
+ // This will only support one answer of the type NUMERICAL
+ // However, lib.php has support for multiple answers
+ if (!empty($question->id)) {
+ $answersraw= quiz_get_answers($question);
+ }
+ $answers= array();
+ for ($i=0; $i<6; $i++) {
+ $answers[$i]->answer = ""; // Make answer slots, default as blank...
+ $answers[$i]->min = "";
+ $answers[$i]->max = "";
+ $answers[$i]->feedback = "";
+ }
+ if (!empty($answersraw)) {
+ $i=0;
+ foreach ($answersraw as $answer) {
+ $answers[$i] = $answer;
+ $i++;
+ }
+ }
+ print_heading_with_help(get_string("editingnumerical", "quiz"), "numerical", "quiz");
+ require("numerical.html");
?>
print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);
- if ($usehtmleditor) { /// Trying this out for a while
+ if ($usehtmleditor) {
echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';
} else {
echo "<div align=right>";
}
}
</SCRIPT>
-<?php
- if ($usehtmleditor) {
- print_richedit_javascript("theform", "questiontext", "no");
- }
-?>
-
<?PHP // $Id$
- print_heading_with_help(get_string("editingrandom", "quiz"), "random", "quiz");
- require("random.html");
+ print_heading_with_help(get_string("editingrandom", "quiz"), "random", "quiz");
+ require("random.html");
?>
<center>\r
-<form name="theform" method="post" action="question.php">\r
+<form name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
\r
<table cellpadding=5>\r
<tr valign=top>\r
<?PHP // $Id$
- if (!empty($question->id)) {
- $options = get_record("quiz_randomsamatch", "question", $question->id);
- } else {
- $options->choose = "";
- }
- $numberavailable = count_records("quiz_questions", "category", $category->id, "qtype", SHORTANSWER);
- print_heading_with_help(get_string("editingrandomsamatch", "quiz"), "randomsamatch", "quiz");
- require("randomsamatch.html");
+ if (!empty($question->id)) {
+ $options = get_record("quiz_randomsamatch", "question", $question->id);
+ } else {
+ $options->choose = "";
+ }
+ $numberavailable = count_records("quiz_questions", "category", $category->id, "qtype", SHORTANSWER);
+ print_heading_with_help(get_string("editingrandomsamatch", "quiz"), "randomsamatch", "quiz");
+ require("randomsamatch.html");
?>
}\r
print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
\r
- if ($usehtmleditor) { /// Trying this out for a while\r
+ if ($usehtmleditor) {\r
echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
} else {\r
echo "<div align=right>";\r
\r
</CENTER>\r
</FORM>\r
-<?php \r
- if ($usehtmleditor) { \r
- print_richedit_javascript("theform", "questiontext", "no");\r
- }\r
-?>\r
<?PHP // $Id$
- if (!empty($question->id)) {
- $options = get_record("quiz_shortanswer", "question", $question->id);
- } else {
- $options->usecase = 0;
- }
- if (!empty($options->answers)) {
- $answersraw = get_records_list("quiz_answers", "id", $options->answers);
- }
- for ($i=0; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
- $answers[] = ""; // Make answer slots, default as blank
- }
- if (!empty($answersraw)) {
- $i=0;
- foreach ($answersraw as $answer) {
- $answers[$i] = $answer; // insert answers into slots
- $i++;
- }
- }
- print_heading_with_help(get_string("editingshortanswer", "quiz"), "shortanswer", "quiz");
- require("shortanswer.html");
+ if (!empty($question->id)) {
+ $options = get_record("quiz_shortanswer", "question", $question->id);
+ } else {
+ $options->usecase = 0;
+ }
+ if (!empty($options->answers)) {
+ $answersraw = get_records_list("quiz_answers", "id", $options->answers);
+ }
+ for ($i=0; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
+ $answers[] = ""; // Make answer slots, default as blank
+ }
+ if (!empty($answersraw)) {
+ $i=0;
+ foreach ($answersraw as $answer) {
+ $answers[$i] = $answer; // insert answers into slots
+ $i++;
+ }
+ }
+ print_heading_with_help(get_string("editingshortanswer", "quiz"), "shortanswer", "quiz");
+ require("shortanswer.html");
?>
\r
print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
\r
- if ($usehtmleditor) { /// Trying this out for a while\r
+ if ($usehtmleditor) {\r
echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
} else {\r
echo "<div align=right>";\r
\r
</CENTER>\r
</FORM>\r
-<?php \r
- if ($usehtmleditor) { \r
- print_richedit_javascript("theform", "questiontext", "no");\r
- }\r
-?>\r
<?PHP // $Id$
- if (!empty($question->id)) {
- $options = get_record("quiz_truefalse", "question", "$question->id");
- }
- if (!empty($options->trueanswer)) {
- $true = get_record("quiz_answers", "id", $options->trueanswer);
- } else {
- $true->fraction = 1;
- $true->feedback = "";
- }
- if (!empty($options->falseanswer)) {
- $false = get_record("quiz_answers", "id", "$options->falseanswer");
- } else {
- $false->fraction = 0;
- $false->feedback = "";
- }
+ if (!empty($question->id)) {
+ $options = get_record("quiz_truefalse", "question", "$question->id");
+ }
+ if (!empty($options->trueanswer)) {
+ $true = get_record("quiz_answers", "id", $options->trueanswer);
+ } else {
+ $true->fraction = 1;
+ $true->feedback = "";
+ }
+ if (!empty($options->falseanswer)) {
+ $false = get_record("quiz_answers", "id", "$options->falseanswer");
+ } else {
+ $false->fraction = 0;
+ $false->feedback = "";
+ }
- if ($true->fraction > $false->fraction) {
- $question->answer = 1;
- } else {
- $question->answer = 0;
- }
+ if ($true->fraction > $false->fraction) {
+ $question->answer = 1;
+ } else {
+ $question->answer = 0;
+ }
- print_heading_with_help(get_string("editingtruefalse", "quiz"), "truefalse", "quiz");
- require("truefalse.html");
+ print_heading_with_help(get_string("editingtruefalse", "quiz"), "truefalse", "quiz");
+ require("truefalse.html");
?>
\r
print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
\r
- if ($usehtmleditor) { /// Trying this out for a while\r
+ if ($usehtmleditor) { \r
echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
} else {\r
echo "<div align=right>";\r
\r
</CENTER>\r
</FORM>\r
-<?php \r
- if ($usehtmleditor) { \r
- print_richedit_javascript("theform", "questiontext", "no");\r
- }\r
-?>\r