The ISNULL() function is a nasty mysql-ism. The standard SQL syntax is "xxx IS NULL...
[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
bbbf2d40 29
30
4a173181 31/// overwrite filter code here
4a173181 32
33if ($filtertype) {
34 switch ($filtertype) {
35
36 case 'site':
37 if ($filterselect) {
38 $userid = $filterselect;
39 } else {
40 $userid = 0;
41 }
42 $course = get_site();
43 $courseid = SITEID;
44 break;
45
46 case 'course':
47 if ($filterselect) {
48 $courseid = $filterselect;
49 $course = get_record('course','id',$courseid);
50 }
51 $userid =0;
52 $groupid = 0;
4a173181 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;
4a173181 65 break;
66
67 case 'user':
68 if ($filterselect) {
69 $userid = $filterselect;
70 }
71 $groupid = 0;
4a173181 72 break;
73 default:
74 break;
75 }
76
bbbf2d40 77} else if ($userid) { // default to user
4a173181 78 $filtertype = 'user';
79 $filterselect = $userid;
80} else {
81 $filtertype = 'site';
82 $filterselect = '';
83}
84
bbbf2d40 85
86
87/// Rights checking.
4a173181 88
89switch ($filtertype) {
90 case 'site':
bbbf2d40 91 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
d7bf6d17 92 if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
bbbf2d40 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':
bbbf2d40 99 $context = get_context_instance(CONTEXT_COURSE, $courseid);
d7bf6d17 100 if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
bbbf2d40 101 error('Course blogs is not enabled');
4a173181 102 }
4a173181 103 break;
104 case 'group':
d7bf6d17 105 $context = get_context_instance(CONTEXT_GROUP, $groupid);
106 if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
bbbf2d40 107 error ('Group blogs is not enabled');
4a173181 108 }
d7bf6d17 109 if (groupmode($course) == SEPARATEGROUPS &&
110 !has_capability('moodle/site:accessallgroups', $context)) {
4a173181 111 if (!ismember($filterselect)) {
bbbf2d40 112 error ('You are not a member of this group');
4a173181 113 }
114 }
115 /// check if user is editting teacher, or if spg, is member
116 break;
117 case 'user':
d7bf6d17 118 $context = get_context_instance(CONTEXT_USERID, $userid);
119 if ($CFG->bloglevel < BLOG_USER_LEVEL) {
4a173181 120 error ('Blogs is not enabled');
121 }
d7bf6d17 122 if ($CFG->bloglevel == BLOG_USER_LEVEL && $USER->id != $filterselect) {
f4c85f46 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
d7bf6d17 135if (!has_capability('moodle/blog:view', $context)) {
136 error('You do not have the required permissions to to view blogs');
137}
138
139
8c9814f9 140// first set the start and end day equal to the day argument passed in from the get vars
4a173181 141if ($limit == 'none') {
bbbf2d40 142 $limit = get_user_preferences('blogpagesize', 10);
4a173181 143}
f99fee6c 144
4a173181 145include($CFG->dirroot .'/blog/header.php');
146
bbbf2d40 147// prints the tabs
148$currenttab = 'blogs';
149$user = $USER;
150if (!$course) {
151 $course = get_record('course', 'id', optional_param('courseid', SITEID, PARAM_INT));
152}
bbbf2d40 153
154$blogpage = optional_param('blogpage', 0, PARAM_INT);
c2ee4e87 155
156blog_print_html_formatted_entries($userid, $postid, $limit, ($blogpage * $limit) ,$filtertype, $filterselect, $tagid, $tag, $filtertype, $filterselect);
4a173181 157
06622f92 158add_to_log($courseid, 'blog', 'view', 'index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;postid='.$postid.'&amp;tagid='.$tagid.'&amp;tag='.$tag, 'view blog entry');
92a019ac 159
4a173181 160include($CFG->dirroot .'/blog/footer.php');
161
d7bf6d17 162
163?>