small fix and cleaning
[moodle.git] / blog / header.php
CommitLineData
4a173181 1<?php //$Id$
2
eccfc1ca 3/// Sets up blocks and navigation for index.php, edit.php
4
4a173181 5require_once($CFG->dirroot .'/blog/lib.php');
6require_once($CFG->libdir .'/pagelib.php');
7require_once($CFG->dirroot .'/blog/blogpage.php');
8require_once($CFG->libdir .'/blocklib.php');
9require_once($CFG->dirroot .'/course/lib.php');
10
5c625033 11$blockaction = optional_param('blockaction','', PARAM_ALPHA);
9154b440 12$instanceid = optional_param('instanceid', 0, PARAM_INT);
13$blockid = optional_param('blockid', 0, PARAM_INT);
4a173181 14
4a173181 15if (!$site = get_site()) {
16 redirect($CFG->wwwroot.'/index.php');
17}
18
19if ($courseid == 0 ) {
20 $courseid = SITEID;
21}
22
23// now check that they are logged in and allowed into the course (if specified)
24if ($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}
30
4a173181 31// Bounds for block widths within this page
32define('BLOCK_L_MIN_WIDTH', 160);
33define('BLOCK_L_MAX_WIDTH', 210);
34define('BLOCK_R_MIN_WIDTH', 160);
35define('BLOCK_R_MAX_WIDTH', 210);
36
37//_____________ new page class code ________
38$pagetype = PAGE_BLOG_VIEW;
39$pageclass = 'page_blog';
40
41// map our page identifier to the actual name
42// of the class which will be handling its operations.
43page_map_class($pagetype, $pageclass);
44
45// Now, create our page object.
46if (!isset($USER->id)) {
47 $PAGE = page_create_object($pagetype);
48}
49else {
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
54
91366ca7 55if (!empty($tagid)) {
4a173181 56 $taginstance = get_record('tags', 'id', $tagid);
57} else {
58 $tagid = '';
91366ca7 59 if (!empty($tag)) {
40b6323c 60 $tagrec = get_record('tags', 'text', $tag);
61 $tagid = $tagrec->id;
62 $taginstance = get_record('tags', 'id', $tagid);
63 }
4a173181 64}
65if (!isset($filtertype)) {
66 $filtertype = 'user';
67 $filterselect = $USER->id;
68}
69
9154b440 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)
4a173181 75$blogstring = get_string('blogs','blog');
25a78406 76$tagstring = get_string('tag');
4a173181 77
78switch ($filtertype) {
79 case 'site':
91366ca7 80 if ($tagid || !empty($tag)) {
4a173181 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;
88
89 case 'course':
91366ca7 90 if ($tagid || !empty($tag)) {
4a173181 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;
100
101 case 'group':
102
103 $thisgroup = get_record('groups', 'id', $filterselect);
104
91366ca7 105 if ($tagid || !empty($tag)) {
4a173181 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());
115
116 }
117
118 break;
119
120 case 'user':
121 $user = get_record('user', 'id', $filterselect);
122 $participants = get_string('participants');
123
dcd0d143 124 if (isset($course->id) && $course->id && $course->id != SITEID) {
91366ca7 125 if ($tagid || !empty($tag)) {
4a173181 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> ->
5c625033 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());
4a173181 131
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());
138
139 }
140
141 }
142 //in top view
143 else {
144
91366ca7 145 if ($tagid || !empty($tag)) {
4a173181 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());
149
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());
154
155 }
156
157 }
158 break;
159
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;
165}
166
4a173181 167$editing = false;
168if ($PAGE->user_allowed_editing()) {
169 $editing = $PAGE->user_is_editing();
170}
171
172// Calculate the preferred width for left, right and center (both center positions will use the same)
5c625033 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);
4a173181 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);
179
180// Display the blocks and allow blocklib to handle any block action requested
181$pageblocks = blocks_get_by_page($PAGE);
182
183if ($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);
196}
197
198/// Layout the whole page as three big columns.
199print '<table border="0" cellpadding="3" cellspacing="0" width="100%">' . "\n";
200print '<tr valign="top">' . "\n";
201
202/// The left column ...
203if (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";
209}
210
211/// Start main column
212print '<!-- Begin page content -->' . "\n";
213print '<td width="*">';
214?>
215<table width="100%">
216<tr>
217<td height="100%" valign="top">