MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / lesson / pagelib.php
blobe12429128d1d8be5ba77e6d5b39dc23049436b0f
1 <?php // $Id$
2 /**
3 * Page class for lesson
5 * @author Mark Nielsen
6 * @version $Id$
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package lesson
9 **/
11 require_once($CFG->libdir.'/pagelib.php');
12 require_once($CFG->dirroot.'/course/lib.php'); // needed for some blocks
14 /**
15 * Define the page types
17 **/
18 define('PAGE_LESSON_VIEW', 'mod-lesson-view');
20 /**
21 * Map the classes to the page types
23 **/
24 page_map_class(PAGE_LESSON_VIEW, 'page_lesson');
26 /**
27 * Add the page types defined in this file
29 **/
30 $DEFINEDPAGES = array(PAGE_LESSON_VIEW);
32 /**
33 * Class that models the behavior of a lesson
35 * @author Mark Nielsen (lesson extention only)
36 * @package lesson
37 **/
38 class page_lesson extends page_generic_activity {
40 /**
41 * Module name
43 * @var string
44 **/
45 var $activityname = 'lesson';
46 /**
47 * Current lesson page ID
49 * @var string
50 **/
51 var $lessonpageid = NULL;
53 /**
54 * Print a standard lesson heading.
56 * This will also print up to three
57 * buttons in the breadcrumb, lesson heading
58 * lesson tabs, lesson notifications and perhaps
59 * a popup with a media file.
61 * @return void
62 **/
63 function print_header($title = '', $morenavlinks = array()) {
64 global $CFG;
66 $this->init_full();
68 /// Variable setup/check
69 $context = get_context_instance(CONTEXT_MODULE, $this->modulerecord->id);
70 $activityname = format_string($this->activityrecord->name);
72 if ($this->lessonpageid === NULL) {
73 error('Programmer error: must set the lesson page ID');
75 if (empty($title)) {
76 $title = "{$this->courserecord->shortname}: $activityname";
79 $navlinks = array();
80 $navlinks[] = array('name' => get_string('modulenameplural', $this->activityname), 'link' => $CFG->wwwroot."/mod/{$this->activityname}/index.php?id={$this->courserecord->id}", 'type' => 'activity');
81 $navlinks[] = array('name' => format_string($this->activityrecord->name), 'link' => $CFG->wwwroot."/mod/{$this->activityname}/view.php?id={$this->modulerecord->id}", 'type' => 'activityinstance');
83 if (!empty($morenavlinks)) {
84 $navlinks = array_merge($navlinks, $morenavlinks);
88 /// Build the buttons
89 if (has_capability('mod/lesson:edit', $context)) {
90 $buttons = '<span class="edit_buttons">'.update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'lesson'));
92 if (!empty($this->lessonpageid) and $this->lessonpageid != LESSON_EOL) {
93 $buttons .= '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/lesson.php">'.
94 '<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
95 '<input type="hidden" name="action" value="editpage" />'.
96 '<input type="hidden" name="redirect" value="navigation" />'.
97 '<input type="hidden" name="pageid" value="'.$this->lessonpageid.'" />'.
98 '<input type="submit" value="'.get_string('editpagecontent', 'lesson').'" />'.
99 '</form>';
101 if (!empty($CFG->showblocksonmodpages) and $this->user_allowed_editing()) {
102 if ($this->user_is_editing()) {
103 $onoff = 'off';
104 } else {
105 $onoff = 'on';
107 $buttons .= '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/view.php">'.
108 '<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
109 '<input type="hidden" name="pageid" value="'.$this->lessonpageid.'" />'.
110 '<input type="hidden" name="edit" value="'.$onoff.'" />'.
111 '<input type="submit" value="'.get_string("blocksedit$onoff").'" />
112 </form>';
115 $buttons .= '</span>';
116 } else {
117 $buttons = '&nbsp;';
120 /// Build the meta
121 /// Currently broken because the $meta is printed before the JavaScript is printed
122 // if (!optional_param('pageid', 0, PARAM_INT) and !empty($this->activityrecord->mediafile)) {
123 // // open our pop-up
124 // $url = '/mod/lesson/mediafile.php?id='.$this->modulerecord->id;
125 // $name = 'lessonmediafile';
126 // $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $this->activityrecord->mediawidth .',height='. $this->activityrecord->mediaheight;
127 // $meta = "\n<script type=\"text/javascript\">";
128 // $meta .= "\n<!--\n";
129 // $meta .= " openpopup('$url', '$name', '$options', 0);";
130 // $meta .= "\n// -->\n";
131 // $meta .= '</script>';
132 // } else {
133 $meta = '';
134 // }
136 $navigation = build_navigation($navlinks);
138 print_header($title, $this->courserecord->fullname, $navigation, '', $meta, true, $buttons, navmenu($this->courserecord, $this->modulerecord));
140 if (has_capability('mod/lesson:manage', $context)) {
141 print_heading_with_help($activityname, 'overview', 'lesson');
143 // Rename our objects for the sake of the tab code
144 list($cm, $course, $lesson, $currenttab) = array(&$this->modulerecord, &$this->courserecord, &$this->activityrecord, 'view');
145 include($CFG->dirroot.'/mod/lesson/tabs.php');
146 } else {
147 print_heading($activityname);
150 lesson_print_messages();
153 function get_type() {
154 return PAGE_LESSON_VIEW;
157 function blocks_get_positions() {
158 return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
161 function blocks_default_position() {
162 return BLOCK_POS_RIGHT;
165 function blocks_move_position(&$instance, $move) {
166 if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
167 return BLOCK_POS_RIGHT;
168 } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
169 return BLOCK_POS_LEFT;
171 return $instance->position;
175 * Needed to add the ID of the current lesson page
177 * @return array
179 function url_get_parameters() {
180 $this->init_full();
181 return array('id' => $this->modulerecord->id, 'pageid' => $this->lessonpageid);;
185 * Set the current lesson page ID
187 * @return void
189 function set_lessonpageid($pageid) {
190 $this->lessonpageid = $pageid;