3 require_once('../config.php');
4 require_once('lib.php');
7 $noteid = required_param('id', PARAM_INT
);
9 $PAGE->set_url('/notes/delete.php', array('id'=>$noteid));
11 // locate note information
12 if (!$note = note_load($noteid)) {
13 print_error('invalidid');
16 // locate course information
17 if (!$course = $DB->get_record('course', array('id'=>$note->courseid
))) {
18 print_error('invalidcourseid');
21 // locate user information
22 if (!$user = $DB->get_record('user', array('id'=>$note->userid
))) {
23 print_error('invaliduserid');
26 // require login to access notes
27 require_login($course);
29 // locate context information
30 $context = context_course
::instance($course->id
);
33 if (!has_capability('moodle/notes:manage', $context)) {
34 print_error('nopermissiontodelete', 'notes');
37 if (empty($CFG->enablenotes
)) {
38 print_error('notesdisabled', 'notes');
41 if (data_submitted() && confirm_sesskey()) {
42 //if data was submitted and is valid, then delete note
43 $returnurl = $CFG->wwwroot
. '/notes/index.php?course=' . $course->id
. '&user=' . $note->userid
;
44 if (!note_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
);
57 if (has_capability('moodle/course:viewparticipants', $context) ||
has_capability('moodle/site:viewparticipants', context_system
::instance())) {
58 $link = new moodle_url('/user/index.php',array('id'=>$course->id
));
60 $PAGE->navbar
->add(get_string('participants'), $link);
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
)));
63 $PAGE->navbar
->add(get_string('delete'));
64 $PAGE->set_title($course->shortname
. ': ' . $strnotes);
65 $PAGE->set_heading($course->fullname
);
66 echo $OUTPUT->header();
67 echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'), new moodle_url('delete.php',$optionsyes), new moodle_url('index.php',$optionsno));
69 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD
);
70 echo $OUTPUT->footer();