MDL-40010 notes: passing an object rather than an id to avoid debugging message
[moodle.git] / notes / delete.php
CommitLineData
2f4a2f27 1<?php
83e70cc2 2
3require_once('../config.php');
4require_once('lib.php');
5
6// retrieve parameters
241bcec5 7$noteid = required_param('id', PARAM_INT);
83e70cc2 8
a6855934 9$PAGE->set_url('/notes/delete.php', array('id'=>$noteid));
2f4a2f27 10
83e70cc2 11// locate note information
12if (!$note = note_load($noteid)) {
38eac4d5 13 print_error('invalidid');
83e70cc2 14}
15
16// locate course information
b3829d0a 17if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
38eac4d5 18 print_error('invalidcourseid');
83e70cc2 19}
b26adbef 20
21// locate user information
b3829d0a 22 if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
38eac4d5 23 print_error('invaliduserid');
b26adbef 24 }
25
83e70cc2 26// require login to access notes
241bcec5 27require_login($course);
83e70cc2 28
29// locate context information
bf0f06b1 30$context = context_course::instance($course->id);
83e70cc2 31
32// check capability
33if (!has_capability('moodle/notes:manage', $context)) {
38eac4d5 34 print_error('nopermissiontodelete', 'notes');
83e70cc2 35}
36
90658eef 37if (empty($CFG->enablenotes)) {
38 print_error('notesdisabled', 'notes');
39}
40
294ce987 41if (data_submitted() && confirm_sesskey()) {
83e70cc2 42//if data was submitted and is valid, then delete note
43 $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $note->userid;
ec162527 44 if (!note_delete($note)) {
38eac4d5 45 print_error('cannotdeletepost', 'notes', $returnurl);
83e70cc2 46 }
47 redirect($returnurl);
241bcec5 48
83e70cc2 49} else {
50// if data was not submitted yet, then show note data with a delete confirmation form
51 $strnotes = get_string('notes', 'notes');
241bcec5 52 $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey());
53 $optionsno = array('course'=>$course->id, 'user'=>$note->userid);
83e70cc2 54
55// output HTML
fb676024 56 $link = null;
bf0f06b1 57 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
a6855934 58 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
b26adbef 59 }
fb676024 60 $PAGE->navbar->add(get_string('participants'), $link);
a6855934
PS
61 $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
62 $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
fb676024 63 $PAGE->navbar->add(get_string('delete'));
64 $PAGE->set_title($course->shortname . ': ' . $strnotes);
65 $PAGE->set_heading($course->fullname);
66 echo $OUTPUT->header();
4fa7dc61 67 echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'), new moodle_url('delete.php',$optionsyes), new moodle_url('index.php',$optionsno));
83e70cc2 68 echo '<br />';
69 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
3c1d69dd 70 echo $OUTPUT->footer();
db4ff7f8 71}