MDL-8100, defaultgrade not imported.\rQuestion obect initialisation and value import...
[moodle-linuxchix.git] / blog / header.php
bloba5c1002bdf39c9ab21eeb90ed7a7ab0eae4afe88
1 <?php //$Id$
3 /// Sets up blocks and navigation for index.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 if (!$course = get_record('course', 'id', $courseid)) {
20 error('The course number was incorrect ('. $courseid .')');
23 // Bounds for block widths within this page
24 define('BLOCK_L_MIN_WIDTH', 160);
25 define('BLOCK_L_MAX_WIDTH', 210);
26 define('BLOCK_R_MIN_WIDTH', 160);
27 define('BLOCK_R_MAX_WIDTH', 210);
29 //_____________ new page class code ________
30 $pagetype = PAGE_BLOG_VIEW;
31 $pageclass = 'page_blog';
33 // map our page identifier to the actual name
34 // of the class which will be handling its operations.
35 page_map_class($pagetype, $pageclass);
37 // Now, create our page object.
38 if (empty($USER->id)) {
39 $PAGE = page_create_object($pagetype);
40 } else {
41 $PAGE = page_create_object($pagetype, $USER->id);
43 $PAGE->courseid = $courseid;
44 $PAGE->filtertype = $filtertype;
45 $PAGE->filterselect = $filterselect;
46 $PAGE->tagid = $tagid;
48 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
50 $editing = false;
51 if ($PAGE->user_allowed_editing()) {
52 $editing = $PAGE->user_is_editing();
55 // Calculate the preferred width for left, right and center (both center positions will use the same)
56 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
57 BLOCK_L_MAX_WIDTH);
58 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
59 BLOCK_R_MAX_WIDTH);
61 // Display the blocks and allow blocklib to handle any block action requested
62 $pageblocks = blocks_get_by_page($PAGE);
64 if ($editing) {
65 if (!empty($blockaction) && confirm_sesskey()) {
66 if (!empty($blockid)) {
67 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
68 } else if (!empty($instanceid)) {
69 $instance = blocks_find_instance($instanceid, $pageblocks);
70 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
72 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
73 // but I'm not sure if it's worth the complexity increase...
74 $pageblocks = blocks_get_by_page($PAGE);
76 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
79 if (!empty($tagid)) {
80 $taginstance = get_record('tags', 'id', $tagid);
81 } else {
82 $tagid = '';
83 if (!empty($tag)) {
84 $tagrec = get_record('tags', 'text', $tag);
85 $tagid = $tagrec->id;
86 $taginstance = get_record('tags', 'id', $tagid);
90 /// navigations
91 /// site blogs - sitefullname -> blogs -> (?tag)
92 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
93 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
94 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
96 $blogstring = get_string('blogs','blog');
97 $tagstring = get_string('tag');
99 // needed also for user tabs later
100 if (!$course = get_record('course', 'id', $courseid)) {
101 error('Wrong course id');
105 /// This is very messy atm.
107 switch ($filtertype) {
108 case 'site':
109 if ($tagid || !empty($tag)) {
110 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
111 '<a href="index.php?filtertype=site">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
112 } else {
113 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
114 $blogstring,'','',true,$PAGE->get_extra_header_string());
116 break;
118 case 'course':
119 if ($tagid || !empty($tag)) {
120 print_header("$course->shortname: $blogstring", $course->fullname,
121 '<a href="index.php?filtertype=course&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
122 } else {
123 print_header("$course->shortname: $blogstring", $course->fullname,
124 $blogstring,'','',true,$PAGE->get_extra_header_string());
126 break;
128 case 'group':
130 if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
131 if ($tagid || !empty($tag)) {
132 print_header("$course->shortname: $blogstring", $course->fullname,
133 '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name.'</a> ->
134 <a href="index.php?filtertype=group&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
135 } else {
136 print_header("$course->shortname: $blogstring", $course->fullname,
137 '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect.'">'.$thisgroup->name."</a> ->
138 $blogstring",'','',true,$PAGE->get_extra_header_string());
140 } else {
141 print_error('Unable to find group');
144 break;
146 case 'user':
147 $participants = get_string('participants');
148 if (!$user = get_record('user', 'id', $filterselect)) {
149 error('Wrong user id');
152 if ($course->id != SITEID) {
153 if ($tagid || !empty($tag)) {
154 print_header("$course->shortname: $blogstring", $course->fullname,
155 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
156 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
157 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
158 <a href="index.php?courseid='.$course->id.'&amp;filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
160 } else {
161 print_header("$course->shortname: $blogstring", $course->fullname,
162 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->
163 <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'">'.$participants.'</a> ->
164 <a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'&amp;course='.$course->id.'">'.fullname($user).'</a> ->
165 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
168 } else {
170 //in top view
172 if ($tagid || !empty($tag)) {
173 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
174 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
175 <a href="index.php?filtertype=user&amp;filterselect='.$filterselect.'">'. "$blogstring</a> -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
177 } else {
178 print_header("$SITE->shortname: $blogstring", $SITE->fullname,
179 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$filterselect.'">'.fullname($user).'</a> ->
180 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
185 break;
187 default:
188 error ('Error unknown filtertype');
189 break;
193 // prints the tabs
194 if ($filtertype=='user') {
195 $showroles = true;
196 } else {
197 $showroles = false;
199 $currenttab = 'blogs';
201 require_once($CFG->dirroot .'/user/tabs.php');
204 /// Layout the whole page as three big columns.
205 print '<table border="0" cellpadding="3" cellspacing="0" width="100%">' . "\n";
206 print '<tr valign="top">' . "\n";
208 /// The left column ...
209 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
210 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;">' . "\n";
211 print '<!-- Begin left side blocks -->' . "\n";
212 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
213 print '<!-- End left side blocks -->' . "\n";
214 print '</td>' . "\n";
217 /// Start main column
218 print '<!-- Begin page content -->' . "\n";
219 print '<td width="*">';
221 <table width="100%">
222 <tr>
223 <td height="100%" valign="top">