MDL-11328 Added the missing variable
[moodle-pu.git] / blog / header.php
blob3e770e66d2bb8cac654b556a9f3bcaf3ed787332
1 <?php //$Id$
3 /// Sets up blocks and navigation for index.php
5 require_once($CFG->dirroot .'/blog/lib.php');
6 require_once($CFG->libdir .'/pagelib.php');
7 require_once($CFG->dirroot .'/blog/blogpage.php');
8 require_once($CFG->libdir .'/blocklib.php');
9 require_once($CFG->dirroot .'/course/lib.php');
11 if (!empty($THEME->customcorners)) {
12 require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
15 $blockaction = optional_param('blockaction','', PARAM_ALPHA);
16 $instanceid = optional_param('instanceid', 0, PARAM_INT);
17 $blockid = optional_param('blockid', 0, PARAM_INT);
19 /// If user has never visited this page before, install 2 blocks for him
20 blog_check_and_install_blocks();
23 if (!$course = get_record('course', 'id', $courseid)) {
24 error('The course number was incorrect ('. $courseid .')');
27 // Bounds for block widths
28 // more flexible for theme designers taken from theme config.php
29 $lmin = (empty($THEME->block_l_min_width)) ? 160 : $THEME->block_l_min_width;
30 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
31 $rmin = (empty($THEME->block_r_min_width)) ? 160 : $THEME->block_r_min_width;
32 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
34 define('BLOCK_L_MIN_WIDTH', $lmin);
35 define('BLOCK_L_MAX_WIDTH', $lmax);
36 define('BLOCK_R_MIN_WIDTH', $rmin);
37 define('BLOCK_R_MAX_WIDTH', $rmax);
39 //_____________ new page class code ________
40 $pagetype = PAGE_BLOG_VIEW;
41 $pageclass = 'page_blog';
43 // map our page identifier to the actual name
44 // of the class which will be handling its operations.
45 page_map_class($pagetype, $pageclass);
47 // Now, create our page object.
48 if (empty($USER->id)) {
49 $PAGE = page_create_object($pagetype);
50 } else {
51 $PAGE = page_create_object($pagetype, $USER->id);
53 $PAGE->courseid = $courseid;
54 $PAGE->filtertype = $filtertype;
55 $PAGE->filterselect = $filterselect;
56 $PAGE->tagid = $tagid;
58 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
60 $editing = false;
61 if ($PAGE->user_allowed_editing()) {
62 $editing = $PAGE->user_is_editing();
65 // Calculate the preferred width for left, right and center (both center positions will use the same)
66 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
67 BLOCK_L_MAX_WIDTH);
68 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
69 BLOCK_R_MAX_WIDTH);
71 // Display the blocks and allow blocklib to handle any block action requested
72 $pageblocks = blocks_get_by_page($PAGE);
74 if ($editing) {
75 if (!empty($blockaction) && confirm_sesskey()) {
76 if (!empty($blockid)) {
77 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
78 } else if (!empty($instanceid)) {
79 $instance = blocks_find_instance($instanceid, $pageblocks);
80 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
82 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
83 // but I'm not sure if it's worth the complexity increase...
84 $pageblocks = blocks_get_by_page($PAGE);
86 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
89 if (!empty($tagid)) {
90 $taginstance = get_record('tag', 'id', $tagid);
91 } else {
92 $tagid = '';
93 if (!empty($tag)) {
94 $taginstance = tag_id($tag);
98 /// navigations
99 /// site blogs - sitefullname -> blogs -> (?tag)
100 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
101 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
102 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
104 $blogstring = get_string('blogs','blog');
105 $tagstring = get_string('tag');
107 // needed also for user tabs later
108 if (!$course = get_record('course', 'id', $courseid)) {
109 error('Wrong course id');
112 $navlinks = array();
114 /// This is very messy atm.
116 switch ($filtertype) {
117 case 'site':
118 if ($tagid || !empty($tag)) {
119 $navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc');
120 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
121 $navigation = build_navigation($navlinks);
122 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
123 } else {
124 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
125 $navigation = build_navigation($navlinks);
126 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
128 break;
130 case 'course':
131 if ($tagid || !empty($tag)) {
132 $navlinks[] = array('name' => $blogstring,
133 'link' => "index.php?filtertype=course&amp;filterselect=$filterselect",
134 'type' => 'misc');
135 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
136 $navigation = build_navigation($navlinks);
137 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
138 } else {
139 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
140 $navigation = build_navigation($navlinks);
141 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
143 break;
145 case 'group':
147 if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
148 if ($tagid || !empty($tag)) {
149 $navlinks[] = array('name' => $thisgroup->name,
150 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&amp;group=$filterselect",
151 'type' => 'misc');
152 $navlinks[] = array('name' => $blogstring,
153 'link' => "index.php?filtertype=group&amp;filterselect=$filterselect",
154 'type' => 'misc');
155 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
156 $navigation = build_navigation($navlinks);
157 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
158 } else {
159 $navlinks[] = array('name' => $thisgroup->name,
160 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&amp;group=$filterselect",
161 'type' => 'misc');
162 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
163 $navigation = build_navigation($navlinks);
164 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
166 } else {
167 print_error('Unable to find group');
170 break;
172 case 'user':
173 $participants = get_string('participants');
174 if (!$user = get_record('user', 'id', $filterselect)) {
175 error('Wrong user id');
178 if ($course->id != SITEID) {
179 if ($tagid || !empty($tag)) {
180 $navlinks[] = array('name' => $course->shortname,
181 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
182 'type' => 'misc');
183 $navlinks[] = array('name' => $participants,
184 'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
185 'type' => 'misc');
186 $navlinks[] = array('name' => fullname($user),
187 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&amp;course=$course->id",
188 'type' => 'misc');
189 $navlinks[] = array('name' => $blogstring,
190 'link' => "index.php?courseid=$course->id&amp;filtertype=user&amp;filterselect=$filterselect",
191 'type' => 'misc');
192 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
193 $navigation = build_navigation($navlinks);
195 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
197 } else {
198 $navlinks[] = array('name' => $course->shortname,
199 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
200 'type' => 'misc');
201 $navlinks[] = array('name' => $participants,
202 'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
203 'type' => 'misc');
204 $navlinks[] = array('name' => fullname($user),
205 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&amp;course=$course->id",
206 'type' => 'misc');
207 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
208 $navigation = build_navigation($navlinks);
209 print_header("$course->shortname: $blogstring", $course->fullname,
210 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
211 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
212 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
213 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
216 } else {
218 //in top view
220 if ($tagid || !empty($tag)) {
221 $navlinks[] = array('name' => fullname($user),
222 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
223 'type' => 'misc');
224 $navlinks[] = array('name' => $blogstring,
225 'link' => "index.php?filtertype=user&amp;filterselect=$filterselect",
226 'type' => 'misc');
227 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
228 $navigation = build_navigation($navlinks);
230 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
232 } else {
233 $navlinks[] = array('name' => fullname($user),
234 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
235 'type' => 'misc');
236 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
237 $navigation = build_navigation($navlinks);
238 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
243 break;
245 default:
246 error ('Error unknown filtertype');
247 break;
251 // prints the tabs
252 if ($filtertype=='user') {
253 $showroles = true;
254 } else {
255 $showroles = false;
257 $currenttab = 'blogs';
259 require_once($CFG->dirroot .'/user/tabs.php');
262 /// Layout the whole page as three big columns.
263 print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
264 print '<tr valign="top">' . "\n";
266 /// The left column ...
267 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
268 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
269 print '<!-- Begin left side blocks -->' . "\n";
270 if (!empty($THEME->customcorners)) print_custom_corners_start();
271 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
272 if (!empty($THEME->customcorners)) print_custom_corners_end();
273 print '<!-- End left side blocks -->' . "\n";
274 print '</td>' . "\n";
277 /// Start main column
278 print '<!-- Begin page content -->' . "\n";
279 print '<td>';
280 if (!empty($THEME->customcorners)) print_custom_corners_start();
282 <table width="100%">
283 <tr>
284 <td valign="top">