Now can add a single question to quiz with a single click.

This commit is contained in:
gustav_delius 2005-03-05 12:55:26 +00:00
parent 3bab9f2a04
commit fef9b51dac
3 changed files with 45 additions and 17 deletions

View File

@ -10,6 +10,7 @@ $string['addquestionstoquiz'] = 'Add questions to current quiz';
$string['addrandom1'] = ' Add ';
$string['addrandom2'] = 'random questions ';
$string['addselectedtoquiz'] = 'Add selected to quiz';
$string['addtoquiz'] = 'Add to quiz';
$string['affectedstudents'] = 'Affected $a';
$string['aiken'] = 'Aiken format';
$string['allinone'] = 'Unlimited';

View File

@ -101,7 +101,32 @@
}
}
if (isset($_REQUEST['add']) and confirm_sesskey()) { /// Add a question to the current quiz
if (isset($_REQUEST['addquestion']) and confirm_sesskey()) { /// Add a single question to the current quiz
// add question to quiz->questions
$key = $_REQUEST['addquestion'];
if (!empty($modform->questions)) {
$questions = explode(",", $modform->questions);
}
$questions[] = $key;
$modform->questions = implode(",", $questions);
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) {
error('Could not save question list');
}
// update question grades
$questionrecord = get_record("quiz_questions", "id", $key);
if (!empty($questionrecord->defaultgrade)) {
$modform->grades[$key] = $questionrecord->defaultgrade;
} else if ($questionrecord->qtype == DESCRIPTION){
$modform->grades[$key] = 0;
} else {
$modform->grades[$key] = 1;
}
quiz_questiongrades_update($modform->grades, $modform->instance);
}
if (isset($_REQUEST['add']) and confirm_sesskey()) { /// Add selected questions to the current quiz
$rawquestions = $_POST;
if (!empty($modform->questions)) {
$questions = explode(",", $modform->questions);

View File

@ -1338,8 +1338,10 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=
$strquestionname = get_string("questionname", "quiz");
$strdelete = get_string("delete");
$stredit = get_string("edit");
$straction = get_string("action");
$straddselectedtoquiz = get_string("addselectedtoquiz", "quiz");
$straddtoquiz = get_string("addtoquiz", "quiz");
$strtype = get_string("type", "quiz");
$strcreatemultiple = get_string("createmultiple", "quiz");
$strpreview = get_string("preview","quiz");
@ -1412,32 +1414,22 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\">";
echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" width=\"100%\">";
echo "<tr>";
if ($quizselected) {
echo "<th width=\"*\" nowrap=\"nowrap\">$strselect</th>";
if ($canedit) {
echo "<th width=\"105\" nowrap=\"nowrap\">$straction</th>";
}
echo "<th width=\"100%\" align=\"left\" nowrap=\"nowrap\">$strquestionname</th><th width=\"*\" nowrap=\"nowrap\">$strtype</th>";
if ($canedit) {
echo "<th width=\"70\" nowrap=\"nowrap\">$stredit</th>";
}
echo "</tr>\n";
foreach ($questions as $question) {
if ($question->qtype == RANDOM) {
//continue;
}
echo "<tr>\n";
if ($quizselected) {
echo "<td align=\"center\">";
echo "<input type=\"checkbox\" name=\"q$question->id\" value=\"1\" />\n";
echo "</td>";
}
echo "<td>".$question->name."</td>\n";
echo "<td align=\"center\">\n";
quiz_print_question_icon($question, $canedit);
echo "</td>\n";
if ($canedit) {
echo "<td>\n";
echo "<a title=\"$strdelete\" href=\"question.php?id=$question->id&amp;delete=$question->id\">\n<img
src=\"../../pix/t/delete.gif\" border=\"0\" alt=\"$strdelete\" /></a>&nbsp;";
if ($quizselected) {
echo "<a title=\"$straddtoquiz\" href=\"edit.php?addquestion=$question->id&amp;sesskey=$USER->sesskey\"><img
src=\"../../pix/t/moveleft.gif\" border=\"0\" alt=\"$straddtoquiz\" /></a>&nbsp;";
}
echo "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/mod/quiz/preview.php?id=$question->id','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\"><img
src=\"../../pix/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>&nbsp;";
echo "<a title=\"$stredit\" href=\"question.php?id=$question->id\"><img
@ -1454,8 +1446,18 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=
}
echo "<a title=\"$strhideshow\" href=\"question.php?id=$question->id&amp;hide=$hideshow&amp;sesskey=$USER->sesskey\"><img
src=\"../../pix/t/$imghideshow\" border=\"0\" alt=\"$strhideshow\" /></a>";
echo "<a title=\"$strdelete\" href=\"question.php?id=$question->id&amp;delete=$question->id\">\n<img
src=\"../../pix/t/delete.gif\" border=\"0\" alt=\"$strdelete\" /></a>";
if ($quizselected) {
echo "&nbsp;<input title=\"$strselect\" type=\"checkbox\" name=\"q$question->id\" value=\"1\" />";
}
echo "</td>\n";
}
echo "<td>".$question->name."</td>\n";
echo "<td align=\"center\">\n";
quiz_print_question_icon($question, $canedit);
echo "</td>\n";
echo "</tr>\n";
}
$numquestions = count_records_select('quiz_questions', "category IN ($categorylist) AND qtype != '".RANDOM."'");