Automatic installer.php lang files by installer_builder (20090120)
[moodle.git] / blog / header.php
blob1cd06b54ed674e7d1077862417afc830266ed5fd
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 user has never visited this page before, install 2 blocks for him
16 blog_check_and_install_blocks();
19 // now check that they are logged in and allowed into the course (if specified)
20 if ($courseid != SITEID) {
21 if (!$course = get_record('course', 'id', $courseid)) {
22 error('The course number was incorrect ('. $courseid .')');
24 require_login($course->id);
25 } else {
26 $course = $SITE;
29 // Bounds for block widths within this page
30 define('BLOCK_L_MIN_WIDTH', 160);
31 define('BLOCK_L_MAX_WIDTH', 210);
32 define('BLOCK_R_MIN_WIDTH', 160);
33 define('BLOCK_R_MAX_WIDTH', 210);
35 //_____________ new page class code ________
36 $pagetype = PAGE_BLOG_VIEW;
37 $pageclass = 'page_blog';
39 // map our page identifier to the actual name
40 // of the class which will be handling its operations.
41 page_map_class($pagetype, $pageclass);
43 // Now, create our page object.
44 if (!isset($USER->id)) {
45 $PAGE = page_create_object($pagetype);
46 } else {
47 $PAGE = page_create_object($pagetype, $USER->id);
49 $PAGE->courseid = $courseid;
50 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
52 if (!empty($tagid)) {
53 $taginstance = get_record('tags', 'id', $tagid);
54 } else {
55 $tagid = '';
56 if (!empty($tag)) {
57 $tagrec = get_record('tags', 'text', $tag);
58 $tagid = $tagrec->id;
59 $taginstance = get_record('tags', 'id', $tagid);
62 if (!isset($filtertype)) {
63 $filtertype = 'user';
64 $filterselect = $USER->id;
67 /// navigations
68 /// site blogs - sitefullname -> blogs -> (?tag)
69 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
70 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
71 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
73 $blogstring = get_string('blogs','blog');
74 $tagstring = get_string('tag');
76 if ($ME == $CFG->wwwroot.'/blog/edit.php') { /// We are in edit mode, print the editing header
78 // first we need to identify the user
79 if ($editid) { // if we are editing a post
80 $blogEntry = get_record('post','id',$editid);
81 $user = get_record('user','id',$blogEntry->userid);
82 } else {
83 $user = get_record('user','id',$filterselect);
86 if ($editid) {
87 $formHeading = get_string('updateentrywithid', 'blog');
88 } else {
89 $formHeading = get_string('addnewentry', 'blog');
92 print_header("$SITE->shortname: $blogstring", "$SITE->fullname",
93 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
94 <a href="'.$CFG->wwwroot.'/blog/index.php?userid='.$user->id.'">'.$blogstring.'</a> -> '. $formHeading,'','',true);
96 } else { // else, we are in view mode
98 /// This is very messy atm.
100 switch ($filtertype) {
101 case 'site':
102 if ($tagid || !empty($tag)) {
103 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
104 '<a href="index.php?filtertype=site">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
105 } else {
106 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
107 $blogstring,'','',true,$PAGE->get_extra_header_string());
109 break;
111 case 'course':
112 if ($tagid || !empty($tag)) {
113 print_header("$course->shortname: $blogstring", $course->fullname,
114 '<a href="index.php?filtertype=course&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
115 } else {
116 print_header("$course->shortname: $blogstring", $course->fullname,
117 $blogstring,'','',true,$PAGE->get_extra_header_string());
119 break;
121 case 'group':
123 $thisgroup = get_record('groups', 'id', $filterselect);
125 if ($tagid || !empty($tag)) {
126 print_header("$course->shortname: $blogstring", $course->fullname,
127 '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name.'</a> ->
128 <a href="index.php?filtertype=group&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
129 } else {
130 print_header("$course->shortname: $blogstring", $course->fullname,
131 '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name."</a> ->
132 $blogstring",'','',true,$PAGE->get_extra_header_string());
136 break;
138 case 'user':
139 $user = get_record('user', 'id', $filterselect);
140 $participants = get_string('participants');
142 if (isset($course->id) && $course->id && $course->id != SITEID) {
143 if ($tagid || !empty($tag)) {
144 print_header("$course->shortname: $blogstring", $course->fullname,
145 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
146 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
147 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
148 <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());
150 } else {
151 print_header("$course->shortname: $blogstring", $course->fullname,
152 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
153 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
154 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
155 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
159 //in top view
160 else {
162 if ($tagid || !empty($tag)) {
163 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
164 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
165 <a href="index.php?filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
167 } else {
168 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
169 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
170 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
175 break;
177 default: //user click on add from block
178 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
179 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
180 <a href="'.$CFG->wwwroot.'/blog/index.php?userid='.$user->id.'">'.$blogstring.'</a> -> '.get_string('addentry','blog'),'','',true,$PAGE->get_extra_header_string());
181 break;
184 } /// close switch
186 // prints the tabs
187 $currenttab = 'blogs';
188 $user = $USER;
189 if (!$course) {
190 $course = get_record('course','id',optional_param('courseid', SITEID, PARAM_INT));
192 require_once($CFG->dirroot .'/user/tabs.php');
194 $editing = false;
195 if ($PAGE->user_allowed_editing()) {
196 $editing = $PAGE->user_is_editing();
199 // Calculate the preferred width for left, right and center (both center positions will use the same)
200 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
201 BLOCK_L_MAX_WIDTH);
202 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
203 BLOCK_R_MAX_WIDTH);
205 // Display the blocks and allow blocklib to handle any block action requested
206 $pageblocks = blocks_get_by_page($PAGE);
208 if ($editing) {
209 if (!empty($blockaction) && confirm_sesskey()) {
210 if (!empty($blockid)) {
211 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
212 } else if (!empty($instanceid)) {
213 $instance = blocks_find_instance($instanceid, $pageblocks);
214 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
216 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
217 // but I'm not sure if it's worth the complexity increase...
218 $pageblocks = blocks_get_by_page($PAGE);
220 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
223 /// Layout the whole page as three big columns.
224 print '<table border="0" cellpadding="3" cellspacing="0" width="100%">' . "\n";
225 print '<tr valign="top">' . "\n";
227 /// The left column ...
228 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
229 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;">' . "\n";
230 print '<!-- Begin left side blocks -->' . "\n";
231 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
232 print '<!-- End left side blocks -->' . "\n";
233 print '</td>' . "\n";
236 /// Start main column
237 print '<!-- Begin page content -->' . "\n";
238 print '<td width="*">';
240 <table width="100%">
241 <tr>
242 <td height="100%" valign="top">