* 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
$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&id=$question->id&delete=$delete&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.
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") {
} 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&sesskey=$USER->sesskey&deleteselected=$questionlist&confirm=".md5($questionlist), "edit.php");
+ "edit.php?courseid=$course->id&sesskey=$USER->sesskey&deleteselected=$questionlist&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;