Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / blog / header.php
blobd891f961de3a92269432cbf27069cdefb2243ae6
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('tags', 'id', $tagid);
91 } else {
92 $tagid = '';
93 if (!empty($tag)) {
94 $tagrec = get_record('tags', 'text', $tag);
95 $tagid = $tagrec->id;
96 $taginstance = get_record('tags', 'id', $tagid);
100 /// navigations
101 /// site blogs - sitefullname -> blogs -> (?tag)
102 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
103 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
104 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
106 $blogstring = get_string('blogs','blog');
107 $tagstring = get_string('tag');
109 // needed also for user tabs later
110 if (!$course = get_record('course', 'id', $courseid)) {
111 error('Wrong course id');
115 /// This is very messy atm.
117 switch ($filtertype) {
118 case 'site':
119 if ($tagid || !empty($tag)) {
120 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
121 '<a href="index.php?filtertype=site">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
122 } else {
123 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
124 $blogstring,'','',true,$PAGE->get_extra_header_string());
126 break;
128 case 'course':
129 if ($tagid || !empty($tag)) {
130 print_header("$course->shortname: $blogstring", $course->fullname,
131 '<a href="index.php?filtertype=course&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
132 } else {
133 print_header("$course->shortname: $blogstring", $course->fullname,
134 $blogstring,'','',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 print_header("$course->shortname: $blogstring", $course->fullname,
143 '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name.'</a> ->
144 <a href="index.php?filtertype=group&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
145 } else {
146 print_header("$course->shortname: $blogstring", $course->fullname,
147 '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name."</a> ->
148 $blogstring",'','',true,$PAGE->get_extra_header_string());
150 } else {
151 print_error('Unable to find group');
154 break;
156 case 'user':
157 $participants = get_string('participants');
158 if (!$user = get_record('user', 'id', $filterselect)) {
159 error('Wrong user id');
162 if ($course->id != SITEID) {
163 if ($tagid || !empty($tag)) {
164 print_header("$course->shortname: $blogstring", $course->fullname,
165 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
166 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
167 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
168 <a href="index.php?courseid='.$course->id.'&amp;filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
170 } else {
171 print_header("$course->shortname: $blogstring", $course->fullname,
172 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
173 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
174 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
175 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
178 } else {
180 //in top view
182 if ($tagid || !empty($tag)) {
183 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
184 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
185 <a href="index.php?filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
187 } else {
188 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
189 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
190 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
195 break;
197 default:
198 error ('Error unknown filtertype');
199 break;
203 // prints the tabs
204 if ($filtertype=='user') {
205 $showroles = true;
206 } else {
207 $showroles = false;
209 $currenttab = 'blogs';
211 require_once($CFG->dirroot .'/user/tabs.php');
214 /// Layout the whole page as three big columns.
215 print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
216 print '<tr valign="top">' . "\n";
218 /// The left column ...
219 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
220 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
221 print '<!-- Begin left side blocks -->' . "\n";
222 if (!empty($THEME->customcorners)) print_custom_corners_start();
223 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
224 if (!empty($THEME->customcorners)) print_custom_corners_end();
225 print '<!-- End left side blocks -->' . "\n";
226 print '</td>' . "\n";
229 /// Start main column
230 print '<!-- Begin page content -->' . "\n";
231 print '<td>';
232 if (!empty($THEME->customcorners)) print_custom_corners_start();
234 <table width="100%">
235 <tr>
236 <td valign="top">