Merge branch 'MDL-76857-39' of https://github.com/sarjona/moodle into MOODLE_39_STABLE
[moodle.git] / mod / lesson / continue.php
blobf69fd05f42bc2fe6176205d8113eef90ef20b760
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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/>.
18 /**
19 * Action for processing page answers by users
21 * @package mod_lesson
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 **/
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);
37 require_sesskey();
39 // Apply overrides.
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));
47 $PAGE->set_url($url);
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
53 if (!$canmanage) {
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.
60 } else {
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)));
77 // Set Messages.
78 $lesson->add_messages_on_page_process($page, $result, $reviewmode);
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 if ($lesson->displayleft) {
88 echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>';
90 // This calculates and prints the ongoing score message
91 if ($lesson->ongoing && !$reviewmode) {
92 echo $lessonoutput->ongoing_score($lesson);
94 if (!$reviewmode) {
95 echo format_text($result->feedback, FORMAT_MOODLE, array('context' => $context, 'noclean' => true));
98 // User is modifying attempts - save button and some instructions
99 if (isset($USER->modattempts[$lesson->id])) {
100 $content = $OUTPUT->box(get_string("gotoendoflesson", "lesson"), 'center');
101 $content .= $OUTPUT->box(get_string("or", "lesson"), 'center');
102 $content .= $OUTPUT->box(get_string("continuetonextpage", "lesson"), 'center');
103 $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => LESSON_EOL));
104 echo $content . $OUTPUT->single_button($url, get_string('finish', 'lesson'));
107 // Review button back
108 if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$reviewmode && $lesson->review && !$result->maxattemptsreached) {
109 $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
110 echo $OUTPUT->single_button($url, get_string('reviewquestionback', 'lesson'));
113 $url = new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id, 'pageid'=>$result->newpageid));
115 if ($lesson->review && !$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$result->maxattemptsreached) {
116 // 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
117 // page then don't show the "No, I just want to go on to the next question" button. It's confusing.
118 if ($page->id != $result->newpageid) {
119 // Button to continue the lesson (the page to go is configured by the teacher).
120 echo $OUTPUT->single_button($url, get_string('reviewquestioncontinue', 'lesson'));
122 } else {
123 // Normal continue button
124 echo $OUTPUT->single_button($url, get_string('continue', 'lesson'));
127 echo $lessonoutput->footer();