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