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