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
9 require_once('../config.php');
10 require_once('lib.php');
12 /// retrieve parameters
13 $courseid = optional_param('course', SITEID
, PARAM_INT
);
14 $userid = optional_param('user', 0, PARAM_INT
);
15 $filtertype = optional_param('filtertype', '', PARAM_ALPHA
);
16 $filterselect = optional_param('filterselect', 0, PARAM_INT
);
18 $url = new moodle_url('/notes/index.php');
19 if ($courseid != SITEID
) {
20 $url->param('course', $courseid);
23 $url->param('user', $userid);
27 /// tabs compatibility
30 $courseid = $filterselect;
37 if (empty($courseid)) {
41 /// locate course information
42 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST
);
44 /// locate user information
46 $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST
);
48 $filterselect = $user->id
;
51 echo $OUTPUT->header();
52 echo $OUTPUT->heading(get_string('userdeleted'));
53 echo $OUTPUT->footer();
58 $filtertype = 'course';
59 $filterselect = $course->id
;
62 /// require login to access notes
63 require_login($course);
65 if ($course->id
== SITEID
) {
66 $coursecontext = context_system
::instance(); // SYSTEM context
68 $coursecontext = context_course
::instance($course->id
); // Course context
70 $systemcontext = context_system
::instance(); // SYSTEM context
73 $event = \core\event\notes_viewed
::create(array(
74 'courseid' => $courseid,
75 'relateduserid' => $userid,
76 'context' => $coursecontext,
77 'other' => array('content' => 'notes')
81 if (empty($CFG->enablenotes
)) {
82 print_error('notesdisabled', 'notes');
85 $strnotes = get_string('notes', 'notes');
87 $PAGE->set_context(context_user
::instance($user->id
));
88 $PAGE->navigation
->extend_for_user($user);
91 if (has_capability('moodle/course:viewparticipants', $coursecontext) ||
has_capability('moodle/site:viewparticipants', $systemcontext)) {
92 $link = new moodle_url('/user/index.php',array('id'=>$course->id
));
96 $PAGE->set_pagelayout('course');
97 $PAGE->set_title($course->shortname
. ': ' . $strnotes);
98 $PAGE->set_heading($course->fullname
);
100 echo $OUTPUT->header();
102 echo $OUTPUT->heading(fullname($user).': '.$strnotes);
104 echo $OUTPUT->heading(format_string($course->shortname
, true, array('context' => $coursecontext)).': '.$strnotes);
107 $strsitenotes = get_string('sitenotes', 'notes');
108 $strcoursenotes = get_string('coursenotes', 'notes');
109 $strpersonalnotes = get_string('personalnotes', 'notes');
110 $straddnewnote = get_string('addnewnote', 'notes');
112 echo $OUTPUT->box_start();
114 if ($courseid != SITEID
) {
115 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
116 $context = context_course
::instance($courseid);
117 $addid = has_capability('moodle/notes:manage', $context) ?
$courseid : 0;
118 $view = has_capability('moodle/notes:view', $context);
119 $fullname = format_string($course->fullname
, true, array('context' => $context));
120 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE
, 0);
121 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC
, 0);
122 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT
, $USER->id
);
124 } else { // Normal course
125 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
126 $view = has_capability('moodle/notes:view', context_system
::instance());
127 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE
, 0);
128 echo '<a name="coursenotes"></a>';
130 if (!empty($userid)) {
131 $courses = enrol_get_users_courses($userid);
132 foreach($courses as $c) {
133 $ccontext = context_course
::instance($c->id
);
134 $cfullname = format_string($c->fullname
, true, array('context' => $ccontext));
135 $header = '<a href="' . $CFG->wwwroot
. '/course/view.php?id=' . $c->id
. '">' . $cfullname . '</a>';
136 if (has_capability('moodle/notes:manage', context_course
::instance($c->id
))) {
141 note_print_notes($header, $addid, $view, $c->id
, $userid, NOTES_STATE_PUBLIC
, 0);
146 echo $OUTPUT->box_end();
148 echo $OUTPUT->footer();