]> git.mjollnir.org Git - moodle.git/commitdiff
Moved all question deletion code to showbank.php. Fixed bug 5186
authorgustav_delius <gustav_delius>
Mon, 17 Apr 2006 05:31:21 +0000 (05:31 +0000)
committergustav_delius <gustav_delius>
Mon, 17 Apr 2006 05:31:21 +0000 (05:31 +0000)
question/editlib.php
question/question.php
question/showbank.php

index d8790e0a5b057d463442f3bd73b6e216c0dc0741..dd8afaac9f9337930af9d365327acee40063714e 100644 (file)
@@ -227,10 +227,10 @@ function question_list($course, $categoryid, $quizid=0,
                  src=\"$CFG->pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a>&nbsp;";
             // hide-feature
             if($question->hidden) {
-                echo "<a title=\"$strrestore\" href=\"$CFG->wwwroot/question/question.php?id=$question->id&amp;hide=0&amp;sesskey=$USER->sesskey\"><img
+                echo "<a title=\"$strrestore\" href=\"edit.php?courseid=$course->id&amp;unhide=$question->id&amp;sesskey=$USER->sesskey\"><img
                      src=\"$CFG->pixpath/t/restore.gif\" border=\"0\" alt=\"$strrestore\" /></a>";
             } else {
-                echo "<a title=\"$strdelete\" href=\"$CFG->wwwroot/question/question.php?id=$question->id&amp;delete=$question->id\"><img
+                echo "<a title=\"$strdelete\" href=\"edit.php?courseid=$course->id&amp;deleteselected=$question->id&amp;q$question->id=1\"><img
                      src=\"$CFG->pixpath/t/delete.gif\" border=\"0\" alt=\"$strdelete\" /></a>";
             }
         }
index 514ae770c30f247db52635f7b5949febd6184c76..87e649cfdc0be990d076fbd5e97097c671e1fbf4 100644 (file)
@@ -5,14 +5,10 @@
 * This page shows the question editing form or processes the following actions:
 * - create new question (category, qtype)
 * - edit question (id, contextquiz (optional))
-* - delete question from quiz (delete, sesskey)
-* - delete question (in two steps)
-*   - if question is in use: display this conflict (allow to hide the question?)
-*   - else: confirm deletion and delete from database (sesskey, id, delete, confirm)
 * - cancel (cancel)
 *
-* TODO: currently this still treats the quiz as special, for example it sometimes redirects
-*       to mod/quiz/edit.php.
+* TODO: currently this still treats the quiz as special
+* TODO: question versioning is not currently enabled
 *
 * @version $Id$
 * @author Martin Dougiamas and many others. This has recently been extensively
@@ -30,9 +26,6 @@
 
     $qtype = optional_param('qtype', '', PARAM_FILE);
     $category = optional_param('category', 0, PARAM_INT);
-    
-    $delete = optional_param('delete',  0, PARAM_INT);
-    $confirm = optional_param('confirm',  0, PARAM_ALPHANUM);
 
     // rqp questions set the type to rqp_nn where nn is the rqp_type id
     if (substr($qtype, 0, 4) == 'rqp_') {
         redirect($SESSION->returnurl);
     }
 
-    if(!empty($id) && isset($_REQUEST['hide']) && confirm_sesskey()) {
-        $hide = required_param('hide', PARAM_INT);
-        if(!set_field('question', 'hidden', $hide, 'id', $id)) {
-            error("Faild to hide the question.");
-        }
-        redirect($SESSION->returnurl);
-    }
-
     if (empty($qtype)) {
         error("No question type was specified!");
     } else if (!isset($QTYPES[$qtype])) {
 
     print_header_simple("$streditingquestion", "", $strediting);
 
-    if ($delete) {
-        if ($confirm and confirm_sesskey()) {
-            if ($confirm == md5($delete)) {
-                if (record_exists('quiz_question_instances', 'question', $question->id) or
-                    record_exists('question_states', 'originalquestion', $question->id)) {
-                    if (!set_field('question', 'hidden', 1, 'id', $delete)) {
-                        error('Was not able to hide question');
-                    }
-                } else {
-                    if (!delete_records("question", "id", $question->id)) {
-                        error("An error occurred trying to delete question (id $question->id)");
-                    }
-                    if (!delete_records("question", "parent", $question->id)) {
-                        error("An error occurred trying to delete question (id $question->id)");
-                    }
-                }
-                redirect($SESSION->returnurl);
-            } else {
-                error("Confirmation string was incorrect");
-            }
-
-        } else {
-            // TODO: check for other modules using this question
-            if ($quiznames = question_list_instances($id)) {
-                $a->questionname = $question->name;
-                $a->quiznames = implode(', ', $quiznames);
-                notify(get_string('questioninuse', 'quiz', $a));
-            }
-
-            notice_yesno(get_string("deletequestioncheck", "quiz", $question->name),
-                        "question.php?sesskey=$USER->sesskey&amp;id=$question->id&amp;delete=$delete&amp;confirm=".md5($delete), $SESSION->returnurl);
-        }
-        print_footer($course);
-        exit;
-    }
-
     if ($form = data_submitted() and confirm_sesskey()) {
 
         if (isset($form->versioning) && isset($question->id) and false) { // disable versioning until it is fixed.
index 6aa27b86db45d43b7a580a7d95711ef4614ddd4f..3ffcafdc61897fb61f77f5b74103d2e55a91bc7d 100644 (file)
@@ -44,7 +44,7 @@
             error('Invalid category');
         }
         if (!isteacheredit($tocategory->course)) {
-            error(get_string('categorynoedit', 'quiz', $tocategory->name), 'edit.php');
+            error(get_string('categorynoedit', 'quiz', $tocategory->name), 'edit.php?courseid=$course->id');
         }
         foreach ($_POST as $key => $value) {    // Parse input for question ids
             if (substr($key, 0, 1) == "q") {
@@ -81,7 +81,7 @@
 
         } else { // teacher still has to confirm
             // make a list of all the questions that are selected
-            $rawquestions = $_POST;
+            $rawquestions = $_REQUEST;
             $questionlist = '';  // comma separated list of ids of questions to be deleted
             $questionnames = ''; // string with names of questions separated by <br /> with
                                  // an asterix in front of those that are in use
             if ($inuse) {
                 $questionnames .= get_string('questionsinuse', 'quiz');
             }
-            print_header_simple($streditingquestions, '',
-                 "$streditingquestions");
             notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames),
-                        "edit.php?courseid=$course->id&amp;sesskey=$USER->sesskey&amp;deleteselected=$questionlist&amp;confirm=".md5($questionlist), "edit.php");
+                        "edit.php?courseid=$course->id&amp;sesskey=$USER->sesskey&amp;deleteselected=$questionlist&amp;confirm=".md5($questionlist), "edit.php?courseid=$course->id");
             print_footer($course);
             exit;
         }
     }
 
+    // Unhide a question
+    if(isset($_REQUEST['unhide']) && confirm_sesskey()) {
+        $unhide = required_param('unhide', PARAM_INT);
+        if(!set_field('question', 'hidden', 0, 'id', $unhide)) {
+            error("Failed to unhide the question.");
+        }
+        redirect("edit.php?courseid=$course->id");
+    }
+
     if (isset($_REQUEST['cat'])) { /// coming from category selection drop-down menu
         $SESSION->questioncat = required_param('cat', PARAM_INT);
         $page = 0;