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 // require login to access notes
22 require_login($course);
24 if (empty($CFG->enablenotes)) {
25 print_error('notesdisabled', 'notes');
28 if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
29 print_error('invaliduserid');
32 // locate context information
33 $context = context_course::instance($course->id);
36 if (!has_capability('moodle/notes:manage', $context)) {
37 print_error('nopermissiontodelete', 'notes');
40 if (data_submitted() && confirm_sesskey()) {
41 //if data was submitted and is valid, then delete note
42 $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $note->userid;
43 if (!note_delete($note)) {
44 print_error('cannotdeletepost', 'notes', $returnurl);
49 // if data was not submitted yet, then show note data with a delete confirmation form
50 $strnotes = get_string('notes', 'notes');
51 $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey());
52 $optionsno = array('course'=>$course->id, 'user'=>$note->userid);
56 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
57 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
59 $PAGE->navbar->add(get_string('participants'), $link);
60 $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
61 $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
62 $PAGE->navbar->add(get_string('delete'));
63 $PAGE->set_title($course->shortname . ': ' . $strnotes);
64 $PAGE->set_heading($course->fullname);
65 echo $OUTPUT->header();
66 echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'), new moodle_url('delete.php',$optionsyes), new moodle_url('index.php',$optionsno));
68 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
69 echo $OUTPUT->footer();