diff --git a/lang/en/quiz.php b/lang/en/quiz.php
index f57aad37680..be4f45f3d24 100644
--- a/lang/en/quiz.php
+++ b/lang/en/quiz.php
@@ -7,7 +7,7 @@ $string['addcategory'] = 'Add category';
$string['addingquestions'] = 'This side of the page is where you manage your database of questions. Questions are stored in categories to help you keep them organised, and can be used by any quiz in your course or even other courses if you choose to \'publish\' them.
After you select or create a question category you will be able to create or edit questions. You can select any of these questions to add to your quiz over on the other side of this page.';
$string['addquestions'] = 'Add questions';
$string['addquestionstoquiz'] = 'Add questions to current quiz';
-$string['addrandom1'] = ' Add ';
+$string['addrandom1'] = ' << Add ';
$string['addrandom2'] = 'random questions ';
$string['addselectedtoquiz'] = 'Add selected to quiz';
$string['addtoquiz'] = 'Add to quiz';
@@ -50,6 +50,7 @@ $string['categorydeleted'] = 'The category \'$a\' was deleted';
$string['categoryinfo'] = 'Category info';
$string['categorymove'] = 'The category \'$a->name\' contains $a->count questions. Please choose another category to move them to.';
$string['categorymoveto'] = 'Move them to this category';
+$string['categorynoedit'] = 'You do not have editing privileges in the category \'$a\'.';
$string['categoryupdated'] = 'The category was successfully updated';
$string['checkanswer'] = 'Check';
$string['choice'] = 'Choice';
@@ -84,6 +85,8 @@ $string['defaultgrade'] = 'Default question grade';
$string['defaultinfo'] = 'The default category for questions.';
$string['deleteattemptcheck'] = 'Are you absolutely sure you want to completely delete these attempts?';
$string['deletequestioncheck'] = 'Are you absolutely sure you want to delete \'$a\'?';
+$string['deletequestionscheck'] = 'Are you absolutely sure you want to delete the following questions?
$a
';
+$string['deleteselected'] = 'Delete selected';
$string['description'] = 'Description';
$string['discrimination'] = 'Discrim. Index';
$string['eachattemptbuildsonthelast'] = 'Each attempt builds on the last';
@@ -167,6 +170,7 @@ $string['missingquestiontext'] = 'Missing question text';
$string['missingword'] = 'Missing word format';
$string['modulename'] = 'Quiz';
$string['modulenameplural'] = 'Quizzes';
+$string['moveto'] = 'Move to >>';
$string['multianswer'] = 'Embedded Answers (Cloze)';
$string['multichoice'] = 'Multiple Choice';
$string['multiplier'] = 'Multiplier';
@@ -209,6 +213,7 @@ $string['questioninuse'] = 'The question \'$a->questionname\' is currently being
$string['questionname'] = 'Question name';
$string['questionnametoolong'] = 'Question name too long at line $a (255 char. max). It has been truncated.';
$string['questions'] = 'Questions';
+$string['questionsinuse'] = '(* Questions marked by an asterix are already in use in some quizzes. These question will not be deleted from these quizzes but only from the category list.)';
$string['questionsperpage'] = 'Max number of questions per page';
$string['questiontypesetupoptions'] = 'Setup options for question types:';
$string['quizavailable'] = 'The quiz is available until: $a';
@@ -263,6 +268,7 @@ $string['savequiz'] = 'Save this whole quiz';
$string['score'] = 'Raw score';
$string['select'] = 'Select';
$string['selectall'] = 'Select all';
+$string['selectnone'] = 'Deselect all';
$string['selectcategoryabove'] = 'Select a category above';
$string['shortanswer'] = 'Short Answer';
$string['show'] = 'Show';
diff --git a/lib/javascript-static.js b/lib/javascript-static.js
index 1e7a97e8199..674d79c35f7 100644
--- a/lib/javascript-static.js
+++ b/lib/javascript-static.js
@@ -23,6 +23,13 @@ function checkall() {
void(el[i].checked=1)
}
+function checknone() {
+ void(d=document);
+ void(el=d.getElementsByTagName('INPUT'));
+ for(i=0;icourse)) { // data submitted
$SESSION->modform = $modform; // Save the form in the current session
@@ -165,7 +168,25 @@
quiz_questiongrades_update($modform->grades, $modform->instance);
}
- if (isset($_REQUEST['delete']) and confirm_sesskey()) { /// Delete a question from the list
+ if (isset($_REQUEST['move']) and confirm_sesskey()) { /// Move selected questions to new category
+ if (!$tocategory = get_record('quiz_categories', 'id', $_REQUEST['category'])) {
+ error('Invalid category');
+ }
+ if (!isteacheredit($category->course)) {
+ error(get_string('categorynoedit', 'quiz', $tocategory->name), edit.php);
+ }
+ $rawquestions = $_POST;
+ foreach ($rawquestions as $key => $value) { // Parse input for question ids
+ if (substr($key, 0, 1) == "q") {
+ $key = substr($key,1);
+ if (!set_field('quiz_questions', 'category', $tocategory->id, 'id', $key)) {
+ error('Could not update category field');
+ }
+ }
+ }
+ }
+
+ if (isset($_REQUEST['delete']) and confirm_sesskey()) { /// Remove a question from the quiz
$questions = explode(",", $modform->questions);
foreach ($questions as $key => $question) {
if ($question == $delete) {
@@ -183,6 +204,70 @@
}
}
+ if (isset($_REQUEST['deleteselected'])) { // delete selected questions from the category
+
+ if (isset($confirm) and confirm_sesskey()) { // teacher has already confirmed the action
+ if ($confirm == md5($deleteselected)) {
+ if ($questionlist = explode(',', $deleteselected)) {
+ // for each question either hide it if it is in use or delete it
+ foreach ($questionlist as $questionid) {
+ if (record_exists('quiz_responses', 'question', $questionid) or
+ record_exists('quiz_responses', 'originalquestion', $questionid) or
+ record_exists('quiz_question_grades', 'question', $questionid)) {
+ if (!set_field('quiz_questions', 'hidden', 1, 'id', $questionid)) {
+ error('Was not able to hide question');
+ }
+ } else {
+ if (!delete_records("quiz_questions", "id", $questionid)) {
+ error("An error occurred trying to delete question (id $questionid)");
+ }
+ }
+ }
+ }
+ redirect("edit.php");
+ } else {
+ error("Confirmation string was incorrect");
+ }
+
+ } else { // teacher still has to confirm
+ // make a list of all the questions that are selected
+ $rawquestions = $_POST;
+ $questionlist = ''; // comma separated list of ids of questions to be deleted
+ $questionnames = ''; // string with names of questions separated by with
+ // an asterix in front of those that are in use
+ $inuse = false; // set to true if at least one of the questions is in use
+ foreach ($rawquestions as $key => $value) { // Parse input for question ids
+ if (substr($key, 0, 1) == "q") {
+ $key = substr($key,1);
+ $questionlist .= $key.',';
+ if (record_exists('quiz_responses', 'question', $key) or
+ record_exists('quiz_responses', 'originalquestion', $key) or
+ record_exists('quiz_question_grades', 'question', $key)) {
+ $questionnames .= '* ';
+ $inuse = true;
+ }
+ $questionnames .= get_field('quiz_questions', 'name', 'id', $key).' ';
+ }
+ }
+ if (!$questionlist) { // no questions were selected
+ redirect('edit.php');
+ }
+ $questionlist = rtrim($questionlist, ',');
+
+ // Add an explanation about questions in use
+ if ($inuse) {
+ $questionnames .= get_string('questionsinuse', 'quiz');
+ }
+ print_header_simple($strediting, '',
+ "id\">$strquizzes".
+ " -> $strediting");
+ notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames),
+ "edit.php?sesskey=$USER->sesskey&deleteselected=$questionlist&confirm=".md5($questionlist), "edit.php");
+ print_footer($course);
+ exit;
+ }
+ }
+
if (isset($_REQUEST['setgrades']) and confirm_sesskey()) { /// The grades have been updated, so update our internal list
$rawgrades = $_POST;
unset($modform->grades);
@@ -222,9 +307,6 @@
$SESSION->modform = $modform;
- $strquizzes = get_string('modulenameplural', 'quiz');
- $strediting = get_string('editquestions', "quiz");
-
// Print basic page layout.
if (isset($modform->instance) and record_exists_sql("SELECT * FROM {$CFG->prefix}quiz_attempts WHERE quiz = '$modform->instance' AND NOT (userid = '$USER->id') LIMIT 1")){
@@ -293,7 +375,7 @@
print_spacer(5,1);
// continues with list of questions
print_simple_box_start("center", "100%");
- quiz_print_cat_question_list($modform->category,
+ quiz_print_cat_question_list($course, $modform->category,
isset($modform->instance), $modform->recurse, $page, $perpage, $modform->showhidden);
print_simple_box_end();
if (!isset($modform->instance)) {
diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php
index ad4ced72f60..c9b0dc6e2c7 100644
--- a/mod/quiz/locallib.php
+++ b/mod/quiz/locallib.php
@@ -1321,7 +1321,7 @@ function quiz_print_question_list($questionlist, $grades, $allowdelete=true) {
}
-function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=1, $page, $perpage, $showhidden=false) {
+function quiz_print_cat_question_list($course, $categoryid, $quizselected=true, $recurse=1, $page, $perpage, $showhidden=false) {
// Prints the table of questions in a category with interactions
global $QUIZ_QUESTION_TYPE, $USER;
@@ -1334,9 +1334,11 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=
$strnoquestions = get_string("noquestions", "quiz");
$strselect = get_string("select", "quiz");
$strselectall = get_string("selectall", "quiz");
+ $strselectnone = get_string("selectnone", "quiz");
$strcreatenewquestion = get_string("createnewquestion", "quiz");
$strquestionname = get_string("questionname", "quiz");
$strdelete = get_string("delete");
+ $strdeleteselected = get_string("deleteselected", 'quiz');
$stredit = get_string("edit");
$straction = get_string("action");
$strrestore = get_string('restore');
@@ -1416,7 +1418,7 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=
echo "