weekly release 4.0dev
[moodle.git] / notes / index.php
CommitLineData
2f4a2f27 1<?php
ed6fc262
AD
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
83e70cc2 16
2f4a2f27 17/**
18 * file index.php
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
22 */
23require_once('../config.php');
24require_once('lib.php');
93b47710 25require_once($CFG->dirroot . '/course/lib.php');
83e70cc2 26
2f4a2f27 27$courseid = optional_param('course', SITEID, PARAM_INT);
28$userid = optional_param('user', 0, PARAM_INT);
29$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
30$filterselect = optional_param('filterselect', 0, PARAM_INT);
31
9dbf62d2
MG
32if (empty($CFG->enablenotes)) {
33 print_error('notesdisabled', 'notes');
34}
35
a6855934 36$url = new moodle_url('/notes/index.php');
7b2e259c 37if ($courseid != SITEID) {
2f4a2f27 38 $url->param('course', $courseid);
39}
40if ($userid !== 0) {
41 $url->param('user', $userid);
42}
2f4a2f27 43$PAGE->set_url($url);
83e70cc2 44
ed6fc262 45// Tabs compatibility.
2f4a2f27 46switch($filtertype) {
47 case 'course':
48 $courseid = $filterselect;
49 break;
50 case 'site':
51 $courseid = SITEID;
52 break;
53}
83e70cc2 54
7b5f1cd8
SH
55if (empty($courseid)) {
56 $courseid = SITEID;
57}
58
ed6fc262 59$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
83e70cc2 60
2f4a2f27 61if ($userid) {
ed6fc262 62 $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
2f4a2f27 63 $filtertype = 'user';
64 $filterselect = $user->id;
65
66 if ($user->deleted) {
67 echo $OUTPUT->header();
68 echo $OUTPUT->heading(get_string('userdeleted'));
69 echo $OUTPUT->footer();
70 die;
83e70cc2 71 }
72
2f4a2f27 73} else {
74 $filtertype = 'course';
75 $filterselect = $course->id;
4e1f6047 76 $user = $USER;
2f4a2f27 77}
78
2f4a2f27 79require_login($course);
ed6fc262
AD
80
81// Output HTML.
2f4a2f27 82if ($course->id == SITEID) {
ed6fc262 83 $coursecontext = context_system::instance();
2f4a2f27 84} else {
ed6fc262 85 $coursecontext = context_course::instance($course->id);
2f4a2f27 86}
ed6fc262 87
9dbf62d2 88require_capability('moodle/notes:view', $coursecontext);
ed6fc262 89$systemcontext = context_system::instance();
2f4a2f27 90
c4f9401c 91// Trigger event.
f0c5f840 92note_view($coursecontext, $userid);
c4f9401c 93
2f4a2f27 94$strnotes = get_string('notes', 'notes');
327e68e6 95if ($userid && $course->id == SITEID) {
bf0f06b1 96 $PAGE->set_context(context_user::instance($user->id));
7a7e209d 97 $PAGE->navigation->extend_for_user($user);
f495187d
AG
98 // If we are looking at our own notes, then change focus to 'my notes'.
99 if ($userid == $USER->id) {
100 $notenode = $PAGE->navigation->find('notes', null)->make_inactive();
101 }
327e68e6
DC
102
103 $notesurl = new moodle_url('/notes/index.php', array('user' => $userid));
104 $PAGE->navbar->add(get_string('notes', 'notes'), $notesurl);
105} else if ($course->id != SITEID) {
106 $notenode = $PAGE->navigation->find('currentcoursenotes', null)->make_inactive();
327e68e6
DC
107
108 $notesurl = new moodle_url('/notes/index.php', array('user' => $userid, 'course' => $courseid));
109 $PAGE->navbar->add(get_string('notes', 'notes'), $notesurl);
110
111 $PAGE->set_context(context_course::instance($courseid));
7a7e209d 112} else {
3406acde 113 $link = null;
93b47710 114 if (course_can_view_participants($coursecontext) || course_can_view_participants($systemcontext)) {
ed6fc262 115 $link = new moodle_url('/user/index.php', array('id' => $course->id));
3406acde 116 }
2f4a2f27 117}
3406acde 118
369484bf 119$PAGE->set_pagelayout('incourse');
4e1f6047 120$PAGE->set_title($course->fullname);
327e68e6
DC
121if ($course->id == SITEID) {
122 $PAGE->set_heading(fullname($user));
123} else {
124 $PAGE->set_heading($course->fullname);
125}
2f4a2f27 126
127echo $OUTPUT->header();
327e68e6
DC
128
129if ($course->id != SITEID) {
130 $headerinfo = array('heading' => fullname($user), 'user' => $user);
131 echo $OUTPUT->context_header($headerinfo, 2);
132}
133
4e1f6047 134echo $OUTPUT->heading($strnotes);
2f4a2f27 135
136$strsitenotes = get_string('sitenotes', 'notes');
137$strcoursenotes = get_string('coursenotes', 'notes');
138$strpersonalnotes = get_string('personalnotes', 'notes');
139$straddnewnote = get_string('addnewnote', 'notes');
140
141echo $OUTPUT->box_start();
142
143if ($courseid != SITEID) {
bf0f06b1 144 $context = context_course::instance($courseid);
2f4a2f27 145 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
146 $view = has_capability('moodle/notes:view', $context);
91d284c1 147 $fullname = format_string($course->fullname, true, array('context' => $context));
ed6fc262
AD
148 note_print_notes(
149 '<a name="sitenotes"></a>' . $strsitenotes,
150 $addid,
151 $view,
152 0,
153 $userid,
154 NOTES_STATE_SITE,
155 0
156 );
157 note_print_notes(
158 '<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')',
159 $addid,
160 $view,
161 $courseid,
162 $userid,
163 NOTES_STATE_PUBLIC,
164 0
165 );
166 note_print_notes(
167 '<a name="personalnotes"></a>' . $strpersonalnotes,
168 $addid,
169 $view,
170 $courseid,
171 $userid,
172 NOTES_STATE_DRAFT,
173 $USER->id
174 );
175
176} else { // Normal course.
bf0f06b1 177 $view = has_capability('moodle/notes:view', context_system::instance());
2f4a2f27 178 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
179 echo '<a name="coursenotes"></a>';
180
181 if (!empty($userid)) {
df997f84 182 $courses = enrol_get_users_courses($userid);
ed6fc262 183 foreach ($courses as $c) {
bf0f06b1 184 $ccontext = context_course::instance($c->id);
91d284c1
SH
185 $cfullname = format_string($c->fullname, true, array('context' => $ccontext));
186 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $cfullname . '</a>';
face1521
SL
187 $viewcoursenotes = has_capability('moodle/notes:view', $ccontext);
188 if (has_capability('moodle/notes:manage', $ccontext)) {
2f4a2f27 189 $addid = $c->id;
190 } else {
191 $addid = 0;
83e70cc2 192 }
face1521 193 note_print_notes($header, $addid, $viewcoursenotes, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
83e70cc2 194 }
2f6c662f 195 }
2f4a2f27 196}
83e70cc2 197
2f4a2f27 198echo $OUTPUT->box_end();
83e70cc2 199
1d422980 200echo $OUTPUT->footer();