MDL-15080 char to int cast problem in get_recent_enrolments()
[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
eccfc1ca 9require_once('../config.php');
4a173181 10require_once($CFG->dirroot .'/blog/lib.php');
11require_once($CFG->libdir .'/blocklib.php');
12
93caac3a 13$id = optional_param('id', 0, PARAM_INT);
93caac3a 14$start = optional_param('formstart', 0, PARAM_INT);
db32b054 15$userid = optional_param('userid', 0, PARAM_INT);
93caac3a 16$tag = optional_param('tag', '', PARAM_NOTAGS);
17$tagid = optional_param('tagid', 0, PARAM_INT);
db32b054 18$postid = optional_param('postid', 0, PARAM_INT);
93caac3a 19$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
9154b440 20$filterselect = optional_param('filterselect', 0, PARAM_INT);
e96f2a77 21
93caac3a 22$edit = optional_param('edit', -1, PARAM_BOOL);
e96f2a77 23$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs and course tracking
24
4a173181 25
ab2f17b0 26if (empty($CFG->bloglevel)) {
8b141784 27 print_error('blogdisable', 'blog');
ab2f17b0 28}
bbbf2d40 29
d9d16e56 30$sitecontext = get_context_instance(CONTEXT_SYSTEM);
93caac3a 31
32
33// change block edit staus if not guest and logged in
34if (isloggedin() and !isguest() and $edit != -1) {
35 $SESSION->blog_editing_enabled = $edit;
36}
37
e96f2a77 38if (empty($filtertype)) {
39 if ($userid) { // default to user if specified
40 $filtertype = 'user';
41 $filterselect = $userid;
42 } else if (has_capability('moodle/blog:view', $sitecontext) and $CFG->bloglevel > BLOG_USER_LEVEL) {
dde73b9e 43 if ($postid) {
44 $filtertype = 'user';
45 if (!$postobject = get_record('post', 'module', 'blog', 'id', $postid)) {
46 error('No such blog entry');
47 }
48 $filterselect = $postobject->userid;
49 } else {
50 $filtertype = 'site';
51 $filterselect = '';
52 }
e96f2a77 53 } else {
54 // user might have capability to write blogs, but not read blogs at site level
55 // users might enter this url manually without parameters
56 $filtertype = 'user';
57 $filterselect = $USER->id;
4a173181 58 }
4a173181 59}
e96f2a77 60/// check access and prepare filters
4a173181 61
62switch ($filtertype) {
e96f2a77 63
4a173181 64 case 'site':
d7bf6d17 65 if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
8b141784 66 print_error('siteblogdisable', 'blog');
e96f2a77 67 }
68 if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
4a173181 69 require_login();
70 }
e96f2a77 71 if (!has_capability('moodle/blog:view', $sitecontext)) {
8b141784 72 print_error('cannotviewsiteblog', 'blog');
e96f2a77 73 }
4a173181 74 break;
e96f2a77 75
4a173181 76 case 'course':
d7bf6d17 77 if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
8b141784 78 print_error('courseblogdisable', 'blog');
4a173181 79 }
e96f2a77 80 if (!$course = get_record('course', 'id', $filterselect)) {
8b141784 81 print_error('invalidcourseid');
e96f2a77 82 }
83 $courseid = $course->id;
84 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
673bc55d 85 require_login($course);
11b03793 86 if (!has_capability('moodle/blog:view', $coursecontext)) {
8b141784 87 print_error('cannotviewcourseblog', 'blog');
e96f2a77 88 }
4a173181 89 break;
e96f2a77 90
4a173181 91 case 'group':
d7bf6d17 92 if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
8b141784 93 print_error('groupblogdisable', 'blog');
e96f2a77 94 }
11993a60 95
96 // fix for MDL-9268
97 if (! $group = groups_get_group($filterselect)) { //TODO:check.
8b141784 98 print_error('invalidgroupid');
e96f2a77 99 }
100 if (!$course = get_record('course', 'id', $group->courseid)) {
8b141784 101 print_error('invalidcourseid');
4a173181 102 }
e96f2a77 103 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
104 $courseid = $course->id;
673bc55d 105 require_login($course);
e96f2a77 106 if (!has_capability('moodle/blog:view', $coursecontext)) {
8b141784 107 print_error('cannotviewcourseorgroupblog', 'blog');
e96f2a77 108 }
ffc536af 109 if (groups_get_course_groupmode($course) == SEPARATEGROUPS
e96f2a77 110 and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
2c386f82 111 if (!groups_is_member($filterselect)) {
8b141784 112 print_error('notmemberofgroup');
4a173181 113 }
114 }
e96f2a77 115
4a173181 116 break;
e96f2a77 117
4a173181 118 case 'user':
d7bf6d17 119 if ($CFG->bloglevel < BLOG_USER_LEVEL) {
8b141784 120 print_error('blogdisable', 'blog');
4a173181 121 }
e96f2a77 122 if (!$user = get_record('user', 'id', $filterselect)) {
8b141784 123 print_error('invaliduserid');
f4c85f46 124 }
e96f2a77 125 if ($USER->id == $filterselect) {
126 if (!has_capability('moodle/blog:create', $sitecontext)
127 and !has_capability('moodle/blog:view', $sitecontext)) {
8b141784 128 print_error('donothaveblog', 'blog');
e96f2a77 129 }
130 } else {
131 $personalcontext = get_context_instance(CONTEXT_USER, $filterselect);
132 if (!has_capability('moodle/blog:view', $sitecontext)
133 and !has_capability('moodle/user:readuserblogs', $personalcontext)) {
8b141784 134 print_error('cannotviewuserblog', 'blog');
e96f2a77 135 }
136 if (!blog_user_can_view_user_post($filterselect)) {
8b141784 137 print_error('cannotviewcourseblog', 'blog');
e96f2a77 138 }
139 }
140 $userid = $filterselect;
f4c85f46 141
673bc55d 142 if (!empty($courseid)) {
143 require_login($courseid);
144 }
145
4a173181 146 break;
e96f2a77 147
4a173181 148 default:
8b141784 149 print_error('incorrectblogfilter', 'blog');
4a173181 150 break;
151}
152
e96f2a77 153if (empty($courseid)) {
154 $courseid = SITEID;
4a173181 155}
f99fee6c 156
4a173181 157include($CFG->dirroot .'/blog/header.php');
158
e96f2a77 159blog_print_html_formatted_entries($postid, $filtertype, $filterselect, $tagid, $tag);
4a173181 160
06622f92 161add_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 162
4a173181 163include($CFG->dirroot .'/blog/footer.php');
164
d7bf6d17 165
4b10f08b 166?>