MDL-59081 mod_lesson: Remove continue button if not needed.
[moodle.git] / mod / lesson / continue.php
CommitLineData
0a4abb73
SH
1<?php
2
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.
14//
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/>.
17
18/**
19 * Action for processing page answers by users
20 *
9b24f68b 21 * @package mod_lesson
cc3dbaaa
PS
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
0a4abb73
SH
24 **/
25
26/** Require the specific libraries */
27require_once("../../config.php");
28require_once($CFG->dirroot.'/mod/lesson/locallib.php');
29
b3daa926
PS
30$id = required_param('id', PARAM_INT);
31
0e35ba6f 32$cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
74df2951 33$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
61b51764 34$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST), $cm, $course);
0a4abb73
SH
35
36require_login($course, false, $cm);
37require_sesskey();
38
e0e1a83e
JMV
39// Apply overrides.
40$lesson->update_effective_access($USER->id);
41
61b51764
JL
42$context = $lesson->context;
43$canmanage = $lesson->can_manage();
649cf95d 44$lessonoutput = $PAGE->get_renderer('mod_lesson');
0a4abb73 45
a6855934 46$url = new moodle_url('/mod/lesson/continue.php', array('id'=>$cm->id));
0a4abb73 47$PAGE->set_url($url);
ed9b45ec 48$PAGE->set_pagetype('mod-lesson-view');
0a4abb73
SH
49$PAGE->navbar->add(get_string('continue', 'lesson'));
50
51// This is the code updates the lesson time for a timed test
52// get time information for this user
53if (!$canmanage) {
54 $lesson->displayleft = lesson_displayleftif($lesson);
55 $timer = $lesson->update_timer();
dbba944e
JL
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.
0a4abb73
SH
59 }
60} else {
61 $timer = new stdClass;
62}
63
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));
abd5c24e 66
37029e46 67$reviewmode = $lesson->is_in_review_mode();
abd5c24e 68
61b51764
JL
69// Process the page responses.
70$result = $lesson->process_page_responses($page);
0a4abb73 71
8d674838
JL
72if ($result->nodefaultresponse || $result->inmediatejump) {
73 // Don't display feedback or force a redirecto to newpageid.
a6855934 74 redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id,'pageid'=>$result->newpageid)));
0a4abb73
SH
75}
76
61b51764
JL
77// Set Messages.
78$lesson->add_messages_on_page_process($page, $result, $reviewmode);
0a4abb73 79
a6855934 80$PAGE->set_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
0a4abb73
SH
81$PAGE->set_subpage($page->id);
82
83/// Print the header, heading and tabs
d9c26e21 84lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
d42bc7dc 85echo $lessonoutput->header($lesson, $cm, 'view', true, $page->id, get_string('continue', 'lesson'));
0a4abb73
SH
86
87if ($lesson->displayleft) {
88 echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>';
89}
90// This calculates and prints the ongoing score message
abd5c24e 91if ($lesson->ongoing && !$reviewmode) {
0a4abb73
SH
92 echo $lessonoutput->ongoing_score($lesson);
93}
0dea8ed7 94if (!$reviewmode) {
a25863a3 95 echo format_text($result->feedback, FORMAT_MOODLE, array('context' => $context, 'noclean' => true));
0a6a2543 96}
0a4abb73
SH
97
98// User is modifying attempts - save button and some instructions
99if (isset($USER->modattempts[$lesson->id])) {
100 $url = $CFG->wwwroot.'/mod/lesson/view.php';
57a4bd03 101 $content = $OUTPUT->box(get_string("gotoendoflesson", "lesson"), 'center');
0a4abb73 102 $content .= $OUTPUT->box(get_string("or", "lesson"), 'center');
57a4bd03 103 $content .= $OUTPUT->box(get_string("continuetonextpage", "lesson"), 'center');
dc88d782 104 $content .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$cm->id));
916276fc 105 $content .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'pageid', 'value'=>LESSON_EOL));
57a4bd03 106 $content .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'submit', 'value'=>get_string('finish', 'lesson')));
39f5b5c1 107 echo html_writer::tag('form', "<div>$content</div>", array('method'=>'post', 'action'=>$url));
0a4abb73
SH
108}
109
110// Review button back
0a6a2543 111if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$reviewmode && $lesson->review && !$result->maxattemptsreached) {
0a4abb73 112 $url = $CFG->wwwroot.'/mod/lesson/view.php';
dc88d782 113 $content = html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$cm->id));
916276fc
PS
114 $content .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'pageid', 'value'=>$page->id));
115 $content .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'submit', 'value'=>get_string('reviewquestionback', 'lesson')));
39f5b5c1 116 echo html_writer::tag('form', "<div class=\"singlebutton\">$content</div>", array('method'=>'post', 'action'=>$url));
0a4abb73
SH
117}
118
a6855934 119$url = new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id, 'pageid'=>$result->newpageid));
dab563f5 120
0a6a2543 121if ($lesson->review && !$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$result->maxattemptsreached) {
dab563f5
AG
122 // 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
123 // page then don't show the "No, I just want to go on to the next question" button. It's confusing.
124 if ($page->id != $result->newpageid) {
125 // Button to continue the lesson (the page to go is configured by the teacher).
126 echo $OUTPUT->single_button($url, get_string('reviewquestioncontinue', 'lesson'));
127 }
0a4abb73
SH
128} else {
129 // Normal continue button
5c2ed7e2 130 echo $OUTPUT->single_button($url, get_string('continue', 'lesson'));
0a4abb73 131}
5c2ed7e2 132
0e35ba6f 133echo $lessonoutput->footer();