Merged MDL-8566 from 1.9
[moodle.git] / blog / header.php
CommitLineData
4a173181 1<?php //$Id$
2
e96f2a77 3/// Sets up blocks and navigation for index.php
eccfc1ca 4
4a173181 5require_once($CFG->dirroot .'/blog/lib.php');
6require_once($CFG->libdir .'/pagelib.php');
7require_once($CFG->dirroot .'/blog/blogpage.php');
8require_once($CFG->libdir .'/blocklib.php');
9require_once($CFG->dirroot .'/course/lib.php');
10
5c625033 11$blockaction = optional_param('blockaction','', PARAM_ALPHA);
e96f2a77 12$instanceid = optional_param('instanceid', 0, PARAM_INT);
13$blockid = optional_param('blockid', 0, PARAM_INT);
4a173181 14
8c9814f9 15/// If user has never visited this page before, install 2 blocks for him
16blog_check_and_install_blocks();
17
4a173181 18
e96f2a77 19if (!$course = get_record('course', 'id', $courseid)) {
5a2a5331 20 print_error('The course number was incorrect ('. $courseid .')');
4a173181 21}
22
c15816ce 23// Bounds for block widths
24// more flexible for theme designers taken from theme config.php
25$lmin = (empty($THEME->block_l_min_width)) ? 160 : $THEME->block_l_min_width;
26$lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
27$rmin = (empty($THEME->block_r_min_width)) ? 160 : $THEME->block_r_min_width;
28$rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
29
30define('BLOCK_L_MIN_WIDTH', $lmin);
31define('BLOCK_L_MAX_WIDTH', $lmax);
32define('BLOCK_R_MIN_WIDTH', $rmin);
33define('BLOCK_R_MAX_WIDTH', $rmax);
e295df44 34
4a173181 35//_____________ new page class code ________
36$pagetype = PAGE_BLOG_VIEW;
37$pageclass = 'page_blog';
38
39// map our page identifier to the actual name
40// of the class which will be handling its operations.
e96f2a77 41page_map_class($pagetype, $pageclass);
4a173181 42
43// Now, create our page object.
86a1ba04 44if (empty($USER->id)) {
4a173181 45 $PAGE = page_create_object($pagetype);
a0a6424c 46} else {
4a173181 47 $PAGE = page_create_object($pagetype, $USER->id);
48}
e96f2a77 49$PAGE->courseid = $courseid;
50$PAGE->filtertype = $filtertype;
51$PAGE->filterselect = $filterselect;
47b87873 52$PAGE->tagid = $tagid;
e96f2a77 53
4a173181 54$PAGE->init_full(); //init the BlogInfo object and the courserecord object
55
e96f2a77 56$editing = false;
57if ($PAGE->user_allowed_editing()) {
58 $editing = $PAGE->user_is_editing();
59}
60
61// Calculate the preferred width for left, right and center (both center positions will use the same)
62$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
63 BLOCK_L_MAX_WIDTH);
64$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
65 BLOCK_R_MAX_WIDTH);
66
67// Display the blocks and allow blocklib to handle any block action requested
68$pageblocks = blocks_get_by_page($PAGE);
69
70if ($editing) {
71 if (!empty($blockaction) && confirm_sesskey()) {
72 if (!empty($blockid)) {
73 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
74 } else if (!empty($instanceid)) {
75 $instance = blocks_find_instance($instanceid, $pageblocks);
76 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
77 }
78 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
79 // but I'm not sure if it's worth the complexity increase...
80 $pageblocks = blocks_get_by_page($PAGE);
81 }
82 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
83}
84
91366ca7 85if (!empty($tagid)) {
bd1f4559 86 $taginstance = get_record('tag', 'id', $tagid);
3d535996 87} elseif (!empty($tag)) {
88 $taginstance = tag_id($tag);
4a173181 89}
4a173181 90
9154b440 91/// navigations
92/// site blogs - sitefullname -> blogs -> (?tag)
93/// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
94/// group blogs - sitefullname -> course fullname ->group ->(?tag)
95/// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
f4c85f46 96
4a173181 97$blogstring = get_string('blogs','blog');
25a78406 98$tagstring = get_string('tag');
4a173181 99
e96f2a77 100// needed also for user tabs later
101if (!$course = get_record('course', 'id', $courseid)) {
5a2a5331 102 print_error('Wrong course id');
e96f2a77 103}
f4c85f46 104
e295df44 105$navlinks = array();
4a173181 106
f4c85f46 107/// This is very messy atm.
4a173181 108
f4c85f46 109 switch ($filtertype) {
110 case 'site':
111 if ($tagid || !empty($tag)) {
e295df44 112 $navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc');
bd1f4559 113 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
e295df44 114 $navigation = build_navigation($navlinks);
115 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
f4c85f46 116 } else {
e295df44 117 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
118 $navigation = build_navigation($navlinks);
119 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
f4c85f46 120 }
121 break;
122
123 case 'course':
91366ca7 124 if ($tagid || !empty($tag)) {
e295df44 125 $navlinks[] = array('name' => $blogstring,
126 'link' => "index.php?filtertype=course&amp;filterselect=$filterselect",
127 'type' => 'misc');
bd1f4559 128 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
e295df44 129 $navigation = build_navigation($navlinks);
130 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
f4c85f46 131 } else {
e295df44 132 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
133 $navigation = build_navigation($navlinks);
134 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
f4c85f46 135 }
136 break;
137
138 case 'group':
4a173181 139
f3f7610c 140 if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
a044c05d 141 if ($tagid || !empty($tag)) {
e295df44 142 $navlinks[] = array('name' => $thisgroup->name,
143 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&amp;group=$filterselect",
144 'type' => 'misc');
145 $navlinks[] = array('name' => $blogstring,
146 'link' => "index.php?filtertype=group&amp;filterselect=$filterselect",
147 'type' => 'misc');
bd1f4559 148 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
e295df44 149 $navigation = build_navigation($navlinks);
150 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
a044c05d 151 } else {
e295df44 152 $navlinks[] = array('name' => $thisgroup->name,
153 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&amp;group=$filterselect",
154 'type' => 'misc');
155 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
156 $navigation = build_navigation($navlinks);
157 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
f3f7610c
ML
158 }
159 } else {
160 print_error('Unable to find group');
4a173181 161 }
162
f4c85f46 163 break;
4a173181 164
f4c85f46 165 case 'user':
f4c85f46 166 $participants = get_string('participants');
e96f2a77 167 if (!$user = get_record('user', 'id', $filterselect)) {
5a2a5331 168 print_error('Wrong user id');
e96f2a77 169 }
4a173181 170
e96f2a77 171 if ($course->id != SITEID) {
2647f80e 172 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
173 $systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
174
175 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
e295df44 176 $navlinks[] = array('name' => $participants,
177 'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
178 'type' => 'misc');
2647f80e 179 }
180 $navlinks[] = array('name' => fullname($user),
181 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&amp;course=$course->id",
182 'type' => 'misc');
183
184 if ($tagid || !empty($tag)) {
e295df44 185 $navlinks[] = array('name' => $blogstring,
186 'link' => "index.php?courseid=$course->id&amp;filtertype=user&amp;filterselect=$filterselect",
187 'type' => 'misc');
bd1f4559 188 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
e295df44 189 $navigation = build_navigation($navlinks);
190
f4c85f46 191 } else {
e295df44 192 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
193 $navigation = build_navigation($navlinks);
f4c85f46 194 }
dde73b9e 195 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
4a173181 196
e96f2a77 197 } else {
198
f4c85f46 199 //in top view
f4c85f46 200
dde73b9e 201 if ($postid) {
e295df44 202 $navlinks[] = array('name' => fullname($user),
203 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
204 'type' => 'misc');
205 $navlinks[] = array('name' => $blogstring,
206 'link' => "index.php?filtertype=user&amp;filterselect=$filterselect",
207 'type' => 'misc');
dde73b9e 208 $navlinks[] = array('name' => format_string($postobject->subject), 'link' => null, 'type' => 'misc');
e295df44 209 $navigation = build_navigation($navlinks);
210
dde73b9e 211 } else if ($tagid || !empty($tag)) {
212 $navlinks[] = array('name' => fullname($user),
213 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
214 'type' => 'misc');
215 $navlinks[] = array('name' => $blogstring,
216 'link' => "index.php?filtertype=user&amp;filterselect=$filterselect",
217 'type' => 'misc');
218 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
219 $navigation = build_navigation($navlinks);
f4c85f46 220
221 } else {
e295df44 222 $navlinks[] = array('name' => fullname($user),
223 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
224 'type' => 'misc');
225 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
226 $navigation = build_navigation($navlinks);
f4c85f46 227 }
dde73b9e 228 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
f4c85f46 229
230 }
231 break;
232
e96f2a77 233 default:
234 error ('Error unknown filtertype');
f4c85f46 235 break;
236 }
237
4a173181 238
e3ec7995 239// prints the tabs
b3e900ce 240if ($filtertype=='user') {
e96f2a77 241 $showroles = true;
242} else {
243 $showroles = false;
b3e900ce 244}
e3ec7995 245$currenttab = 'blogs';
e3ec7995 246
fc3ebc9d 247require_once($CFG->dirroot .'/user/tabs.php');
248
249
4a173181 250/// Layout the whole page as three big columns.
3d6d2447 251print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
4a173181 252print '<tr valign="top">' . "\n";
253
254/// The left column ...
255if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
3d6d2447 256 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
4a173181 257 print '<!-- Begin left side blocks -->' . "\n";
9f7f1a74 258 print_container_start();
4a173181 259 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
9f7f1a74 260 print_container_end();
4a173181 261 print '<!-- End left side blocks -->' . "\n";
262 print '</td>' . "\n";
263}
264
265/// Start main column
266print '<!-- Begin page content -->' . "\n";
fbe31d22 267print '<td>';
9f7f1a74 268print_container_start();
4a173181 269?>
290cf2f4 270<table width="100%">
271<tr>
fbe31d22 272<td valign="top">