Merge branch 'wip-MDL-29006-m21' of git://github.com/samhemelryk/moodle into MOODLE_2...
[moodle.git] / notes / delete.php
blobf69f103bd44cecd7d278bd1bc6dda572307c4a4e
1 <?php
3 require_once('../config.php');
4 require_once('lib.php');
6 // retrieve parameters
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 = get_context_instance(CONTEXT_COURSE, $course->id);
32 // check capability
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 . '&amp;user=' . $note->userid;
44 if (note_delete($noteid)) {
45 add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'delete note');
46 } else {
47 print_error('cannotdeletepost', 'notes', $returnurl);
49 redirect($returnurl);
51 } else {
52 // if data was not submitted yet, then show note data with a delete confirmation form
53 $strnotes = get_string('notes', 'notes');
54 $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey());
55 $optionsno = array('course'=>$course->id, 'user'=>$note->userid);
57 // output HTML
58 $link = null;
59 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
60 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
62 $PAGE->navbar->add(get_string('participants'), $link);
63 $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
64 $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
65 $PAGE->navbar->add(get_string('delete'));
66 $PAGE->set_title($course->shortname . ': ' . $strnotes);
67 $PAGE->set_heading($course->fullname);
68 echo $OUTPUT->header();
69 echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'), new moodle_url('delete.php',$optionsyes), new moodle_url('index.php',$optionsno));
70 echo '<br />';
71 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
72 echo $OUTPUT->footer();