Permalink
Browse files

Can now delete questions. It checks that the question doesn't belong to

any quizzes first (if it's in a published category then it checks all quizzes
on the server).
  • Loading branch information...
1 parent 34a4dfe commit e1c91df09b9dc71758fec06de2c4809faa9700ae moodler committed Oct 21, 2002
Showing with 50 additions and 6 deletions.
  1. +2 −0 lang/en/quiz.php
  2. +2 −3 mod/quiz/lib.php
  3. +43 −2 mod/quiz/question.php
  4. +3 −1 mod/quiz/report.php
View
@@ -36,6 +36,7 @@
$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['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";
View
@@ -19,8 +19,7 @@
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>";
View
@@ -43,15 +43,56 @@
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");
$streditingquestion = get_string("editingquestion", "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
View
@@ -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);

0 comments on commit e1c91df

Please sign in to comment.