blog (development code)
[moodle.git] / blog / header.php
1 <?php //$Id$
3 global $CFG, $USER;
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 optional_param('blockaction');
12 optional_param('instanceid', 0, PARAM_INT);
13 optional_param('blockid',    0, PARAM_INT);
14 optional_param('groupid',    0, PARAM_INT);
15 optional_param('userid',     0, PARAM_INT);
17 optional_variable($categoryid, '');
18 optional_variable($groupid, '');
19 optional_variable($pageTitle, '');
20 optional_variable($pageHeading, ''/*$site->fullname*/);
21 optional_variable($pageFocus, '');
22 optional_variable($pageMeta, '');
23 optional_variable($pageNavigation, '');
25 if (!isset($courseid)) {
26     $courseid = optional_param('courseid', SITEID, PARAM_INT);
27 }
29 //header('X-Pingback: '. $CFG->wwwroot .'/blog/api.php'."\n");
31 if (!$site = get_site()) {
32     redirect($CFG->wwwroot.'/index.php');
33 }
35 if ($courseid == 0 ) {
36     $courseid = SITEID;
37 }
39 // now check that they are logged in and allowed into the course (if specified)
40 if ($courseid != SITEID) {
41     if (! $course = get_record('course', 'id', $courseid)) {
42         error('The course number was incorrect ('. $courseid .')');
43     }
44     require_login($course->id);
45 }
47 // ensure that if a group is specified that the user is in fact a member of that group
48 /*
49 if ($groupid) {
50     if (!ismember($groupid) && !isteacher($course->id)) {
51         error('You are not a member of the specified group. Group with id#('. $groupid .')');
52     }
53 }*/
55 // Bounds for block widths within this page
56 define('BLOCK_L_MIN_WIDTH', 160);
57 define('BLOCK_L_MAX_WIDTH', 210);
58 define('BLOCK_R_MIN_WIDTH', 160);
59 define('BLOCK_R_MAX_WIDTH', 210);
61 //_____________ new page class code ________
62 $pagetype = PAGE_BLOG_VIEW;
63 $pageclass = 'page_blog';
65 // map our page identifier to the actual name
66 // of the class which will be handling its operations.
67 page_map_class($pagetype, $pageclass);    
69 // Now, create our page object.
70 if (!isset($USER->id)) {
71     $PAGE = page_create_object($pagetype);
72 }
73 else {
74     $PAGE = page_create_object($pagetype, $USER->id);
75 }
76 $PAGE->courseid = $courseid;
77 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
79 if (isset($tagid)) {
80     $taginstance = get_record('tags', 'id', $tagid);
81 } else {
82     $tagid = '';
83 }
84 if (!isset($filtertype)) {
85     $filtertype = 'user';
86     $filterselect = $USER->id;
87 }
89 $blogstring = get_string('blogs','blog');
90 $tagstring = get_string('tag','blog');
92 switch ($filtertype) {
93     case 'site':
94         if ($tagid) {
95             print_header("$site->shortname: $blogstring", "$site->fullname",
96                         '<a href="index.php?filtertype=site">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
97         } else {
98             print_header("$site->shortname: $blogstring", "$site->fullname",
99                         "$blogstring",'','',true,$PAGE->get_extra_header_string());
100         }
101     break;
103     case 'course':
104         if ($tagid) {
105             print_header("$course->shortname: $blogstring", "$course->fullname",
106                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$filterselect.'">'.$course->shortname.'</a> ->
107                         <a href="index.php?filtertype=course&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
108         } else {
109             print_header("$site->shortname: $blogstring", "$site->fullname",
110                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$filterselect.'">'.$course->shortname."</a> ->
111                         $blogstring",'','',true,$PAGE->get_extra_header_string());
112         }
113     break;
115     case 'group':
117         $thisgroup = get_record('groups', 'id', $filterselect);
119         if ($tagid) {
120             print_header("$course->shortname: $blogstring", "$course->fullname",
121                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
122                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name.'</a> ->
123                         <a href="index.php?filtertype=group&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
124         } else {
125             print_header("$course->shortname: $blogstring", "$course->fullname",
126                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
127                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name."</a> ->
128                         $blogstring",'','',true,$PAGE->get_extra_header_string());
130         }
131     
132     break;
134     case 'user':
135         $user = get_record('user', 'id', $filterselect);
136         $participants = get_string('participants');
138         if ($course->id && $course->id != SITEID) {
139             if ($tagid) {
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                         <a href="index.php?courseid='.optional_param('courseid').'&amp;filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
146             } else {
147                 print_header("$course->shortname: $blogstring", "$course->fullname",
148                         '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
149                         <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
150                         <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
151                         '.$blogstring,'','',true,$PAGE->get_extra_header_string());
153             }
155         }
156         //in top view
157         else {
159             if ($tagid) {
160                 print_header("$site->shortname: $blogstring", "$site->fullname",
161                         '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
162                         <a href="index.php?filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
164             } else {
165                 print_header("$site->shortname: $blogstring", "$site->fullname",
166                         '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
167                         '.$blogstring,'','',true,$PAGE->get_extra_header_string());
169             }
170            
171         }
172     break;
174     default:    //user click on add from block
175         print_header("$site->shortname: $blogstring", "$site->fullname",
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());
178     break;
182 /// site blogs - sitefullname -> blogs -> (?tag)
183 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
184 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
185 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
187 $editing = false;
188 if ($PAGE->user_allowed_editing()) {
189     $editing = $PAGE->user_is_editing();
192 // Calculate the preferred width for left, right and center (both center positions will use the same)
193 optional_variable($preferred_width_left,  blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]));
194 optional_variable($preferred_width_right, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]));
195 $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH);
196 $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH);
197 $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
198 $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);
200 // Display the blocks and allow blocklib to handle any block action requested
201 $pageblocks = blocks_get_by_page($PAGE);
203 if ($editing) {
204     if (!empty($blockaction) && confirm_sesskey()) {
205         if (!empty($blockid)) {
206             blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
207         } else if (!empty($instanceid)) {
208             $instance = blocks_find_instance($instanceid, $pageblocks);
209             blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
210         }
211         // This re-query could be eliminated by judicious programming in blocks_execute_action(),
212         // but I'm not sure if it's worth the complexity increase...
213         $pageblocks = blocks_get_by_page($PAGE);
214     }
215     $missingblocks = blocks_get_missing($PAGE, $pageblocks);
218 /// Layout the whole page as three big columns.
219 print '<table border="0" cellpadding="3" cellspacing="0" width="100%">' . "\n";
220 print '<tr valign="top">' . "\n";
222 /// The left column ...
223 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
224     print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;">' . "\n";
225     print '<!-- Begin left side blocks -->' . "\n";
226     blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
227     print '<!-- End left side blocks -->' . "\n";
228     print '</td>' . "\n";
231 /// Start main column
232 print '<!-- Begin page content -->' . "\n";
233 print '<td width="*">';
234 ?>
235 <table width="100%">
236 <tr>
237 <td height="100%" valign="top">