3 require_once('../config.php');
4 require_once('lib.php');
7 $noteid = required_param('note', 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');
18 // require login to access notes
19 require_login($course->id
);
21 // locate context information
22 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
25 if (!has_capability('moodle/notes:manage', $context)) {
26 error('You may not delete this note');
29 if (data_submitted() && confirm_sesskey()) {
30 //if data was submitted and is valid, then delete note
31 $returnurl = $CFG->wwwroot
. '/notes/index.php?course=' . $course->id
. '&user=' . $note->userid
;
32 if (note_delete($noteid)) {
33 add_to_log($note->courseid
, 'notes', 'delete', 'index.php?course='.$note->courseid
.'&user='.$note->userid
. '#note-' . $note->id
, 'delete note');
35 error('Error occured while deleting post', $returnurl);
39 // if data was not submitted yet, then show note data with a delete confirmation form
40 $strnotes = get_string('notes', 'notes');
41 $optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey());
42 $optionsno = array('course'=>$course->id
, 'user'=>$note->userid
);
45 $crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));
46 print_header($course->shortname
. ': ' . $strnotes, $course->fullname
, build_navigation($crumbs));
47 notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
49 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD
);