file installer.php was added on branch MOODLE_16_STABLE on 2007-11-05 08:34:10 +0000
[moodle.git] / blog / index.php
blob953de9b68d23a1ae12579990885c845bfc0f8873
1 <?php // $Id$
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 */
9 if (!file_exists('../config.php')) {
10 header('Location: ../install.php');
11 die;
14 require_once('../config.php');
15 require_once($CFG->dirroot .'/blog/lib.php');
16 require_once($CFG->libdir .'/blocklib.php');
18 $id = optional_param('id', 0, PARAM_INT);
19 $limit = optional_param('limit', 0, PARAM_INT);
20 $start = optional_param('formstart', 0, PARAM_INT);
21 $userid = optional_param('userid',0,PARAM_INT);
22 $courseid = optional_param('courseid',SITEID,PARAM_INT);
23 $tag = optional_param('tag', '', PARAM_NOTAGS);
24 $tagid = optional_param('tagid', 0, PARAM_INT);
25 $postid = optional_param('postid',0,PARAM_INT);
26 $filtertype = optional_param('filtertype', '', PARAM_ALPHA);
27 $filterselect = optional_param('filterselect', 0, PARAM_INT);
29 /// overwrite filter code here
31 if ($filtertype) {
32 switch ($filtertype) {
34 case 'site':
35 if ($filterselect) {
36 $userid = $filterselect;
37 } else {
38 $userid = 0;
40 $course = get_site();
41 $courseid = SITEID;
42 break;
44 case 'course':
45 if ($filterselect) {
46 $courseid = $filterselect;
47 $course = get_record('course','id',$courseid);
49 $userid =0;
50 $groupid = 0;
52 break;
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;
63 $userid = 0;
65 break;
67 case 'user':
68 if ($filterselect) {
69 $userid = $filterselect;
71 $groupid = 0;
73 break;
74 default:
75 break;
78 } else if ($userid) { //default to user
79 $filtertype = 'user';
80 $filterselect = $userid;
81 } else {
82 $filtertype = 'site';
83 $filterselect = '';
86 /// rights checking
88 switch ($filtertype) {
89 case 'site':
90 if ($CFG->bloglevel < BLOG_SITE_LEVEL && (!isadmin())) {
91 error ('site blogs is not enabled');
92 } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
93 require_login();
95 break;
96 case 'course':
97 if ($CFG->bloglevel < BLOG_COURSE_LEVEL && (!isadmin())) {
98 error ('course blogs is not enabled');
101 if (!isstudent($filterselect) && !isteacher($filterselect)) {
102 error ('you must be a student in this course to view course blogs');
104 /// check if viewer is student
105 break;
106 case 'group':
107 if ($CFG->bloglevel < BLOG_GROUP_LEVEL && (!isadmin())) {
108 error ('group blogs is not enabled');
110 if (!isteacheredit($course) and (groupmode($course) == SEPARATEGROUPS)) {
111 if (!ismember($filterselect)) {
112 error ('you are not in this group');
115 /// check if user is editting teacher, or if spg, is member
116 break;
117 case 'user':
118 if ($CFG->bloglevel < BLOG_USER_LEVEL && (!isadmin())) {
119 error ('Blogs is not enabled');
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');
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 blog_user_can_view_user_post($filterselect);
130 break;
131 default:
132 break;
135 // first set the start and end day equal to the day argument passed in from the get vars
136 if ($limit == 'none') {
137 $limit = get_user_preferences('blogpagesize',10);
140 include($CFG->dirroot .'/blog/header.php');
142 $blogpage = optional_param('blogpage',0,PARAM_INT);
144 blog_print_html_formatted_entries($userid, $postid, $limit, ($blogpage * $limit) ,$filtertype, $filterselect, $tagid, $tag, $filtertype, $filterselect);
146 add_to_log($courseid, 'blog', 'view', 'index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;postid='.$postid.'&amp;tagid='.$tagid.'&amp;tag='.$tag, 'view blog entry');
148 include($CFG->dirroot .'/blog/footer.php');