';
@@ -215,7 +229,8 @@ function question_list($course, $categoryid, $quizid=0,
if ($canedit) {
echo "
$strcreatenewquestion: | ";
echo '
';
- popup_form ("$CFG->wwwroot/question/question.php?category=$category->id&qtype=", $qtypemenu, "addquestion",
+ $returnurl = urlencode($pageurl->out());
+ popup_form ("$CFG->wwwroot/question/question.php?returnurl=$returnurl&category=$category->id&qtype=", $qtypemenu, "addquestion",
"", "choose", "", "", false, "self");
echo ' | ';
helpbutton("questiontypes", $strcreatenewquestion, "quiz");
@@ -257,10 +272,10 @@ function question_list($course, $categoryid, $quizid=0,
print_paging_bar($totalnumber, $page, $perpage,
"edit.php?courseid={$course->id}&perpage=$perpage&");
- echo '\n";
}
+/**
+ * Shows the question bank editing interface.
+ *
+ * The function also processes a number of actions:
+ *
+ * Actions affecting the question pool:
+ * move Moves a question to a different category
+ * deleteselected Deletes the selected questions from the category
+ * Other actions:
+ * cat Chooses the category
+ * displayoptions Sets display options
+ *
+ * @author Martin Dougiamas and many others. This has recently been extensively
+ * rewritten by Gustav Delius and other members of the Serving Mathematics project
+ * {@link http://maths.york.ac.uk/serving_maths}
+ * @param moodle_url $pageurl object representing this pages url.
+ */
+function showbank($pageurl, $cm){
+ global $SESSION, $COURSE;
+ $page = optional_param('page', -1, PARAM_INT);
+ $perpage = optional_param('perpage', -1, PARAM_INT);
+ $sortorder = optional_param('sortorder', '');
+ if (preg_match("/[';]/", $sortorder)) {
+ error("Incorrect use of the parameter 'sortorder'");
+ }
+ if ($page > -1) {
+ $SESSION->questionpage = $page;
+ } else {
+ $page = isset($SESSION->questionpage) ? $SESSION->questionpage : 0;
+ }
+
+ if ($perpage > -1) {
+ $SESSION->questionperpage = $perpage;
+ } else {
+ $perpage = isset($SESSION->questionperpage) ? $SESSION->questionperpage : DEFAULT_QUESTIONS_PER_PAGE;
+ }
+
+ if ($sortorder) {
+ $SESSION->questionsortorder = $sortorder;
+ } else {
+ $sortorder = isset($SESSION->questionsortorder) ? $SESSION->questionsortorder : 'qtype, name ASC';
+ }
+ $SESSION->fromurl = $pageurl->out();
+
+/// Now, check for commands on this page and modify variables as necessary
+ if (isset($_REQUEST['move']) and confirm_sesskey()) { /// Move selected questions to new category
+ $tocategoryid = required_param('category', PARAM_INT);
+ if (!$tocategory = get_record('question_categories', 'id', $tocategoryid)) {
+ error('Invalid category');
+ }
+ if (!has_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSE, $tocategory->course))){
+ error(get_string('categorynoedit', 'quiz', $tocategory->name), $pageurl->out());
+ }
+ foreach ($_POST as $key => $value) { // Parse input for question ids
+ if (substr($key, 0, 1) == "q") {
+ $key = substr($key,1);
+ if (!set_field('question', 'category', $tocategory->id, 'id', $key)) {
+ error('Could not update category field');
+ }
+ }
+ }
+ }
+
+ if (isset($_REQUEST['deleteselected'])) { // delete selected questions from the category
+
+ if (isset($_REQUEST['confirm']) and confirm_sesskey()) { // teacher has already confirmed the action
+ $deleteselected = required_param('deleteselected');
+ if ($_REQUEST['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_question_instances', 'question', $questionid) or
+ record_exists('question_states', 'originalquestion', $questionid)) {
+ if (!set_field('question', 'hidden', 1, 'id', $questionid)) {
+ error('Was not able to hide question');
+ }
+ } else {
+ delete_question($questionid);
+ }
+ }
+ }
+ echo ' | ';
+ echo '';
+ echo '
';
+ redirect($pageurl->out());
+ } else {
+ error("Confirmation string was incorrect");
+ }
+
+ } else { // teacher still has to confirm
+ // make a list of all the questions that are selected
+ $rawquestions = $_REQUEST;
+ $questionlist = ''; // comma separated list of ids of questions to be deleted
+ $questionnames = ''; // string with names of questions separated by