Now, hidden courses that haven't been modified in the last month
[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);
9fad492e 22$courseid = optional_param('courseid',SITEID,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':
14148bc2 90 if ($CFG->bloglevel < BLOG_SITE_LEVEL && (!isadmin())) {
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':
14148bc2 97 if ($CFG->bloglevel < BLOG_COURSE_LEVEL && (!isadmin())) {
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':
14148bc2 107 if ($CFG->bloglevel < BLOG_GROUP_LEVEL && (!isadmin())) {
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':
14148bc2 118 if ($CFG->bloglevel < BLOG_USER_LEVEL && (!isadmin())) {
4a173181 119 error ('Blogs is not enabled');
120 }
f4c85f46 121
122 if ($CFG->bloglevel == BLOG_USER_LEVEL and $USER->id != $filterselect and !isadmin()) {
123 error ('Under this setting, you can only view your own blogs');
124 }
516194d0 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
f4c85f46 128 blog_user_can_view_user_post($filterselect);
129
4a173181 130 break;
131 default:
132 break;
133}
134
8c9814f9 135// first set the start and end day equal to the day argument passed in from the get vars
4a173181 136if ($limit == 'none') {
eccfc1ca 137 $limit = get_user_preferences('blogpagesize',10);
4a173181 138}
f99fee6c 139
4a173181 140include($CFG->dirroot .'/blog/header.php');
141
8c9814f9 142// prints the tabs
4a173181 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
c2ee4e87 150$blogpage = optional_param('blogpage',0,PARAM_INT);
151
152blog_print_html_formatted_entries($userid, $postid, $limit, ($blogpage * $limit) ,$filtertype, $filterselect, $tagid, $tag, $filtertype, $filterselect);
4a173181 153
154include($CFG->dirroot .'/blog/footer.php');
155
156?>