MDL-14303, add missing cmidnumber parameter. see tracker
[moodle-linuxchix.git] / blog / header.php
blob5b003a33103a8f9564abcfae7168c2712dbd0d03
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 $blockaction = optional_param('blockaction','', PARAM_ALPHA);
12 $instanceid = optional_param('instanceid', 0, PARAM_INT);
13 $blockid = optional_param('blockid', 0, PARAM_INT);
15 /// If user has never visited this page before, install 2 blocks for him
16 blog_check_and_install_blocks();
19 if (!$course = get_record('course', 'id', $courseid)) {
20 error('The course number was incorrect ('. $courseid .')');
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;
30 define('BLOCK_L_MIN_WIDTH', $lmin);
31 define('BLOCK_L_MAX_WIDTH', $lmax);
32 define('BLOCK_R_MIN_WIDTH', $rmin);
33 define('BLOCK_R_MAX_WIDTH', $rmax);
35 //_____________ new page class code ________
36 $pagetype = PAGE_BLOG_VIEW;
37 $pageclass = 'page_blog';
39 // map our page identifier to the actual name
40 // of the class which will be handling its operations.
41 page_map_class($pagetype, $pageclass);
43 // Now, create our page object.
44 if (empty($USER->id)) {
45 $PAGE = page_create_object($pagetype);
46 } else {
47 $PAGE = page_create_object($pagetype, $USER->id);
49 $PAGE->courseid = $courseid;
50 $PAGE->filtertype = $filtertype;
51 $PAGE->filterselect = $filterselect;
52 $PAGE->tagid = $tagid;
54 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
56 $editing = false;
57 if ($PAGE->user_allowed_editing()) {
58 $editing = $PAGE->user_is_editing();
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);
67 // Display the blocks and allow blocklib to handle any block action requested
68 $pageblocks = blocks_get_by_page($PAGE);
70 if ($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);
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);
82 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
85 if (!empty($tagid)) {
86 $taginstance = get_record('tag', 'id', $tagid);
87 } elseif (!empty($tag)) {
88 $taginstance = tag_id($tag);
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)
97 $blogstring = get_string('blogs','blog');
98 $tagstring = get_string('tag');
100 // needed also for user tabs later
101 if (!$course = get_record('course', 'id', $courseid)) {
102 error('Wrong course id');
105 $navlinks = array();
107 /// This is very messy atm.
109 switch ($filtertype) {
110 case 'site':
111 if ($tagid || !empty($tag)) {
112 $navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc');
113 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
114 $navigation = build_navigation($navlinks);
115 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
116 } else {
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());
121 break;
123 case 'course':
124 if ($tagid || !empty($tag)) {
125 $navlinks[] = array('name' => $blogstring,
126 'link' => "index.php?filtertype=course&amp;filterselect=$filterselect",
127 'type' => 'misc');
128 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
129 $navigation = build_navigation($navlinks);
130 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
131 } else {
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());
136 break;
138 case 'group':
140 if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
141 if ($tagid || !empty($tag)) {
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');
148 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
149 $navigation = build_navigation($navlinks);
150 print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
151 } else {
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());
159 } else {
160 print_error('Unable to find group');
163 break;
165 case 'user':
166 $participants = get_string('participants');
167 if (!$user = get_record('user', 'id', $filterselect)) {
168 error('Wrong user id');
171 if ($course->id != SITEID) {
172 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
173 $systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
175 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
176 $navlinks[] = array('name' => $participants,
177 'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
178 'type' => 'misc');
180 $navlinks[] = array('name' => fullname($user),
181 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&amp;course=$course->id",
182 'type' => 'misc');
184 if ($tagid || !empty($tag)) {
185 $navlinks[] = array('name' => $blogstring,
186 'link' => "index.php?courseid=$course->id&amp;filtertype=user&amp;filterselect=$filterselect",
187 'type' => 'misc');
188 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
189 $navigation = build_navigation($navlinks);
191 } else {
192 $navlinks[] = array('name' => $blogstring, '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 {
199 //in top view
201 if ($postid) {
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');
208 $navlinks[] = array('name' => format_string($postobject->subject), 'link' => null, 'type' => 'misc');
209 $navigation = build_navigation($navlinks);
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);
221 } else {
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);
228 print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
231 break;
233 default:
234 error ('Error unknown filtertype');
235 break;
239 // prints the tabs
240 if ($filtertype=='user') {
241 $showroles = true;
242 } else {
243 $showroles = false;
245 $currenttab = 'blogs';
247 require_once($CFG->dirroot .'/user/tabs.php');
250 /// Layout the whole page as three big columns.
251 print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
252 print '<tr valign="top">' . "\n";
254 /// The left column ...
255 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
256 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
257 print '<!-- Begin left side blocks -->' . "\n";
258 print_container_start();
259 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
260 print_container_end();
261 print '<!-- End left side blocks -->' . "\n";
262 print '</td>' . "\n";
265 /// Start main column
266 print '<!-- Begin page content -->' . "\n";
267 print '<td>';
268 print_container_start();
270 <table width="100%">
271 <tr>
272 <td valign="top">