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