MDL-3714 mod_forum: Add an inbound message handler
[moodle.git] / notes / delete.php
blobccd2b16f045e44a595808e2e31c9eedac70a708b
1 <?php
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.
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 . '&amp;user=' . $note->userid;
51 if (!note_delete($note)) {
52 print_error('cannotdeletepost', 'notes', $returnurl);
54 redirect($returnurl);
56 } else {
57 // If data was not submitted yet, then show note data with a delete confirmation form.
58 $strnotes = get_string('notes', 'notes');
59 $optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
60 $optionsno = array('course' => $course->id, 'user' => $note->userid);
62 // Output HTML.
63 $link = null;
64 if (has_capability('moodle/course:viewparticipants', $context)
65 || has_capability('moodle/site:viewparticipants', context_system::instance())) {
67 $link = new moodle_url('/user/index.php', array('id' => $course->id));
69 $PAGE->navbar->add(get_string('participants'), $link);
70 $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));
71 $PAGE->navbar->add(get_string('notes', 'notes'),
72 new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $course->id)));
73 $PAGE->navbar->add(get_string('delete'));
74 $PAGE->set_title($course->shortname . ': ' . $strnotes);
75 $PAGE->set_heading($course->fullname);
76 echo $OUTPUT->header();
77 echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'),
78 new moodle_url('delete.php', $optionsyes),
79 new moodle_url('index.php', $optionsno));
80 echo '<br />';
81 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
82 echo $OUTPUT->footer();