3 require_once('../config.php');
4 require_once('lib.php');
7 $noteid = required_param('id', PARAM_INT
);
9 // locate note information
10 if (!$note = note_load($noteid)) {
11 error('Incorrect note id specified');
14 // locate course information
15 if (!$course = get_record('course', 'id', $note->courseid
)) {
16 error('Incorrect course id found');
19 // locate user information
20 if (!$user = get_record('user', 'id', $note->userid
)) {
21 error('Incorrect user id found');
24 // require login to access notes
25 require_login($course);
27 // locate context information
28 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
31 if (!has_capability('moodle/notes:manage', $context)) {
32 print_error('nopermissiontodelete', 'notes');
35 if (empty($CFG->enablenotes
)) {
36 print_error('notesdisabled', 'notes');
39 if (data_submitted() && confirm_sesskey()) {
40 //if data was submitted and is valid, then delete note
41 $returnurl = $CFG->wwwroot
. '/notes/index.php?course=' . $course->id
. '&user=' . $note->userid
;
42 if (note_delete($noteid)) {
43 add_to_log($note->courseid
, 'notes', 'delete', 'index.php?course='.$note->courseid
.'&user='.$note->userid
. '#note-' . $note->id
, 'delete note');
45 print_error('cannotdeletepost', 'notes', $returnurl);
50 // if data was not submitted yet, then show note data with a delete confirmation form
51 $strnotes = get_string('notes', 'notes');
52 $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey());
53 $optionsno = array('course'=>$course->id
, 'user'=>$note->userid
);
56 if (has_capability('moodle/course:viewparticipants', $context) ||
has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM
))) {
57 $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot
. '/user/index.php?id=' . $course->id
, 'type' => 'misc');
59 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot
. '/user/view.php?id=' . $user->id
. '&course=' . $course->id
, 'type' => 'misc');
60 $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot
. '/notes/index.php?course=' . $course->id
. '&user=' . $user->id
, 'type' => 'misc');
61 $nav[] = array('name' => get_string('delete'), 'link' => '', 'type' => 'activity');
62 print_header($course->shortname
. ': ' . $strnotes, $course->fullname
, build_navigation($nav));
63 notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
65 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD
);