diff --git a/lang/en_utf8/question.php b/lang/en_utf8/question.php index 2faedc712a2..2f87805d451 100644 --- a/lang/en_utf8/question.php +++ b/lang/en_utf8/question.php @@ -130,6 +130,7 @@ $string['movingquestionsnofiles']= 'Are you sure you want to move question(s) { $string['needtochoosecat'] = 'You need to choose a category to move this question to or press \'cancel\'.'; $string['nocate'] = 'No such category $a!'; $string['nopermissionadd'] = 'You don\'t have permission to add questions here.'; +$string['nopermissionmove'] = 'You don\'t have permission to move questions from here. You must save the question in this category or save it as a new question.'; $string['noprobs'] = 'No problems found in your question database.'; $string['notenoughdatatoeditaquestion'] = 'Neither a question id, nor a category id and question type, was specified.'; $string['notenoughdatatomovequestions'] = 'You need to provide the question ids of questions you want to move.'; diff --git a/question/type/edit_question_form.php b/question/type/edit_question_form.php index b3467609c7b..da1a155d325 100644 --- a/question/type/edit_question_form.php +++ b/question/type/edit_question_form.php @@ -219,6 +219,17 @@ class question_edit_form extends moodleform { $mform->hardFreezeAllVisibleExcept(array('categorymoveto', 'buttonar', 'currentgrp')); } } + + function validation($fromform, $files) { + $errors= parent::validation($fromform, $files); + if (empty($fromform->makecopy) && isset($this->question->id) + && ($this->question->formoptions->canedit || $this->question->formoptions->cansaveasnew) + && empty($fromform->usecurrentcat) && !$this->question->formoptions->canmove){ + $errors['currentgrp'] = get_string('nopermissionmove', 'question'); + } + return $errors; + } + /** * Add any question-type specific form fields. diff --git a/question/type/questiontype.php b/question/type/questiontype.php index 4e6acb78cfb..088057b6ac4 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -306,10 +306,11 @@ class default_questiontype { $question->defaultgrade = $form->defaultgrade; } - if (!empty($question->id)) { // Question already exists - if (isset($form->categorymoveto)){ + if (!empty($question->id) && !empty($form->categorymoveto)) { // Question already exists + list($movetocategory, $movetocontextid) = explode(',', $form->categorymoveto); + if ($movetocategory != $question->category){ question_require_capability_on($question, 'move'); - list($question->category, $movetocontextid) = explode(',', $form->categorymoveto); + $question->category = $movetocategory; //don't need to test add permission of category we are moving question to. //Only categories that we have permission to add //a question to will get through the form cleaning code for the select box. diff --git a/question/type/random/edit_random_form.php b/question/type/random/edit_random_form.php index 0433ae51579..9d0682d5d84 100644 --- a/question/type/random/edit_random_form.php +++ b/question/type/random/edit_random_form.php @@ -71,7 +71,11 @@ class question_edit_random_form extends question_edit_form { $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); } - + function validation($fromform, $files) { + //validation of category + //is not relevant for this question type + return array(); + } function qtype() { return 'random'; }