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/>.
17 require_once('../config.php');
18 require_once('lib.php');
20 $noteid = required_param('id', PARAM_INT
);
22 $PAGE->set_url('/notes/delete.php', array('id' => $noteid));
24 if (!$note = note_load($noteid)) {
25 print_error('invalidid');
28 if (!$course = $DB->get_record('course', array('id' => $note->courseid
))) {
29 print_error('invalidcourseid');
32 require_login($course);
34 if (empty($CFG->enablenotes
)) {
35 print_error('notesdisabled', 'notes');
38 if (!$user = $DB->get_record('user', array('id' => $note->userid
))) {
39 print_error('invaliduserid');
42 $context = context_course
::instance($course->id
);
44 if (!has_capability('moodle/notes:manage', $context)) {
45 print_error('nopermissiontodelete', 'notes');
48 if (data_submitted() && confirm_sesskey()) {
49 // If data was submitted and is valid, then delete note.
50 $returnurl = $CFG->wwwroot
. '/notes/index.php?course=' . $course->id
. '&user=' . $note->userid
;
55 // If data was not submitted yet, then show note data with a delete confirmation form.
56 $strnotes = get_string('notes', 'notes');
57 $optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
58 $optionsno = array('course' => $course->id
, 'user' => $note->userid
);
62 if (has_capability('moodle/course:viewparticipants', $context)
63 ||
has_capability('moodle/site:viewparticipants', context_system
::instance())) {
65 $link = new moodle_url('/user/index.php', array('id' => $course->id
));
67 $PAGE->navbar
->add(get_string('participants'), $link);
68 $PAGE->navbar
->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id
, 'course' => $course->id
)));
69 $PAGE->navbar
->add(get_string('notes', 'notes'),
70 new moodle_url('/notes/index.php', array('user' => $user->id
, 'course' => $course->id
)));
71 $PAGE->navbar
->add(get_string('delete'));
72 $PAGE->set_title($course->shortname
. ': ' . $strnotes);
73 $PAGE->set_heading($course->fullname
);
74 echo $OUTPUT->header();
75 echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'),
76 new moodle_url('delete.php', $optionsyes),
77 new moodle_url('index.php', $optionsno));
79 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD
);
80 echo $OUTPUT->footer();