Fixing my moodle bug in forum track posts display
[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}
13require_once('../config.php');
14
15require_once($CFG->dirroot .'/blog/lib.php');
16require_once($CFG->libdir .'/blocklib.php');
17
18$id = optional_param('id');
19$limit = optional_param('limit');
20optional_variable($formstart, 'none');
21optional_variable($m, ''); //month
22optional_variable($y, ''); //year
23optional_variable($d, ''); //day
24optional_variable($limit, 'none');
25optional_variable($formstart, 'none');
26
27$userid = optional_param('userid',0,PARAM_INT);
28$groupid = optional_param('groupid',0,PARAM_INT);
29$courseid = optional_param('courseid',0,PARAM_INT);
30$tag = optional_param('tag');
31$tagid = optional_param('tagid');
32$filtertype = optional_param('filtertype','',PARAM_ALPHA);
33$filterselect = optional_param('filterselect','',PARAM_NOTAGS);
34
35/// overwrite filter code here
36/// the the following code does the rights checkings?
37
38if ($filtertype) {
39 switch ($filtertype) {
40
41 case 'site':
42 if ($filterselect) {
43 $userid = $filterselect;
44 } else {
45 $userid = 0;
46 }
47 $course = get_site();
48 $courseid = SITEID;
49 break;
50
51 case 'course':
52 if ($filterselect) {
53 $courseid = $filterselect;
54 $course = get_record('course','id',$courseid);
55 }
56 $userid =0;
57 $groupid = 0;
58
59 break;
60
61 case 'group':
62 if ($filterselect) {
63 $groupid = $filterselect;
64 $group = get_record('groups','id',$groupid);
65 $course = get_record('course','id',$group->courseid);
66 $courseid = $course->id;
67 } else {
68 $groupid = 0;
69 }
70 $userid = 0;
71
72 break;
73
74 case 'user':
75 if ($filterselect) {
76 $userid = $filterselect;
77 }
78 $groupid = 0;
79
80 break;
81 default:
82 break;
83 }
84
85} else if ($userid) { //default to user
86 $filtertype = 'user';
87 $filterselect = $userid;
88} else {
89 $filtertype = 'site';
90 $filterselect = '';
91}
92
93
94/// rights checking
95
96switch ($filtertype) {
97 case 'site':
98 if ($CFG->bloglevel < 4) {
99 error ('site blogs is not enabled');
100 } else if ($CFG->bloglevel < 5) {
101 require_login();
102 }
103 break;
104 case 'course':
105 if ($CFG->bloglevel < 3) {
106 error ('course blogs is not enabled');
107 }
108
109 if (!isstudent($filterselect) && !isteacher($filterselect)) {
110 error ('you must be a student in this course to view course blogs');
111 }
112 /// check if viewer is student
113 break;
114 case 'group':
115 if ($CFG->bloglevel < 2) {
116 error ('group blogs is not enabled');
117 }
118 if (!isteacheredit($course) and (groupmode($course) == SEPARATEGROUPS)) {
119 if (!ismember($filterselect)) {
120 error ('you are not in this group');
121 }
122 }
123 /// check if user is editting teacher, or if spg, is member
124 break;
125 case 'user':
126 if ($CFG->bloglevel < 1) {
127 error ('Blogs is not enabled');
128 }
129 $canview = 0; //bad start
130
131 $usercourses = get_my_courses($filterselect);
132 foreach ($usercourses as $usercourse) {
133 /// if viewer and user sharing same non-spg course, then grant permission
134 if (groupmode($usercourse)!= SEPARATEGROUPS){
135 if (isstudent($usercourse->id) || isteacher($usercourse->id)) {
136 $canview = 1;
137 }
138 } else {
139 /// now we need every group the user is in, and check to see if view is a member
140 if ($usergroups = user_group($usercourse->id, $filterselect)) {
141 foreach ($usergroups as $usergroup) {
142 if (ismember($usergroup->id)) {
143 $canview = 1;
144 }
145 }
146 }
147 }
148 }
149 if (!$canview && $CFG->bloglevel < 4) {
150 error ('you can not view this user\'s blogs');
151 }
152 /// check to see if the viewer is sharing no_group, visible group course.
153 /// if not , check if the viewer is in any spg group as the user
154 break;
155 default:
156 break;
157}
158
159
160//first set the start and end day equal to the day argument passed in from the get vars
161$startday = $d;
162$endday = $d + 1;
163if ( empty($d) && !empty($m) && !empty($y) ) {
164 //if there was no day specified then the entire month is wanted.
165 $startday = 1;
166 $endday = blog_mk_getLastDayofMonth($m, $y);
167}
168
169if ($limit == 'none') {
170 $limit = get_user_preferences('blogpagesize',8);
171}
172
173if ($formstart == 'none' || $formstart < 0) {
174 $start = 0;
175} else {
176 $start = $formstart;
177}
178
179$blogFilter =& new BlogFilter($userid, '', $courseid, $groupid, $limit, $start, $m, $startday, $y, $m, $endday, $y,$filtertype, $filterselect, $tagid, $tag);
180//print_object($blogFilter); //debug
181
182$pageNavigation = '';
183
184include($CFG->dirroot .'/blog/header.php');
185
186//prints the tabs
187$currenttab = 'blogs';
188$user = $USER;
189if (!$course) {
190 $course = get_record('course','id',optional_param('courseid', SITEID, PARAM_INT));
191}
192require_once($CFG->dirroot .'/user/tabs.php');
193
194blog_print_html_formatted_entries($blogFilter, $filtertype, $filterselect);
195
196include($CFG->dirroot .'/blog/footer.php');
197
198?>