forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.php
executable file
·266 lines (223 loc) · 11.6 KB
/
header.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php //$Id$
/// Sets up blocks and navigation for index.php
require_once($CFG->dirroot .'/blog/lib.php');
require_once($CFG->dirroot .'/blog/blogpage.php');
require_once($CFG->dirroot .'/course/lib.php');
$blockaction = optional_param('blockaction','', PARAM_ALPHA);
$instanceid = optional_param('instanceid', 0, PARAM_INT);
$blockid = optional_param('blockid', 0, PARAM_INT);
/// If user has never visited this page before, install 2 blocks for him
blog_check_and_install_blocks();
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid', '', '', $courseid);
}
// Bounds for block widths
// more flexible for theme designers taken from theme config.php
$lmin = (empty($THEME->block_l_min_width)) ? 160 : $THEME->block_l_min_width;
$lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
$rmin = (empty($THEME->block_r_min_width)) ? 160 : $THEME->block_r_min_width;
$rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
define('BLOCK_L_MIN_WIDTH', $lmin);
define('BLOCK_L_MAX_WIDTH', $lmax);
define('BLOCK_R_MIN_WIDTH', $rmin);
define('BLOCK_R_MAX_WIDTH', $rmax);
//_____________ new page class code ________
$pagetype = PAGE_BLOG_VIEW;
$pageclass = 'page_blog';
// map our page identifier to the actual name
// of the class which will be handling its operations.
page_map_class($pagetype, $pageclass);
// Now, create our page object.
if (empty($USER->id)) {
$PAGE = page_create_object($pagetype);
} else {
$PAGE = page_create_object($pagetype, $USER->id);
}
$PAGE->set_course($course);
$PAGE->filtertype = $filtertype;
$PAGE->filterselect = $filterselect;
$PAGE->tagid = $tagid;
$array = array();
if (!empty($course->id)) {
$array['courseid'] = $course->id;
}
if (!empty($filtertype)) {
$array['filtertype'] = $filtertype;
}
if (!empty($filterselect)) {
$array['filterselect'] = $filterselect;
}
if (!empty($tagid)) {
$array['tagid'] = $tagid;
}
$PAGE->set_url('blog/index.php', $array);
$PAGE->set_blocks_editing_capability('moodle/blog:create');
$PAGE->init_full(); //init the BlogInfo object and the courserecord object
$editing = false;
if ($PAGE->user_allowed_editing()) {
$editing = $PAGE->user_is_editing();
}
// Calculate the preferred width for left, right and center (both center positions will use the same)
$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
BLOCK_L_MAX_WIDTH);
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
BLOCK_R_MAX_WIDTH);
if (!empty($tagid)) {
$taginstance = $DB->get_record('tag', array('id'=>$tagid));
} elseif (!empty($tag)) {
$taginstance = tag_id($tag);
}
/// navigations
/// site blogs - sitefullname -> blogs -> (?tag)
/// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
/// group blogs - sitefullname -> course fullname ->group ->(?tag)
/// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
$blogstring = get_string('blogs','blog');
$tagstring = get_string('tag');
// needed also for user tabs later
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid', '', '', $courseid);
}
$navlinks = array();
/// This is very messy atm.
switch ($filtertype) {
case 'site':
if ($tagid || !empty($tag)) {
$navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
} else {
$navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
}
break;
case 'course':
if ($tagid || !empty($tag)) {
$navlinks[] = array('name' => $blogstring,
'link' => "index.php?filtertype=course&filterselect=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
} else {
$navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
}
break;
case 'group':
if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
if ($tagid || !empty($tag)) {
$navlinks[] = array('name' => $thisgroup->name,
'link' => "$CFG->wwwroot/user/index.php?id=$course->id&group=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => $blogstring,
'link' => "index.php?filtertype=group&filterselect=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
} else {
$navlinks[] = array('name' => $thisgroup->name,
'link' => "$CFG->wwwroot/user/index.php?id=$course->id&group=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
}
} else {
print_error('cannotfindgroup');
}
break;
case 'user':
$participants = get_string('participants');
if (!$user = $DB->get_record('user', array('id'=>$filterselect))) {
print_error('invaliduserid');
}
if ($course->id != SITEID) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
$navlinks[] = array('name' => $participants,
'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
'type' => 'misc');
}
$navlinks[] = array('name' => fullname($user),
'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&course=$course->id",
'type' => 'misc');
if ($tagid || !empty($tag)) {
$navlinks[] = array('name' => $blogstring,
'link' => "index.php?courseid=$course->id&filtertype=user&filterselect=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
} else {
$navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
}
print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
} else {
//in top view
if ($postid) {
$navlinks[] = array('name' => fullname($user),
'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => $blogstring,
'link' => "index.php?filtertype=user&filterselect=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => format_string($postobject->subject), 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
} else if ($tagid || !empty($tag)) {
$navlinks[] = array('name' => fullname($user),
'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => $blogstring,
'link' => "index.php?filtertype=user&filterselect=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
} else {
$navlinks[] = array('name' => fullname($user),
'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
'type' => 'misc');
$navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
}
print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
}
break;
default:
print_error('unknownfiletype');
break;
}
// prints the tabs
if ($filtertype=='user') {
$showroles = true;
} else {
$showroles = false;
}
$currenttab = 'blogs';
require_once($CFG->dirroot .'/user/tabs.php');
/// Layout the whole page as three big columns.
print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
print '<tr valign="top">' . "\n";
/// The left column ...
if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
print '<!-- Begin left side blocks -->' . "\n";
print_container_start();
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
print_container_end();
print '<!-- End left side blocks -->' . "\n";
print '</td>' . "\n";
}
/// Start main column
print '<!-- Begin page content -->' . "\n";
print '<td>';
print_container_start();
?>
<table width="100%">
<tr>
<td valign="top">