Slightly more helpful message if no courses can be shown.
[moodle-linuxchix.git] / blog / header.php
blobf99ec1cd1329f3ca7324b7f33fdbc0c65461d41a
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 within this page
24 // define('BLOCK_L_MIN_WIDTH', 160);
25 // define('BLOCK_L_MAX_WIDTH', 210);
26 // define('BLOCK_R_MIN_WIDTH', 160);
27 // define('BLOCK_R_MAX_WIDTH', 210);
29 // Bounds for block widths
30 // more flexible for theme designers taken from theme config.php
31 $lmin = (empty($THEME->block_l_min_width)) ? 160 : $THEME->block_l_min_width;
32 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
33 $rmin = (empty($THEME->block_r_min_width)) ? 160 : $THEME->block_r_min_width;
34 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
36 define('BLOCK_L_MIN_WIDTH', $lmin);
37 define('BLOCK_L_MAX_WIDTH', $lmax);
38 define('BLOCK_R_MIN_WIDTH', $rmin);
39 define('BLOCK_R_MAX_WIDTH', $rmax);
41 //_____________ new page class code ________
42 $pagetype = PAGE_BLOG_VIEW;
43 $pageclass = 'page_blog';
45 // map our page identifier to the actual name
46 // of the class which will be handling its operations.
47 page_map_class($pagetype, $pageclass);
49 // Now, create our page object.
50 if (empty($USER->id)) {
51 $PAGE = page_create_object($pagetype);
52 } else {
53 $PAGE = page_create_object($pagetype, $USER->id);
55 $PAGE->courseid = $courseid;
56 $PAGE->filtertype = $filtertype;
57 $PAGE->filterselect = $filterselect;
58 $PAGE->tagid = $tagid;
60 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
62 $editing = false;
63 if ($PAGE->user_allowed_editing()) {
64 $editing = $PAGE->user_is_editing();
67 // Calculate the preferred width for left, right and center (both center positions will use the same)
68 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
69 BLOCK_L_MAX_WIDTH);
70 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
71 BLOCK_R_MAX_WIDTH);
73 // Display the blocks and allow blocklib to handle any block action requested
74 $pageblocks = blocks_get_by_page($PAGE);
76 if ($editing) {
77 if (!empty($blockaction) && confirm_sesskey()) {
78 if (!empty($blockid)) {
79 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
80 } else if (!empty($instanceid)) {
81 $instance = blocks_find_instance($instanceid, $pageblocks);
82 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
84 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
85 // but I'm not sure if it's worth the complexity increase...
86 $pageblocks = blocks_get_by_page($PAGE);
88 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
91 if (!empty($tagid)) {
92 $taginstance = get_record('tags', 'id', $tagid);
93 } else {
94 $tagid = '';
95 if (!empty($tag)) {
96 $tagrec = get_record('tags', 'text', $tag);
97 $tagid = $tagrec->id;
98 $taginstance = get_record('tags', 'id', $tagid);
102 /// navigations
103 /// site blogs - sitefullname -> blogs -> (?tag)
104 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
105 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
106 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
108 $blogstring = get_string('blogs','blog');
109 $tagstring = get_string('tag');
111 // needed also for user tabs later
112 if (!$course = get_record('course', 'id', $courseid)) {
113 error('Wrong course id');
117 /// This is very messy atm.
119 switch ($filtertype) {
120 case 'site':
121 if ($tagid || !empty($tag)) {
122 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
123 '<a href="index.php?filtertype=site">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
124 } else {
125 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
126 $blogstring,'','',true,$PAGE->get_extra_header_string());
128 break;
130 case 'course':
131 if ($tagid || !empty($tag)) {
132 print_header("$course->shortname: $blogstring", $course->fullname,
133 '<a href="index.php?filtertype=course&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
134 } else {
135 print_header("$course->shortname: $blogstring", $course->fullname,
136 $blogstring,'','',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 print_header("$course->shortname: $blogstring", $course->fullname,
145 '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name.'</a> ->
146 <a href="index.php?filtertype=group&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
147 } else {
148 print_header("$course->shortname: $blogstring", $course->fullname,
149 '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name."</a> ->
150 $blogstring",'','',true,$PAGE->get_extra_header_string());
152 } else {
153 print_error('Unable to find group');
156 break;
158 case 'user':
159 $participants = get_string('participants');
160 if (!$user = get_record('user', 'id', $filterselect)) {
161 error('Wrong user id');
164 if ($course->id != SITEID) {
165 if ($tagid || !empty($tag)) {
166 print_header("$course->shortname: $blogstring", $course->fullname,
167 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
168 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
169 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
170 <a href="index.php?courseid='.$course->id.'&amp;filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
172 } else {
173 print_header("$course->shortname: $blogstring", $course->fullname,
174 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
175 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
176 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
177 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
180 } else {
182 //in top view
184 if ($tagid || !empty($tag)) {
185 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
186 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
187 <a href="index.php?filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
189 } else {
190 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
191 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
192 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
197 break;
199 default:
200 error ('Error unknown filtertype');
201 break;
205 // prints the tabs
206 if ($filtertype=='user') {
207 $showroles = true;
208 } else {
209 $showroles = false;
211 $currenttab = 'blogs';
213 require_once($CFG->dirroot .'/user/tabs.php');
216 /// Layout the whole page as three big columns.
217 print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
218 print '<tr valign="top">' . "\n";
220 /// The left column ...
221 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
222 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
223 print '<!-- Begin left side blocks -->' . "\n";
224 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
225 print '<!-- End left side blocks -->' . "\n";
226 print '</td>' . "\n";
229 /// Start main column
230 print '<!-- Begin page content -->' . "\n";
231 print '<td>';
233 <table width="100%">
234 <tr>
235 <td valign="top">