f5f84c12e2b5c3a77bb843a796a30f43f104300e
[moodle.git] / blog / header.php
1 <?php //$Id$
3 require_once($CFG->dirroot .'/blog/lib.php');
4 require_once($CFG->libdir .'/pagelib.php');
5 require_once($CFG->dirroot .'/blog/blogpage.php');
6 require_once($CFG->libdir .'/blocklib.php');
7 require_once($CFG->dirroot .'/course/lib.php');
9 $blockaction = optional_param('blockaction','', PARAM_ALPHA);
10 $instanceid = optional_param('instanceid', 0, PARAM_INT);
11 $blockid = optional_param('blockid',    0, PARAM_INT);
12 $groupid = optional_param('groupid',    0, PARAM_INT);
14 if (!isset($userid)) {
15     $userid = optional_param('userid',     0, PARAM_INT);
16 }
18 if (!isset($courseid)) {
19     $courseid = optional_param('courseid', SITEID, PARAM_INT);
20 }
22 if (!$site = get_site()) {
23     redirect($CFG->wwwroot.'/index.php');
24 }
26 if ($courseid == 0 ) {
27     $courseid = SITEID;
28 }
30 // now check that they are logged in and allowed into the course (if specified)
31 if ($courseid != SITEID) {
32     if (! $course = get_record('course', 'id', $courseid)) {
33         error('The course number was incorrect ('. $courseid .')');
34     }
35     require_login($course->id);
36 }
38 // Bounds for block widths within this page
39 define('BLOCK_L_MIN_WIDTH', 160);
40 define('BLOCK_L_MAX_WIDTH', 210);
41 define('BLOCK_R_MIN_WIDTH', 160);
42 define('BLOCK_R_MAX_WIDTH', 210);
44 //_____________ new page class code ________
45 $pagetype = PAGE_BLOG_VIEW;
46 $pageclass = 'page_blog';
48 // map our page identifier to the actual name
49 // of the class which will be handling its operations.
50 page_map_class($pagetype, $pageclass);    
52 // Now, create our page object.
53 if (!isset($USER->id)) {
54     $PAGE = page_create_object($pagetype);
55 }
56 else {
57     $PAGE = page_create_object($pagetype, $USER->id);
58 }
59 $PAGE->courseid = $courseid;
60 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
62 if (!empty($tagid)) {
63     $taginstance = get_record('tags', 'id', $tagid);
64 } else {
65     $tagid = '';
66     if (!empty($tag)) {
67         $tagrec = get_record('tags', 'text', $tag);
68         $tagid = $tagrec->id;
69         $taginstance = get_record('tags', 'id', $tagid);
70     }
71 }
72 if (!isset($filtertype)) {
73     $filtertype = 'user';
74     $filterselect = $USER->id;
75 }
77 /// navigations
78 /// site blogs - sitefullname -> blogs -> (?tag)
79 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
80 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
81 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
82 $blogstring = get_string('blogs','blog');
83 $tagstring = get_string('tag');
85 switch ($filtertype) {
86     case 'site':
87         if ($tagid || !empty($tag)) {
88             print_header("$site->shortname: $blogstring", "$site->fullname",
89                         '<a href="index.php?filtertype=site">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
90         } else {
91             print_header("$site->shortname: $blogstring", "$site->fullname",
92                         "$blogstring",'','',true,$PAGE->get_extra_header_string());
93         }
94     break;
96     case 'course':
97         if ($tagid || !empty($tag)) {
98             print_header("$course->shortname: $blogstring", "$course->fullname",
99                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$filterselect.'">'.$course->shortname.'</a> ->
100                         <a href="index.php?filtertype=course&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
101         } else {
102             print_header("$site->shortname: $blogstring", "$site->fullname",
103                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$filterselect.'">'.$course->shortname."</a> ->
104                         $blogstring",'','',true,$PAGE->get_extra_header_string());
105         }
106     break;
108     case 'group':
110         $thisgroup = get_record('groups', 'id', $filterselect);
112         if ($tagid || !empty($tag)) {
113             print_header("$course->shortname: $blogstring", "$course->fullname",
114                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
115                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name.'</a> ->
116                         <a href="index.php?filtertype=group&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
117         } else {
118             print_header("$course->shortname: $blogstring", "$course->fullname",
119                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
120                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name."</a> ->
121                         $blogstring",'','',true,$PAGE->get_extra_header_string());
123         }
124     
125     break;
127     case 'user':
128         $user = get_record('user', 'id', $filterselect);
129         $participants = get_string('participants');
131         if (isset($course->id) && $course->id && $course->id != SITEID) {
132             if ($tagid || !empty($tag)) {
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                         <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());
139             } else {
140                 print_header("$course->shortname: $blogstring", "$course->fullname",
141                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
142                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
143                         <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
144                         '.$blogstring,'','',true,$PAGE->get_extra_header_string());
146             }
148         }
149         //in top view
150         else {
152             if ($tagid || !empty($tag)) {
153                 print_header("$site->shortname: $blogstring", "$site->fullname",
154                         '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
155                         <a href="index.php?filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
157             } else {
158                 print_header("$site->shortname: $blogstring", "$site->fullname",
159                         '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
160                         '.$blogstring,'','',true,$PAGE->get_extra_header_string());
162             }
163            
164         }
165     break;
167     default:    //user click on add from block
168         print_header("$site->shortname: $blogstring", "$site->fullname",
169                         '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
170                         '.$blogstring,'','',true,$PAGE->get_extra_header_string());
171     break;
174 $editing = false;
175 if ($PAGE->user_allowed_editing()) {
176     $editing = $PAGE->user_is_editing();
179 // Calculate the preferred width for left, right and center (both center positions will use the same)
180 $preferred_width_left = optional_param('preferred_width_left',  blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), PARAM_INT);
181 $preferred_width_right = optional_param('preferred_width_right', blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), PARAM_INT);
182 $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH);
183 $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH);
184 $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
185 $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);
187 // Display the blocks and allow blocklib to handle any block action requested
188 $pageblocks = blocks_get_by_page($PAGE);
190 if ($editing) {
191     if (!empty($blockaction) && confirm_sesskey()) {
192         if (!empty($blockid)) {
193             blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
194         } else if (!empty($instanceid)) {
195             $instance = blocks_find_instance($instanceid, $pageblocks);
196             blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
197         }
198         // This re-query could be eliminated by judicious programming in blocks_execute_action(),
199         // but I'm not sure if it's worth the complexity increase...
200         $pageblocks = blocks_get_by_page($PAGE);
201     }
202     $missingblocks = blocks_get_missing($PAGE, $pageblocks);
205 /// Layout the whole page as three big columns.
206 print '<table border="0" cellpadding="3" cellspacing="0" width="100%">' . "\n";
207 print '<tr valign="top">' . "\n";
209 /// The left column ...
210 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
211     print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;">' . "\n";
212     print '<!-- Begin left side blocks -->' . "\n";
213     blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
214     print '<!-- End left side blocks -->' . "\n";
215     print '</td>' . "\n";
218 /// Start main column
219 print '<!-- Begin page content -->' . "\n";
220 print '<td width="*">';
221 ?>
222 <table width="100%">
223 <tr>
224 <td height="100%" valign="top">