Small upgrade to fix some guest->mnethostid. MDL-10375
[pfb-moodle.git] / notes / index.php
blob1720558742f0de1621039e9f5fc3e34d12a95ca5
1 <?php // $Id$
3 /**
4 * file index.php
5 * index page to view notes.
6 * if a course id is specified then the entries from that course are shown
7 * if a user id is specified only notes related to that user are shown
8 */
9 require_once('../config.php');
10 require_once('lib.php');
11 // retrieve parameters
12 $courseid = optional_param('course', SITEID, PARAM_INT);
13 $userid = optional_param('user', 0, PARAM_INT);
14 $filtertype = optional_param('filtertype', '', PARAM_ALPHA);
15 $filterselect = optional_param('filterselect', 0, PARAM_INT);
17 // tabs compatibility
18 switch($filtertype) {
19 case 'course':
20 $courseid = $filterselect;
21 break;
22 case 'site':
23 $courseid = SITEID;
24 break;
27 // locate course information
28 if (!$course = get_record('course', 'id', $courseid)) {
29 error('Incorrect course id specified');
32 // locate user information
33 if ($userid) {
34 if(!$user = get_record('user', 'id', $userid)) {
35 error('Incorrect user id specified');
37 $filtertype = 'user';
38 $filterselect = $user->id;
39 } else {
40 $filtertype = 'course';
41 $filterselect = $course->id;
44 // require login to access notes
45 require_login($course->id);
46 $strnotes = get_string('notes', 'notes');
47 $crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));
48 $currenttab = 'notes';
49 // output HTML
50 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs));
52 require_once($CFG->dirroot .'/user/tabs.php');
54 if($courseid != SITEID) {
55 $context = get_context_instance(CONTEXT_COURSE, $courseid);
56 if (has_capability('moodle/notes:manage', $context)) {
57 $addlink = $CFG->wwwroot .'/notes/add.php?course=' . $courseid . '&amp;user=' . $userid;
58 echo '<p><a href="'. $addlink . '">' . get_string('addnewnote', 'notes') . '</a></p>';
60 note_print_notes(get_string('sitenotes', 'notes'), $context, 0, $userid, NOTES_STATE_SITE, 0);
61 note_print_notes(get_string('coursenotes', 'notes'), $context, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
62 note_print_notes(get_string('personalnotes', 'notes'), $context, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
63 } else {
64 $context = get_context_instance(CONTEXT_SYSTEM);
65 note_print_notes(get_string('sitenotes', 'notes'), $context, 0, $userid, NOTES_STATE_SITE, 0);
66 if($userid) {
67 $courses = get_my_courses($userid);
68 foreach($courses as $c) {
69 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
70 note_print_notes($header, $context, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
75 add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
77 print_footer($course);