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).
This commit is contained in:
@@ -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";
|
||||
|
||||
+2
-3
@@ -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> ";
|
||||
echo "<A TITLE=\"$stredit\" HREF=\"question.php?id=$question->id\"><IMG
|
||||
SRC=\"../../pix/t/edit.gif\" BORDER=0></A>";
|
||||
|
||||
+43
-2
@@ -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");
|
||||
@@ -51,7 +51,48 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
+3
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user