MDL-14627 new mod/page:view capability
[moodle.git] / mod / page / view.php
CommitLineData
1ad9ff57 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 * Page module version information
20 *
2c49daf7
PS
21 * @package mod
22 * @subpackage page
23 * @copyright 2009 Petr Skoda (http://skodak.org)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1ad9ff57 25 */
26
27require('../../config.php');
28require_once($CFG->dirroot.'/mod/page/locallib.php');
29
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);
33
34if ($p) {
35 if (!$page = $DB->get_record('page', array('id'=>$p))) {
1ad9ff57 36 print_error('invalidaccessparameter');
37 }
38 $cm = get_coursemodule_from_instance('page', $page->id, $page->course, false, MUST_EXIST);
39
40} else {
41 if (!$cm = get_coursemodule_from_id('page', $id)) {
1ad9ff57 42 print_error('invalidcoursemodule');
43 }
44 $page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST);
45}
46
47$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
48
49require_course_login($course, true, $cm);
50$context = get_context_instance(CONTEXT_MODULE, $cm->id);
0c0484de 51require_capability('mod/page:view', $context);
1ad9ff57 52
53add_to_log($course->id, 'page', 'view', 'view.php?id='.$cm->id, $page->id, $cm->id);
54
c15a60e6 55// Update 'viewed' state if required by completion system
518f7d92 56require_once($CFG->libdir . '/completionlib.php');
c15a60e6
SM
57$completion = new completion_info($course);
58$completion->set_module_viewed($cm);
59
a6855934 60$PAGE->set_url('/mod/page/view.php', array('id' => $cm->id));
1ad9ff57 61
62$options = empty($page->displayoptions) ? array() : unserialize($page->displayoptions);
63
64if ($inpopup and $page->display == RESOURCELIB_DISPLAY_POPUP) {
78946b9b 65 $PAGE->set_pagelayout('popup');
1ad9ff57 66 $PAGE->set_title($course->shortname.': '.$page->name);
67 if (!empty($options['printheading'])) {
68 $PAGE->set_heading($page->name);
69 } else {
70 $PAGE->set_heading('');
71 }
72 echo $OUTPUT->header();
73
74} else {
75 $PAGE->set_title($course->shortname.': '.$page->name);
76 $PAGE->set_heading($course->fullname);
77 $PAGE->set_activity_record($page);
0d7f1180 78 echo $OUTPUT->header();
1ad9ff57 79
80 if (!empty($options['printheading'])) {
81 echo $OUTPUT->heading(format_string($page->name), 2, 'main', 'pageheading');
82 }
83}
84
85if (!empty($options['printintro'])) {
86 if (trim(strip_tags($page->intro))) {
87 echo $OUTPUT->box_start('mod_introbox', 'pageintro');
88 echo format_module_intro('page', $page, $cm->id);
89 echo $OUTPUT->box_end();
90 }
91}
92
64f93798 93$content = file_rewrite_pluginfile_urls($page->content, 'pluginfile.php', $context->id, 'mod_page', 'content', $page->revision);
1ad9ff57 94$formatoptions = (object)array('noclean'=>true);
95$content = format_text($content, $page->contentformat, $formatoptions, $course->id);
96echo $OUTPUT->box($content, "generalbox center clearfix");
97
98$strlastmodified = get_string("lastmodified");
99echo "<div class=\"modified\">$strlastmodified: ".userdate($page->timemodified)."</div>";
100
101echo $OUTPUT->footer();