small fix and cleaning
[moodle.git] / blog / header.php
1 <?php //$Id$
3 /// Sets up blocks and navigation for index.php, edit.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 (!$site = get_site()) {
16     redirect($CFG->wwwroot.'/index.php');
17 }
19 if ($courseid == 0 ) {
20     $courseid = SITEID;
21 }
23 // now check that they are logged in and allowed into the course (if specified)
24 if ($courseid != SITEID) {
25     if (! $course = get_record('course', 'id', $courseid)) {
26         error('The course number was incorrect ('. $courseid .')');
27     }
28     require_login($course->id);
29 }
31 // Bounds for block widths within this page
32 define('BLOCK_L_MIN_WIDTH', 160);
33 define('BLOCK_L_MAX_WIDTH', 210);
34 define('BLOCK_R_MIN_WIDTH', 160);
35 define('BLOCK_R_MAX_WIDTH', 210);
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 (!isset($USER->id)) {
47     $PAGE = page_create_object($pagetype);
48 }
49 else {
50     $PAGE = page_create_object($pagetype, $USER->id);
51 }
52 $PAGE->courseid = $courseid;
53 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
55 if (!empty($tagid)) {
56     $taginstance = get_record('tags', 'id', $tagid);
57 } else {
58     $tagid = '';
59     if (!empty($tag)) {
60         $tagrec = get_record('tags', 'text', $tag);
61         $tagid = $tagrec->id;
62         $taginstance = get_record('tags', 'id', $tagid);
63     }
64 }
65 if (!isset($filtertype)) {
66     $filtertype = 'user';
67     $filterselect = $USER->id;
68 }
70 /// navigations
71 /// site blogs - sitefullname -> blogs -> (?tag)
72 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
73 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
74 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
75 $blogstring = get_string('blogs','blog');
76 $tagstring = get_string('tag');
78 switch ($filtertype) {
79     case 'site':
80         if ($tagid || !empty($tag)) {
81             print_header("$site->shortname: $blogstring", "$site->fullname",
82                         '<a href="index.php?filtertype=site">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
83         } else {
84             print_header("$site->shortname: $blogstring", "$site->fullname",
85                         "$blogstring",'','',true,$PAGE->get_extra_header_string());
86         }
87     break;
89     case 'course':
90         if ($tagid || !empty($tag)) {
91             print_header("$course->shortname: $blogstring", "$course->fullname",
92                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$filterselect.'">'.$course->shortname.'</a> ->
93                         <a href="index.php?filtertype=course&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
94         } else {
95             print_header("$site->shortname: $blogstring", "$site->fullname",
96                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$filterselect.'">'.$course->shortname."</a> ->
97                         $blogstring",'','',true,$PAGE->get_extra_header_string());
98         }
99     break;
101     case 'group':
103         $thisgroup = get_record('groups', 'id', $filterselect);
105         if ($tagid || !empty($tag)) {
106             print_header("$course->shortname: $blogstring", "$course->fullname",
107                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
108                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name.'</a> ->
109                         <a href="index.php?filtertype=group&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
110         } else {
111             print_header("$course->shortname: $blogstring", "$course->fullname",
112                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
113                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name."</a> ->
114                         $blogstring",'','',true,$PAGE->get_extra_header_string());
116         }
117     
118     break;
120     case 'user':
121         $user = get_record('user', 'id', $filterselect);
122         $participants = get_string('participants');
124         if (isset($course->id) && $course->id && $course->id != SITEID) {
125             if ($tagid || !empty($tag)) {
126                 print_header("$course->shortname: $blogstring", "$course->fullname",
127                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
128                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
129                         <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
130                         <a href="index.php?courseid='.optional_param('courseid', 0, PARAM_INT).'&amp;filtertype=user&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                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
135                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
136                         <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
137                         '.$blogstring,'','',true,$PAGE->get_extra_header_string());
139             }
141         }
142         //in top view
143         else {
145             if ($tagid || !empty($tag)) {
146                 print_header("$site->shortname: $blogstring", "$site->fullname",
147                         '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
148                         <a href="index.php?filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
150             } else {
151                 print_header("$site->shortname: $blogstring", "$site->fullname",
152                         '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
153                         '.$blogstring,'','',true,$PAGE->get_extra_header_string());
155             }
156            
157         }
158     break;
160     default:    //user click on add from block
161         print_header("$site->shortname: $blogstring", "$site->fullname",
162                         '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
163                         '.$blogstring,'','',true,$PAGE->get_extra_header_string());
164     break;
167 $editing = false;
168 if ($PAGE->user_allowed_editing()) {
169     $editing = $PAGE->user_is_editing();
172 // Calculate the preferred width for left, right and center (both center positions will use the same)
173 $preferred_width_left = optional_param('preferred_width_left',  blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), PARAM_INT);
174 $preferred_width_right = optional_param('preferred_width_right', blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), PARAM_INT);
175 $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH);
176 $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH);
177 $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
178 $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);
180 // Display the blocks and allow blocklib to handle any block action requested
181 $pageblocks = blocks_get_by_page($PAGE);
183 if ($editing) {
184     if (!empty($blockaction) && confirm_sesskey()) {
185         if (!empty($blockid)) {
186             blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
187         } else if (!empty($instanceid)) {
188             $instance = blocks_find_instance($instanceid, $pageblocks);
189             blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
190         }
191         // This re-query could be eliminated by judicious programming in blocks_execute_action(),
192         // but I'm not sure if it's worth the complexity increase...
193         $pageblocks = blocks_get_by_page($PAGE);
194     }
195     $missingblocks = blocks_get_missing($PAGE, $pageblocks);
198 /// Layout the whole page as three big columns.
199 print '<table border="0" cellpadding="3" cellspacing="0" width="100%">' . "\n";
200 print '<tr valign="top">' . "\n";
202 /// The left column ...
203 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
204     print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;">' . "\n";
205     print '<!-- Begin left side blocks -->' . "\n";
206     blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
207     print '<!-- End left side blocks -->' . "\n";
208     print '</td>' . "\n";
211 /// Start main column
212 print '<!-- Begin page content -->' . "\n";
213 print '<td width="*">';
214 ?>
215 <table width="100%">
216 <tr>
217 <td height="100%" valign="top">