diff --git a/mod/lesson/pagetypes/essay.php b/mod/lesson/pagetypes/essay.php
index b1c8136d024..c5fe1607d91 100644
--- a/mod/lesson/pagetypes/essay.php
+++ b/mod/lesson/pagetypes/essay.php
@@ -95,7 +95,12 @@ class lesson_page_type_essay extends lesson_page {
redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id, 'pageid'=>$this->properties->id)));
}
- $studentanswer = $data->answer['text'];
+ if (is_array($data->answer)) {
+ $studentanswer = $data->answer['text'];
+ } else {
+ $studentanswer = $data->answer;
+ }
+
if (trim($studentanswer) === '') {
$result->noanswer = true;
return $result;
@@ -261,8 +266,9 @@ class lesson_display_answer_form_essay extends moodleform {
if (isset($USER->modattempts[$lessonid]->useranswer) && !empty($USER->modattempts[$lessonid]->useranswer)) {
$attrs = array('disabled' => 'disabled');
$hasattempt = true;
- $useranswer = unserialize($USER->modattempts[$lessonid]->useranswer);
- $useranswer = htmlspecialchars_decode($useranswer->answer, ENT_QUOTES);
+ $useranswertemp = unserialize($USER->modattempts[$lessonid]->useranswer);
+ $useranswer = htmlspecialchars_decode($useranswertemp->answer, ENT_QUOTES);
+ $useranswerraw = $useranswertemp->answer;
}
}
@@ -282,7 +288,7 @@ class lesson_display_answer_form_essay extends moodleform {
if ($hasattempt) {
$mform->addElement('hidden', 'answer', $useranswerraw);
- $mform->setType('answer', PARAM_CLEANHTML);
+ $mform->setType('answer', PARAM_RAW);
$mform->addElement('html', $OUTPUT->container(get_string('youranswer', 'lesson'), 'youranswer'));
$mform->addElement('html', $OUTPUT->container($useranswer, 'reviewessay'));
$this->add_action_buttons(null, get_string("nextpage", "lesson"));
diff --git a/mod/lesson/pagetypes/multichoice.php b/mod/lesson/pagetypes/multichoice.php
index 078af8950be..3e666c5d2fd 100644
--- a/mod/lesson/pagetypes/multichoice.php
+++ b/mod/lesson/pagetypes/multichoice.php
@@ -542,6 +542,15 @@ class lesson_display_answer_form_multichoice_multianswer extends moodleform {
$mform->addElement('html', $OUTPUT->container($contents, 'contents'));
+ $hasattempt = false;
+ $disabled = '';
+ $useranswers = array();
+ if (isset($USER->modattempts[$lessonid]) && !empty($USER->modattempts[$lessonid])) {
+ $hasattempt = true;
+ $disabled = array('disabled' => 'disabled');
+ $useranswers = explode(',', $USER->modattempts[$lessonid]->useranswer);
+ }
+
$options = new stdClass;
$options->para = false;
$options->noclean = true;
@@ -554,16 +563,26 @@ class lesson_display_answer_form_multichoice_multianswer extends moodleform {
foreach ($answers as $answer) {
$mform->addElement('html', '
');
- // NOTE: our silly checkbox supports only value '1' - we can not use it like the radiobox above!!!!!!
- $mform->addElement('checkbox','answer['.$answer->id.']',null,format_text($answer->answer, $answer->answerformat, $options));
- $mform->setType('answer['.$answer->id.']', PARAM_INT);
- if (isset($USER->modattempts[$lessonid]) && $answer->id == $attempt->answerid) {
+ $answerid = 'answer['.$answer->id.']';
+ if ($hasattempt && in_array($answer->id, $useranswers)) {
+ $answerid = 'answer_'.$answer->id;
+ $mform->addElement('hidden', 'answer['.$answer->id.']', $answer->answer);
+ $mform->setType('answer['.$answer->id.']', PARAM_TEXT);
+ $mform->setDefault($answerid, true);
$mform->setDefault('answer['.$answer->id.']', true);
}
+ // NOTE: our silly checkbox supports only value '1' - we can not use it like the radiobox above!!!!!!
+ $mform->addElement('checkbox', $answerid, null, format_text($answer->answer, $answer->answerformat, $options), $disabled);
+ $mform->setType($answerid, PARAM_INT);
+
$mform->addElement('html', '
');
}
- $this->add_action_buttons(null, get_string("pleasecheckoneormoreanswers", "lesson"));
+ if ($hasattempt) {
+ $this->add_action_buttons(null, get_string("nextpage", "lesson"));
+ } else {
+ $this->add_action_buttons(null, get_string("submit", "lesson"));
+ }
}
}
diff --git a/mod/lesson/pagetypes/numerical.php b/mod/lesson/pagetypes/numerical.php
index 18fb54fa2c5..ee5b50fa9f9 100644
--- a/mod/lesson/pagetypes/numerical.php
+++ b/mod/lesson/pagetypes/numerical.php
@@ -50,7 +50,7 @@ class lesson_page_type_numerical extends lesson_page {
}
public function display($renderer, $attempt) {
global $USER, $CFG, $PAGE;
- $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents()));
+ $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents(), 'lessonid'=>$this->lesson->id));
$data = new stdClass;
$data->id = $PAGE->cm->id;
$data->pageid = $this->properties->id;
@@ -268,6 +268,15 @@ class lesson_display_answer_form_numerical extends moodleform {
$mform->addElement('html', $OUTPUT->container($contents, 'contents'));
+ $hasattempt = false;
+ $attrs = array('size'=>'50', 'maxlength'=>'200');
+ if (isset($this->_customdata['lessonid'])) {
+ $lessonid = $this->_customdata['lessonid'];
+ if (isset($USER->modattempts[$lessonid]->useranswer)) {
+ $attrs['readonly'] = 'readonly';
+ $hasattempt = true;
+ }
+ }
$options = new stdClass;
$options->para = false;
$options->noclean = true;
@@ -278,10 +287,14 @@ class lesson_display_answer_form_numerical extends moodleform {
$mform->addElement('hidden', 'pageid');
$mform->setType('pageid', PARAM_INT);
- $mform->addElement('text', 'answer', get_string('youranswer', 'lesson'), array('size'=>'50', 'maxlength'=>'200'));
+ $mform->addElement('text', 'answer', get_string('youranswer', 'lesson'), $attrs);
$mform->setType('answer', PARAM_FLOAT);
- $this->add_action_buttons(null, get_string("pleaseenteryouranswerinthebox", "lesson"));
+ if ($hasattempt) {
+ $this->add_action_buttons(null, get_string("nextpage", "lesson"));
+ } else {
+ $this->add_action_buttons(null, get_string("submit", "lesson"));
+ }
}
}