MDL-20068 new Page module, includes migrate from old mod/resource; remaining issues...
[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 *
21 * @package mod-page
22 * @copyright 2009 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26require('../../config.php');
27require_once($CFG->dirroot.'/mod/page/locallib.php');
28
29$id = optional_param('id', 0, PARAM_INT); // Course Module ID
30$p = optional_param('p', 0, PARAM_INT); // Page instance ID
31$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
32
33if ($p) {
34 if (!$page = $DB->get_record('page', array('id'=>$p))) {
35 page_redirect_if_migrated($r, 0);
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)) {
42 page_redirect_if_migrated(0, $id);
43 print_error('invalidcoursemodule');
44 }
45 $page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST);
46}
47
48$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
49
50require_course_login($course, true, $cm);
51$context = get_context_instance(CONTEXT_MODULE, $cm->id);
52
53add_to_log($course->id, 'page', 'view', 'view.php?id='.$cm->id, $page->id, $cm->id);
54
55$PAGE->set_url('mod/page/view.php', array('id' => $cm->id));
56
57$options = empty($page->displayoptions) ? array() : unserialize($page->displayoptions);
58
59if ($inpopup and $page->display == RESOURCELIB_DISPLAY_POPUP) {
60 $PAGE->set_generaltype('popup');
61 $PAGE->set_title($course->shortname.': '.$page->name);
62 if (!empty($options['printheading'])) {
63 $PAGE->set_heading($page->name);
64 } else {
65 $PAGE->set_heading('');
66 }
67 echo $OUTPUT->header();
68
69} else {
70 $PAGE->set_title($course->shortname.': '.$page->name);
71 $PAGE->set_heading($course->fullname);
72 $PAGE->set_activity_record($page);
73 $PAGE->set_button(update_module_button($cm->id, '', get_string('modulename', 'page')));
74 echo $OUTPUT->header(build_navigation('', $cm), navmenu($course, $cm));
75
76 if (!empty($options['printheading'])) {
77 echo $OUTPUT->heading(format_string($page->name), 2, 'main', 'pageheading');
78 }
79}
80
81if (!empty($options['printintro'])) {
82 if (trim(strip_tags($page->intro))) {
83 echo $OUTPUT->box_start('mod_introbox', 'pageintro');
84 echo format_module_intro('page', $page, $cm->id);
85 echo $OUTPUT->box_end();
86 }
87}
88
89$content = file_rewrite_pluginfile_urls($page->content, 'pluginfile.php', $context->id, 'page_content', $page->revision);
90$formatoptions = (object)array('noclean'=>true);
91$content = format_text($content, $page->contentformat, $formatoptions, $course->id);
92echo $OUTPUT->box($content, "generalbox center clearfix");
93
94$strlastmodified = get_string("lastmodified");
95echo "<div class=\"modified\">$strlastmodified: ".userdate($page->timemodified)."</div>";
96
97echo $OUTPUT->footer();