3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Action for processing page answers by users
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 /** Require the specific libraries */
27 require_once("../../config.php");
28 require_once($CFG->dirroot
.'/mod/lesson/locallib.php');
30 $id = required_param('id', PARAM_INT
);
32 $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST
);
33 $course = $DB->get_record('course', array('id' => $cm->course
), '*', MUST_EXIST
);
34 $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance
), '*', MUST_EXIST
), $cm, $course);
36 require_login($course, false, $cm);
40 $lesson->update_effective_access($USER->id
);
42 $context = $lesson->context
;
43 $canmanage = $lesson->can_manage();
44 $lessonoutput = $PAGE->get_renderer('mod_lesson');
46 $url = new moodle_url('/mod/lesson/continue.php', array('id'=>$cm->id
));
48 $PAGE->set_pagetype('mod-lesson-view');
49 $PAGE->navbar
->add(get_string('continue', 'lesson'));
51 // This is the code updates the lesson time for a timed test
52 // get time information for this user
54 $lesson->displayleft
= lesson_displayleftif($lesson);
55 $timer = $lesson->update_timer();
56 if (!$lesson->check_time($timer)) {
57 redirect(new moodle_url('/mod/lesson/view.php', array('id' => $cm->id
, 'pageid' => LESSON_EOL
, 'outoftime' => 'normal')));
58 die; // Shouldn't be reached, but make sure.
61 $timer = new stdClass
;
64 // record answer (if necessary) and show response (if none say if answer is correct or not)
65 $page = $lesson->load_page(required_param('pageid', PARAM_INT
));
67 $reviewmode = $lesson->is_in_review_mode();
69 // Process the page responses.
70 $result = $lesson->process_page_responses($page);
72 if ($result->nodefaultresponse ||
$result->inmediatejump
) {
73 // Don't display feedback or force a redirecto to newpageid.
74 redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id
,'pageid'=>$result->newpageid
)));
78 $lesson->add_messages_on_page_process($page, $result, $reviewmode);
79 $PAGE->set_secondary_active_tab('modulepage');
80 $PAGE->set_url('/mod/lesson/view.php', array('id' => $cm->id
, 'pageid' => $page->id
));
81 $PAGE->set_subpage($page->id
);
83 /// Print the header, heading and tabs
84 lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
85 echo $lessonoutput->header($lesson, $cm, 'view', true, $page->id
, get_string('continue', 'lesson'));
87 $editbuttons = new \mod_lesson\output\
edit_action_buttons($lesson, $page->id ??
null);
88 echo $lessonoutput->render($editbuttons);
90 if ($lesson->displayleft
) {
91 echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>';
93 // This calculates and prints the ongoing score message
94 if ($lesson->ongoing
&& !$reviewmode) {
95 echo $lessonoutput->ongoing_score($lesson);
98 echo format_text($result->feedback
, FORMAT_MOODLE
, array('context' => $context, 'noclean' => true));
101 // User is modifying attempts - save button and some instructions
102 if (isset($USER->modattempts
[$lesson->id
])) {
103 $content = $OUTPUT->box(get_string("gotoendoflesson", "lesson"), 'center');
104 $content .= $OUTPUT->box(get_string("or", "lesson"), 'center');
105 $content .= $OUTPUT->box(get_string("continuetonextpage", "lesson"), 'center');
106 $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id
, 'pageid' => LESSON_EOL
));
107 echo $content . $OUTPUT->single_button($url, get_string('finish', 'lesson'));
110 // Review button back
111 if (!$result->correctanswer
&& !$result->noanswer
&& !$result->isessayquestion
&& !$reviewmode && $lesson->review
&& !$result->maxattemptsreached
) {
112 $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id
, 'pageid' => $page->id
));
113 echo $OUTPUT->single_button($url, get_string('reviewquestionback', 'lesson'));
116 $url = new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id
, 'pageid'=>$result->newpageid
));
118 if ($lesson->review
&& !$result->correctanswer
&& !$result->noanswer
&& !$result->isessayquestion
&& !$result->maxattemptsreached
) {
119 // If both the "Yes, I'd like to try again" and "No, I just want to go on to the next question" point to the same
120 // page then don't show the "No, I just want to go on to the next question" button. It's confusing.
121 if ($page->id
!= $result->newpageid
) {
122 // Button to continue the lesson (the page to go is configured by the teacher).
123 echo $OUTPUT->single_button($url, get_string('reviewquestioncontinue', 'lesson'));
126 // Normal continue button
127 echo $OUTPUT->single_button($url, get_string('continue', 'lesson'));
130 echo $lessonoutput->footer();