2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * index page to view notes.
20 * if a course id is specified then the entries from that course are shown
21 * if a user id is specified only notes related to that user are shown
23 require_once('../config.php');
24 require_once('lib.php');
26 $courseid = optional_param('course', SITEID
, PARAM_INT
);
27 $userid = optional_param('user', 0, PARAM_INT
);
28 $filtertype = optional_param('filtertype', '', PARAM_ALPHA
);
29 $filterselect = optional_param('filterselect', 0, PARAM_INT
);
31 if (empty($CFG->enablenotes
)) {
32 print_error('notesdisabled', 'notes');
35 $url = new moodle_url('/notes/index.php');
36 if ($courseid != SITEID
) {
37 $url->param('course', $courseid);
40 $url->param('user', $userid);
44 // Tabs compatibility.
47 $courseid = $filterselect;
54 if (empty($courseid)) {
58 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST
);
61 $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST
);
63 $filterselect = $user->id
;
66 echo $OUTPUT->header();
67 echo $OUTPUT->heading(get_string('userdeleted'));
68 echo $OUTPUT->footer();
73 $filtertype = 'course';
74 $filterselect = $course->id
;
78 require_login($course);
81 if ($course->id
== SITEID
) {
82 $coursecontext = context_system
::instance();
84 $coursecontext = context_course
::instance($course->id
);
87 require_capability('moodle/notes:view', $coursecontext);
88 $systemcontext = context_system
::instance();
91 note_view($coursecontext, $userid);
93 $strnotes = get_string('notes', 'notes');
94 if ($userid && $course->id
== SITEID
) {
95 $PAGE->set_context(context_user
::instance($user->id
));
96 $PAGE->navigation
->extend_for_user($user);
97 // If we are looking at our own notes, then change focus to 'my notes'.
98 if ($userid == $USER->id
) {
99 $notenode = $PAGE->navigation
->find('notes', null)->make_inactive();
102 $notesurl = new moodle_url('/notes/index.php', array('user' => $userid));
103 $PAGE->navbar
->add(get_string('notes', 'notes'), $notesurl);
104 } else if ($course->id
!= SITEID
) {
105 $notenode = $PAGE->navigation
->find('currentcoursenotes', null)->make_inactive();
107 $notesurl = new moodle_url('/notes/index.php', array('user' => $userid, 'course' => $courseid));
108 $PAGE->navbar
->add(get_string('notes', 'notes'), $notesurl);
110 $PAGE->set_context(context_course
::instance($courseid));
113 if (has_capability('moodle/course:viewparticipants', $coursecontext)
114 ||
has_capability('moodle/site:viewparticipants', $systemcontext)) {
116 $link = new moodle_url('/user/index.php', array('id' => $course->id
));
120 $PAGE->set_pagelayout('incourse');
121 $PAGE->set_title($course->fullname
);
122 if ($course->id
== SITEID
) {
123 $PAGE->set_heading(fullname($user));
125 $PAGE->set_heading($course->fullname
);
128 echo $OUTPUT->header();
130 if ($course->id
!= SITEID
) {
131 $headerinfo = array('heading' => fullname($user), 'user' => $user);
132 echo $OUTPUT->context_header($headerinfo, 2);
135 echo $OUTPUT->heading($strnotes);
137 $strsitenotes = get_string('sitenotes', 'notes');
138 $strcoursenotes = get_string('coursenotes', 'notes');
139 $strpersonalnotes = get_string('personalnotes', 'notes');
140 $straddnewnote = get_string('addnewnote', 'notes');
142 echo $OUTPUT->box_start();
144 if ($courseid != SITEID
) {
145 $context = context_course
::instance($courseid);
146 $addid = has_capability('moodle/notes:manage', $context) ?
$courseid : 0;
147 $view = has_capability('moodle/notes:view', $context);
148 $fullname = format_string($course->fullname
, true, array('context' => $context));
150 '<a name="sitenotes"></a>' . $strsitenotes,
159 '<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')',
168 '<a name="personalnotes"></a>' . $strpersonalnotes,
177 } else { // Normal course.
178 $view = has_capability('moodle/notes:view', context_system
::instance());
179 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE
, 0);
180 echo '<a name="coursenotes"></a>';
182 if (!empty($userid)) {
183 $courses = enrol_get_users_courses($userid);
184 foreach ($courses as $c) {
185 $ccontext = context_course
::instance($c->id
);
186 $cfullname = format_string($c->fullname
, true, array('context' => $ccontext));
187 $header = '<a href="' . $CFG->wwwroot
. '/course/view.php?id=' . $c->id
. '">' . $cfullname . '</a>';
188 $viewcoursenotes = has_capability('moodle/notes:view', $ccontext);
189 if (has_capability('moodle/notes:manage', $ccontext)) {
194 note_print_notes($header, $addid, $viewcoursenotes, $c->id
, $userid, NOTES_STATE_PUBLIC
, 0);
199 echo $OUTPUT->box_end();
201 echo $OUTPUT->footer();