mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
199 lines
5.6 KiB
PHP
Executable File
199 lines
5.6 KiB
PHP
Executable File
<?php // $Id$
|
|
|
|
/**
|
|
* file index.php
|
|
* index page to view blogs. if no blog is specified then site wide entries are shown
|
|
* if a blog id is specified then the latest entries from that blog are shown
|
|
*/
|
|
|
|
if (!file_exists('../config.php')) {
|
|
header('Location: ../install.php');
|
|
die;
|
|
}
|
|
require_once('../config.php');
|
|
|
|
require_once($CFG->dirroot .'/blog/lib.php');
|
|
require_once($CFG->libdir .'/blocklib.php');
|
|
|
|
$id = optional_param('id');
|
|
$limit = optional_param('limit');
|
|
optional_variable($formstart, 'none');
|
|
optional_variable($m, ''); //month
|
|
optional_variable($y, ''); //year
|
|
optional_variable($d, ''); //day
|
|
optional_variable($limit, 'none');
|
|
optional_variable($formstart, 'none');
|
|
|
|
$userid = optional_param('userid',0,PARAM_INT);
|
|
$groupid = optional_param('groupid',0,PARAM_INT);
|
|
$courseid = optional_param('courseid',0,PARAM_INT);
|
|
$tag = optional_param('tag');
|
|
$tagid = optional_param('tagid');
|
|
$filtertype = optional_param('filtertype','',PARAM_ALPHA);
|
|
$filterselect = optional_param('filterselect','',PARAM_NOTAGS);
|
|
|
|
/// overwrite filter code here
|
|
/// the the following code does the rights checkings?
|
|
|
|
if ($filtertype) {
|
|
switch ($filtertype) {
|
|
|
|
case 'site':
|
|
if ($filterselect) {
|
|
$userid = $filterselect;
|
|
} else {
|
|
$userid = 0;
|
|
}
|
|
$course = get_site();
|
|
$courseid = SITEID;
|
|
break;
|
|
|
|
case 'course':
|
|
if ($filterselect) {
|
|
$courseid = $filterselect;
|
|
$course = get_record('course','id',$courseid);
|
|
}
|
|
$userid =0;
|
|
$groupid = 0;
|
|
|
|
break;
|
|
|
|
case 'group':
|
|
if ($filterselect) {
|
|
$groupid = $filterselect;
|
|
$group = get_record('groups','id',$groupid);
|
|
$course = get_record('course','id',$group->courseid);
|
|
$courseid = $course->id;
|
|
} else {
|
|
$groupid = 0;
|
|
}
|
|
$userid = 0;
|
|
|
|
break;
|
|
|
|
case 'user':
|
|
if ($filterselect) {
|
|
$userid = $filterselect;
|
|
}
|
|
$groupid = 0;
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
} else if ($userid) { //default to user
|
|
$filtertype = 'user';
|
|
$filterselect = $userid;
|
|
} else {
|
|
$filtertype = 'site';
|
|
$filterselect = '';
|
|
}
|
|
|
|
|
|
/// rights checking
|
|
|
|
switch ($filtertype) {
|
|
case 'site':
|
|
if ($CFG->bloglevel < 4) {
|
|
error ('site blogs is not enabled');
|
|
} else if ($CFG->bloglevel < 5) {
|
|
require_login();
|
|
}
|
|
break;
|
|
case 'course':
|
|
if ($CFG->bloglevel < 3) {
|
|
error ('course blogs is not enabled');
|
|
}
|
|
|
|
if (!isstudent($filterselect) && !isteacher($filterselect)) {
|
|
error ('you must be a student in this course to view course blogs');
|
|
}
|
|
/// check if viewer is student
|
|
break;
|
|
case 'group':
|
|
if ($CFG->bloglevel < 2) {
|
|
error ('group blogs is not enabled');
|
|
}
|
|
if (!isteacheredit($course) and (groupmode($course) == SEPARATEGROUPS)) {
|
|
if (!ismember($filterselect)) {
|
|
error ('you are not in this group');
|
|
}
|
|
}
|
|
/// check if user is editting teacher, or if spg, is member
|
|
break;
|
|
case 'user':
|
|
if ($CFG->bloglevel < 1) {
|
|
error ('Blogs is not enabled');
|
|
}
|
|
$canview = 0; //bad start
|
|
|
|
$usercourses = get_my_courses($filterselect);
|
|
foreach ($usercourses as $usercourse) {
|
|
/// if viewer and user sharing same non-spg course, then grant permission
|
|
if (groupmode($usercourse)!= SEPARATEGROUPS){
|
|
if (isstudent($usercourse->id) || isteacher($usercourse->id)) {
|
|
$canview = 1;
|
|
}
|
|
} else {
|
|
/// now we need every group the user is in, and check to see if view is a member
|
|
if ($usergroups = user_group($usercourse->id, $filterselect)) {
|
|
foreach ($usergroups as $usergroup) {
|
|
if (ismember($usergroup->id)) {
|
|
$canview = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!$canview && $CFG->bloglevel < 4) {
|
|
error ('you can not view this user\'s blogs');
|
|
}
|
|
/// check to see if the viewer is sharing no_group, visible group course.
|
|
/// if not , check if the viewer is in any spg group as the user
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
|
|
//first set the start and end day equal to the day argument passed in from the get vars
|
|
$startday = $d;
|
|
$endday = $d + 1;
|
|
if ( empty($d) && !empty($m) && !empty($y) ) {
|
|
//if there was no day specified then the entire month is wanted.
|
|
$startday = 1;
|
|
$endday = blog_mk_getLastDayofMonth($m, $y);
|
|
}
|
|
|
|
if ($limit == 'none') {
|
|
$limit = get_user_preferences('blogpagesize',8);
|
|
}
|
|
|
|
if ($formstart == 'none' || $formstart < 0) {
|
|
$start = 0;
|
|
} else {
|
|
$start = $formstart;
|
|
}
|
|
|
|
$blogFilter =& new BlogFilter($userid, '', $courseid, $groupid, $limit, $start, $m, $startday, $y, $m, $endday, $y,$filtertype, $filterselect, $tagid, $tag);
|
|
//print_object($blogFilter); //debug
|
|
|
|
$pageNavigation = '';
|
|
|
|
include($CFG->dirroot .'/blog/header.php');
|
|
|
|
//prints the tabs
|
|
$currenttab = 'blogs';
|
|
$user = $USER;
|
|
if (!$course) {
|
|
$course = get_record('course','id',optional_param('courseid', SITEID, PARAM_INT));
|
|
}
|
|
require_once($CFG->dirroot .'/user/tabs.php');
|
|
|
|
blog_print_html_formatted_entries($blogFilter, $filtertype, $filterselect);
|
|
|
|
include($CFG->dirroot .'/blog/footer.php');
|
|
|
|
?>
|