blog access rights fix, forgot to check in last week
[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
5c625033 18$id = optional_param('id', 0, PARAM_INT);
19$limit = optional_param('limit', 0, PARAM_INT);
e17426ca 20$start = optional_param('formstart', 0, PARAM_INT);
4a173181 21$userid = optional_param('userid',0,PARAM_INT);
4a173181 22$courseid = optional_param('courseid',0,PARAM_INT);
61ca5f8d 23$tag = s(urldecode(optional_param('tag', '', PARAM_NOTAGS)));
5c625033 24$tagid = optional_param('tagid', 0, PARAM_INT);
516194d0 25$postid = optional_param('postid',0,PARAM_INT);
9154b440 26$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
27$filterselect = optional_param('filterselect', 0, PARAM_INT);
4a173181 28
29/// overwrite filter code here
4a173181 30
31if ($filtertype) {
32 switch ($filtertype) {
33
34 case 'site':
35 if ($filterselect) {
36 $userid = $filterselect;
37 } else {
38 $userid = 0;
39 }
40 $course = get_site();
41 $courseid = SITEID;
42 break;
43
44 case 'course':
45 if ($filterselect) {
46 $courseid = $filterselect;
47 $course = get_record('course','id',$courseid);
48 }
49 $userid =0;
50 $groupid = 0;
51
52 break;
53
54 case 'group':
55 if ($filterselect) {
56 $groupid = $filterselect;
57 $group = get_record('groups','id',$groupid);
58 $course = get_record('course','id',$group->courseid);
59 $courseid = $course->id;
60 } else {
61 $groupid = 0;
62 }
63 $userid = 0;
64
65 break;
66
67 case 'user':
68 if ($filterselect) {
69 $userid = $filterselect;
70 }
71 $groupid = 0;
72
73 break;
74 default:
75 break;
76 }
77
78} else if ($userid) { //default to user
79 $filtertype = 'user';
80 $filterselect = $userid;
81} else {
82 $filtertype = 'site';
83 $filterselect = '';
84}
85
4a173181 86/// rights checking
87
88switch ($filtertype) {
89 case 'site':
9154b440 90 if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
4a173181 91 error ('site blogs is not enabled');
9154b440 92 } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
4a173181 93 require_login();
94 }
95 break;
96 case 'course':
9154b440 97 if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
4a173181 98 error ('course blogs is not enabled');
99 }
100
101 if (!isstudent($filterselect) && !isteacher($filterselect)) {
102 error ('you must be a student in this course to view course blogs');
103 }
104 /// check if viewer is student
105 break;
106 case 'group':
9154b440 107 if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
4a173181 108 error ('group blogs is not enabled');
109 }
110 if (!isteacheredit($course) and (groupmode($course) == SEPARATEGROUPS)) {
111 if (!ismember($filterselect)) {
112 error ('you are not in this group');
113 }
114 }
115 /// check if user is editting teacher, or if spg, is member
116 break;
117 case 'user':
9154b440 118 if ($CFG->bloglevel < BLOG_USER_LEVEL) {
4a173181 119 error ('Blogs is not enabled');
120 }
516194d0 121
122 blog_user_can_view_user_post($filterselect);
123
4a173181 124 /// check to see if the viewer is sharing no_group, visible group course.
125 /// if not , check if the viewer is in any spg group as the user
126 break;
127 default:
128 break;
129}
130
4a173181 131//first set the start and end day equal to the day argument passed in from the get vars
4a173181 132if ($limit == 'none') {
eccfc1ca 133 $limit = get_user_preferences('blogpagesize',10);
4a173181 134}
f99fee6c 135
c2ee4e87 136//$blogFilter =& new BlogFilter($userid, $postid, $limit, $start,$filtertype, $filterselect, $tagid, $tag);
4a173181 137
4a173181 138include($CFG->dirroot .'/blog/header.php');
139
140//prints the tabs
141$currenttab = 'blogs';
142$user = $USER;
143if (!$course) {
144 $course = get_record('course','id',optional_param('courseid', SITEID, PARAM_INT));
145}
146require_once($CFG->dirroot .'/user/tabs.php');
147
c2ee4e87 148$blogpage = optional_param('blogpage',0,PARAM_INT);
149
150blog_print_html_formatted_entries($userid, $postid, $limit, ($blogpage * $limit) ,$filtertype, $filterselect, $tagid, $tag, $filtertype, $filterselect);
4a173181 151
152include($CFG->dirroot .'/blog/footer.php');
153
154?>