param('course', $courseid);
}
if ($userid !== 0) {
$url->param('user', $userid);
}
if ($filtertype !== '') {
$url->param('filtertype', $filtertype);
}
if ($filterselect !== 0) {
$url->param('filterselect', $filterselect);
}
$PAGE->set_url($url);
/// tabs compatibility
switch($filtertype) {
case 'course':
$courseid = $filterselect;
break;
case 'site':
$courseid = SITEID;
break;
}
/// locate course information
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid');
}
/// locate user information
if ($userid) {
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
print_error('invaliduserid');
}
$filtertype = 'user';
$filterselect = $user->id;
if ($user->deleted) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('userdeleted'));
echo $OUTPUT->footer();
die;
}
} else {
$filtertype = 'course';
$filterselect = $course->id;
}
/// require login to access notes
require_login($course);
add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&user='.$userid, 'view notes');
if (empty($CFG->enablenotes)) {
print_error('notesdisabled', 'notes');
}
/// output HTML
if ($course->id == SITEID) {
$coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
} else {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
}
$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
$strnotes = get_string('notes', 'notes');
$link = null;
if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
$link = new moodle_url('/user/index.php',array('id'=>$course->id));
}
if ($userid) {
$PAGE->navigation->extend_for_user($user);
} else {
$PAGE->navbar->add(get_string('participants'), $link);
$PAGE->navbar->add($strnotes);
}
$PAGE->set_title($course->shortname . ': ' . $strnotes);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(fullname($user));
$showroles = 1;
$currenttab = 'notes';
require($CFG->dirroot .'/user/tabs.php');
$strsitenotes = get_string('sitenotes', 'notes');
$strcoursenotes = get_string('coursenotes', 'notes');
$strpersonalnotes = get_string('personalnotes', 'notes');
$straddnewnote = get_string('addnewnote', 'notes');
echo $OUTPUT->box_start();
if ($courseid != SITEID) {
//echo '' . $strsitenotes . ' | ' . $strcoursenotes . ' | ' . $strpersonalnotes . '';
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
$view = has_capability('moodle/notes:view', $context);
note_print_notes('' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
note_print_notes('' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
note_print_notes('' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
} else { // Normal course
//echo '' . $strsitenotes . ' | ' . $strcoursenotes . '';
$view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
note_print_notes('' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
echo '';
if (!empty($userid)) {
$courses = get_my_courses($userid);
foreach($courses as $c) {
$header = '' . $c->fullname . '';
if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
$addid = $c->id;
} else {
$addid = 0;
}
note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
}
}
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer();