MDL-15476
[moodle-linuxchix.git] / mod / lesson / pagelib.php
blob891c11d8318a9af9a5ea6c148364d14c9d74a3b0
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 /// Build the buttons
80 if (has_capability('mod/lesson:edit', $context)) {
81 $buttons = '<span class="edit_buttons">'.update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'lesson'));
83 if (!empty($this->lessonpageid) and $this->lessonpageid != LESSON_EOL) {
84 $buttons .= '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/lesson.php">'.
85 '<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
86 '<input type="hidden" name="action" value="editpage" />'.
87 '<input type="hidden" name="redirect" value="navigation" />'.
88 '<input type="hidden" name="pageid" value="'.$this->lessonpageid.'" />'.
89 '<input type="submit" value="'.get_string('editpagecontent', 'lesson').'" />'.
90 '</form>';
92 if (!empty($CFG->showblocksonmodpages) and $this->user_allowed_editing()) {
93 if ($this->user_is_editing()) {
94 $onoff = 'off';
95 } else {
96 $onoff = 'on';
98 $buttons .= '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/view.php">'.
99 '<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
100 '<input type="hidden" name="pageid" value="'.$this->lessonpageid.'" />'.
101 '<input type="hidden" name="edit" value="'.$onoff.'" />'.
102 '<input type="submit" value="'.get_string("blocksedit$onoff").'" />
103 </form>';
106 $buttons .= '</span>';
107 } else {
108 $buttons = '&nbsp;';
111 /// Build the meta
112 /// Currently broken because the $meta is printed before the JavaScript is printed
113 // if (!optional_param('pageid', 0, PARAM_INT) and !empty($this->activityrecord->mediafile)) {
114 // // open our pop-up
115 // $url = '/mod/lesson/mediafile.php?id='.$this->modulerecord->id;
116 // $name = 'lessonmediafile';
117 // $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $this->activityrecord->mediawidth .',height='. $this->activityrecord->mediaheight;
118 // $meta = "\n<script type=\"text/javascript\">";
119 // $meta .= "\n<!--\n";
120 // $meta .= " openpopup('$url', '$name', '$options', 0);";
121 // $meta .= "\n// -->\n";
122 // $meta .= '</script>';
123 // } else {
124 $meta = '';
125 // }
127 $navigation = build_navigation($morenavlinks, $this->modulerecord);
128 print_header($title, $this->courserecord->fullname, $navigation, '', $meta, true, $buttons, navmenu($this->courserecord, $this->modulerecord));
130 if (has_capability('mod/lesson:manage', $context)) {
131 print_heading_with_help($activityname, 'overview', 'lesson');
133 // Rename our objects for the sake of the tab code
134 list($cm, $course, $lesson, $currenttab) = array(&$this->modulerecord, &$this->courserecord, &$this->activityrecord, 'view');
135 include($CFG->dirroot.'/mod/lesson/tabs.php');
136 } else {
137 print_heading($activityname);
140 lesson_print_messages();
143 function get_type() {
144 return PAGE_LESSON_VIEW;
147 function blocks_get_positions() {
148 return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
151 function blocks_default_position() {
152 return BLOCK_POS_RIGHT;
155 function blocks_move_position(&$instance, $move) {
156 if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
157 return BLOCK_POS_RIGHT;
158 } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
159 return BLOCK_POS_LEFT;
161 return $instance->position;
165 * Needed to add the ID of the current lesson page
167 * @return array
169 function url_get_parameters() {
170 $this->init_full();
171 return array('id' => $this->modulerecord->id, 'pageid' => $this->lessonpageid);;
175 * Set the current lesson page ID
177 * @return void
179 function set_lessonpageid($pageid) {
180 $this->lessonpageid = $pageid;