]> git.mjollnir.org Git - moodle.git/commitdiff
Can now delete questions. It checks that the question doesn't belong to
authormoodler <moodler>
Mon, 21 Oct 2002 15:00:51 +0000 (15:00 +0000)
committermoodler <moodler>
Mon, 21 Oct 2002 15:00:51 +0000 (15:00 +0000)
any quizzes first (if it's in a published category then it checks all quizzes
on the server).

lang/en/quiz.php
mod/quiz/lib.php
mod/quiz/question.php
mod/quiz/report.php

index 5acb098e58a8f31503acf293bfa512e3e91bdb34..8b33d6567b8121212637d95cf63a52b8efe481a7 100644 (file)
@@ -36,6 +36,7 @@ $string['createnewquestion'] = "Create new question";
 $string['daysavailable'] = "Days available";
 $string['default'] = "Default";
 $string['defaultinfo'] = "The default category for questions.";
+$string['deletequestioncheck'] = "Are you absolutely sure you want to delete '\$a'?";
 $string['editcategories'] = "Edit categories";
 $string['editingquiz'] = "Editing quiz";
 $string['editingquestion'] = "Editing a question";
@@ -59,6 +60,7 @@ $string['nomoreattempts'] = "No more attempts are allowed";
 $string['noquestions'] = "No questions have been added yet";
 $string['publish'] = "Publish";
 $string['question'] = "Question";
+$string['questioninuse'] = "The question '\$a' is currently being used:";
 $string['questions'] = "Questions";
 $string['questionname'] = "Question name";
 $string['quizavailable'] = "The quiz is available until: \$a";
index a829ea32b4da26322b6f06531186adb73c3c25b7..4c9e048cab8a206106fae4e4933d73a4c63874bb 100644 (file)
@@ -19,8 +19,7 @@ define("MULTICHOICE", "3");
 define("RANDOM",      "4");
 $QUIZ_QUESTION_TYPE = array ( MULTICHOICE => get_string("multichoice", "quiz"),
                               TRUEFALSE   => get_string("truefalse", "quiz"),
-                              SHORTANSWER => get_string("shortanswer", "quiz"),
-                              RANDOM      => get_string("random", "quiz") );
+                              SHORTANSWER => get_string("shortanswer", "quiz") );
 
 
 
@@ -672,7 +671,7 @@ function quiz_print_cat_question_list($categoryid) {
         echo "</TD>";
         if ($canedit) {
             echo "<TD>";
-                echo "<A TITLE=\"$strdelete\" HREF=\"question.php?delete=$question->id\"><IMG 
+                echo "<A TITLE=\"$strdelete\" HREF=\"question.php?id=$question->id&delete=$question->id\"><IMG 
                      SRC=\"../../pix/t/delete.gif\" BORDER=0></A>&nbsp;";
                 echo "<A TITLE=\"$stredit\" HREF=\"question.php?id=$question->id\"><IMG 
                      SRC=\"../../pix/t/edit.gif\" BORDER=0></A>";
index cf14679ae3c66cedee548eba2ee65e1372070891..aa97b2ad716ddad620fb3584948d00ed3b9b0133 100644 (file)
@@ -43,7 +43,7 @@
     require_login($course->id);
 
     if (!isteacher($course->id)) {
-        error("You can't modify this course!");
+        error("You can't modify these questions!");
     }
 
     $streditingquiz = get_string("editingquiz", "quiz");
 
     print_header("$course->shortname: $streditingquestion", "$course->shortname: $streditingquestion",
                  "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> 
-                   -> <A HREF=\"$HTTP_REFERER\">$streditingquiz</A> -> $streditingquestion");
+                  -> <A HREF=\"$HTTP_REFERER\">$streditingquiz</A> -> $streditingquestion");
+
+    if (isset($delete)) {
+        if (isset($confirm)) {
+            if ($confirm == md5($delete)) {
+                if (!delete_records("quiz_questions", "id", $question->id)) {
+                    error("An error occurred trying to delete question (id $question->id)");
+                }
+                redirect("edit.php");
+            } else {
+                error("Confirmation string was incorrect");
+            }
+            
+        } else {
+            if ($category->publish) {
+                $quizzes = get_records_sql("SELECT * FROM quiz");
+            } else {
+                $quizzes = get_records("quiz", "course", $course->id);
+            }
+            $beingused = array();
+            if ($quizzes) {
+                foreach ($quizzes as $quiz) {
+                    $qqq = explode(",", $quiz->questions);
+                    foreach ($qqq as $key => $value) {
+                        if ($value == $delete) {
+                            $beingused[] = $quiz->name;
+                        }
+                    }
+                }
+            }
+            if ($beingused) {
+                $beingused = implode(", ", $beingused);
+                $beingused = get_string("questioninuse", "quiz", "<I>$question->name</I>")."<P>".$beingused;
+                notice($beingused, "edit.php");
+            } else {
+                notice_yesno(get_string("deletequestioncheck", "quiz", $question->name), 
+                            "question.php?id=$question->id&delete=$delete&confirm=".md5($delete), "edit.php");
+            }
+            print_footer($course);
+            exit;
+        }
+    }
 
     if (match_referer() and isset($HTTP_POST_VARS)) {    // question submitted
 
index e7116106ebefd86730c561015d2490ed748484de..0663559afbe96939d8f642289cb926c2c440b19f 100644 (file)
@@ -8,6 +8,8 @@
     optional_variable($id);    // Course Module ID, or
     optional_variable($q);     // quiz ID
 
+    optional_variable($attempt);     // A particular attempt ID
+
     if ($id) {
         if (! $cm = get_record("course_modules", "id", $id)) {
             error("Course Module ID was incorrect");
@@ -79,7 +81,7 @@
 
         $table->data[] = array ($picture, 
                                 "<A HREF=\"$CFG->wwwroot/user/view.php?id=$grade->user&course=$course->id\">$grade->firstname $grade->lastname</A>", 
-                                "$userattempts", $grade->grade);
+                                "$userattempts", round($grade->grade,0));
     }
 
     print_table($table);