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 * Page module version information
22 * @copyright 2009 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require('../../config.php');
27 require_once($CFG->dirroot
.'/mod/page/locallib.php');
28 require_once($CFG->libdir
.'/completionlib.php');
30 $id = optional_param('id', 0, PARAM_INT
); // Course Module ID
31 $p = optional_param('p', 0, PARAM_INT
); // Page instance ID
32 $inpopup = optional_param('inpopup', 0, PARAM_BOOL
);
35 if (!$page = $DB->get_record('page', array('id'=>$p))) {
36 print_error('invalidaccessparameter');
38 $cm = get_coursemodule_from_instance('page', $page->id
, $page->course
, false, MUST_EXIST
);
41 if (!$cm = get_coursemodule_from_id('page', $id)) {
42 print_error('invalidcoursemodule');
44 $page = $DB->get_record('page', array('id'=>$cm->instance
), '*', MUST_EXIST
);
47 $course = $DB->get_record('course', array('id'=>$cm->course
), '*', MUST_EXIST
);
49 require_course_login($course, true, $cm);
50 $context = context_module
::instance($cm->id
);
51 require_capability('mod/page:view', $context);
53 // Trigger module viewed event.
54 $event = \mod_page\event\course_module_viewed
::create(array(
55 'objectid' => $page->id
,
58 $event->add_record_snapshot('course_modules', $cm);
59 $event->add_record_snapshot('course', $course);
60 $event->add_record_snapshot('page', $page);
63 // Update 'viewed' state if required by completion system
64 require_once($CFG->libdir
. '/completionlib.php');
65 $completion = new completion_info($course);
66 $completion->set_module_viewed($cm);
68 $PAGE->set_url('/mod/page/view.php', array('id' => $cm->id
));
70 $options = empty($page->displayoptions
) ?
array() : unserialize($page->displayoptions
);
72 if ($inpopup and $page->display
== RESOURCELIB_DISPLAY_POPUP
) {
73 $PAGE->set_pagelayout('popup');
74 $PAGE->set_title($course->shortname
.': '.$page->name
);
75 $PAGE->set_heading($course->fullname
);
77 $PAGE->set_title($course->shortname
.': '.$page->name
);
78 $PAGE->set_heading($course->fullname
);
79 $PAGE->set_activity_record($page);
81 echo $OUTPUT->header();
82 if (!isset($options['printheading']) ||
!empty($options['printheading'])) {
83 echo $OUTPUT->heading(format_string($page->name
), 2);
86 if (!empty($options['printintro'])) {
87 if (trim(strip_tags($page->intro
))) {
88 echo $OUTPUT->box_start('mod_introbox', 'pageintro');
89 echo format_module_intro('page', $page, $cm->id
);
90 echo $OUTPUT->box_end();
94 $content = file_rewrite_pluginfile_urls($page->content
, 'pluginfile.php', $context->id
, 'mod_page', 'content', $page->revision
);
95 $formatoptions = new stdClass
;
96 $formatoptions->noclean
= true;
97 $formatoptions->overflowdiv
= true;
98 $formatoptions->context
= $context;
99 $content = format_text($content, $page->contentformat
, $formatoptions);
100 echo $OUTPUT->box($content, "generalbox center clearfix");
102 $strlastmodified = get_string("lastmodified");
103 echo "<div class=\"modified\">$strlastmodified: ".userdate($page->timemodified
)."</div>";
105 echo $OUTPUT->footer();