fix undefined variable $context on line 135
[moodle.git] / blog / index.php
CommitLineData
4a173181 1<?php // $Id$
2
3/**
4 * file index.php
5 * index page to view blogs. if no blog is specified then site wide entries are shown
6 * if a blog id is specified then the latest entries from that blog are shown
7 */
8
9if (!file_exists('../config.php')) {
10 header('Location: ../install.php');
11 die;
12}
4a173181 13
eccfc1ca 14require_once('../config.php');
4a173181 15require_once($CFG->dirroot .'/blog/lib.php');
16require_once($CFG->libdir .'/blocklib.php');
17
93caac3a 18$id = optional_param('id', 0, PARAM_INT);
19$limit = optional_param('limit', 0, PARAM_INT);
20$start = optional_param('formstart', 0, PARAM_INT);
21$userid = optional_param('userid',0,PARAM_INT);
22$courseid = optional_param('courseid',SITEID,PARAM_INT);
23$tag = optional_param('tag', '', PARAM_NOTAGS);
24$tagid = optional_param('tagid', 0, PARAM_INT);
25$postid = optional_param('postid',0,PARAM_INT);
26$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
9154b440 27$filterselect = optional_param('filterselect', 0, PARAM_INT);
93caac3a 28$edit = optional_param('edit', -1, PARAM_BOOL);
4a173181 29
ab2f17b0 30if (empty($CFG->bloglevel)) {
31 error('Blogging is disabled!');
32}
bbbf2d40 33
34
93caac3a 35// Blogs are only global for now.
36// 'post' table will have to be changed to use contextid instead of courseid,
37// modileid, etc. because they are obsolete now.
38$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
39
40
41// change block edit staus if not guest and logged in
42if (isloggedin() and !isguest() and $edit != -1) {
43 $SESSION->blog_editing_enabled = $edit;
44}
45
4a173181 46/// overwrite filter code here
4a173181 47
48if ($filtertype) {
49 switch ($filtertype) {
50
51 case 'site':
52 if ($filterselect) {
53 $userid = $filterselect;
54 } else {
55 $userid = 0;
56 }
57 $course = get_site();
58 $courseid = SITEID;
59 break;
60
61 case 'course':
62 if ($filterselect) {
63 $courseid = $filterselect;
64 $course = get_record('course','id',$courseid);
65 }
66 $userid =0;
67 $groupid = 0;
4a173181 68 break;
69
70 case 'group':
71 if ($filterselect) {
72 $groupid = $filterselect;
73 $group = get_record('groups','id',$groupid);
74 $course = get_record('course','id',$group->courseid);
75 $courseid = $course->id;
76 } else {
77 $groupid = 0;
78 }
79 $userid = 0;
4a173181 80 break;
81
82 case 'user':
83 if ($filterselect) {
84 $userid = $filterselect;
85 }
86 $groupid = 0;
4a173181 87 break;
88 default:
89 break;
90 }
91
bbbf2d40 92} else if ($userid) { // default to user
4a173181 93 $filtertype = 'user';
94 $filterselect = $userid;
95} else {
96 $filtertype = 'site';
97 $filterselect = '';
98}
99
bbbf2d40 100
101
102/// Rights checking.
4a173181 103
104switch ($filtertype) {
105 case 'site':
bbbf2d40 106 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
d7bf6d17 107 if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
bbbf2d40 108 error('Site blogs is not enabled');
9154b440 109 } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
4a173181 110 require_login();
111 }
112 break;
113 case 'course':
bbbf2d40 114 $context = get_context_instance(CONTEXT_COURSE, $courseid);
d7bf6d17 115 if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
bbbf2d40 116 error('Course blogs is not enabled');
4a173181 117 }
4a173181 118 break;
119 case 'group':
d7bf6d17 120 $context = get_context_instance(CONTEXT_GROUP, $groupid);
121 if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
bbbf2d40 122 error ('Group blogs is not enabled');
4a173181 123 }
d7bf6d17 124 if (groupmode($course) == SEPARATEGROUPS &&
125 !has_capability('moodle/site:accessallgroups', $context)) {
4a173181 126 if (!ismember($filterselect)) {
bbbf2d40 127 error ('You are not a member of this group');
4a173181 128 }
129 }
130 /// check if user is editting teacher, or if spg, is member
131 break;
132 case 'user':
4b10f08b 133 $context = get_context_instance(CONTEXT_USER, $userid);
d7bf6d17 134 if ($CFG->bloglevel < BLOG_USER_LEVEL) {
4a173181 135 error ('Blogs is not enabled');
136 }
d7bf6d17 137 if ($CFG->bloglevel == BLOG_USER_LEVEL && $USER->id != $filterselect) {
f4c85f46 138 error ('Under this setting, you can only view your own blogs');
139 }
516194d0 140
4a173181 141 /// check to see if the viewer is sharing no_group, visible group course.
142 /// if not , check if the viewer is in any spg group as the user
f4c85f46 143 blog_user_can_view_user_post($filterselect);
144
4a173181 145 break;
146 default:
147 break;
148}
149
d7bf6d17 150if (!has_capability('moodle/blog:view', $context)) {
151 error('You do not have the required permissions to to view blogs');
152}
153
154
8c9814f9 155// first set the start and end day equal to the day argument passed in from the get vars
4a173181 156if ($limit == 'none') {
bbbf2d40 157 $limit = get_user_preferences('blogpagesize', 10);
4a173181 158}
f99fee6c 159
4a173181 160include($CFG->dirroot .'/blog/header.php');
161
bbbf2d40 162// prints the tabs
163$currenttab = 'blogs';
164$user = $USER;
165if (!$course) {
166 $course = get_record('course', 'id', optional_param('courseid', SITEID, PARAM_INT));
167}
bbbf2d40 168
169$blogpage = optional_param('blogpage', 0, PARAM_INT);
c2ee4e87 170
171blog_print_html_formatted_entries($userid, $postid, $limit, ($blogpage * $limit) ,$filtertype, $filterselect, $tagid, $tag, $filtertype, $filterselect);
4a173181 172
06622f92 173add_to_log($courseid, 'blog', 'view', 'index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;postid='.$postid.'&amp;tagid='.$tagid.'&amp;tag='.$tag, 'view blog entry');
92a019ac 174
4a173181 175include($CFG->dirroot .'/blog/footer.php');
176
d7bf6d17 177
4b10f08b 178?>