files MDL-19799 Updated print_header and build_navigation to OUTPUT and PAGE equivalents
[moodle.git] / notes / delete.php
CommitLineData
83e70cc2 1<?php // $Id$
2
3require_once('../config.php');
4require_once('lib.php');
5
6// retrieve parameters
241bcec5 7$noteid = required_param('id', PARAM_INT);
83e70cc2 8
9// locate note information
10if (!$note = note_load($noteid)) {
38eac4d5 11 print_error('invalidid');
83e70cc2 12}
13
14// locate course information
b3829d0a 15if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
38eac4d5 16 print_error('invalidcourseid');
83e70cc2 17}
b26adbef 18
19// locate user information
b3829d0a 20 if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
38eac4d5 21 print_error('invaliduserid');
b26adbef 22 }
23
83e70cc2 24// require login to access notes
241bcec5 25require_login($course);
83e70cc2 26
27// locate context information
28$context = get_context_instance(CONTEXT_COURSE, $course->id);
29
30// check capability
31if (!has_capability('moodle/notes:manage', $context)) {
38eac4d5 32 print_error('nopermissiontodelete', 'notes');
83e70cc2 33}
34
90658eef 35if (empty($CFG->enablenotes)) {
36 print_error('notesdisabled', 'notes');
37}
38
294ce987 39if (data_submitted() && confirm_sesskey()) {
83e70cc2 40//if data was submitted and is valid, then delete note
41 $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $note->userid;
42 if (note_delete($noteid)) {
43 add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'delete note');
44 } else {
38eac4d5 45 print_error('cannotdeletepost', 'notes', $returnurl);
83e70cc2 46 }
47 redirect($returnurl);
241bcec5 48
83e70cc2 49} else {
50// if data was not submitted yet, then show note data with a delete confirmation form
51 $strnotes = get_string('notes', 'notes');
241bcec5 52 $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey());
53 $optionsno = array('course'=>$course->id, 'user'=>$note->userid);
83e70cc2 54
55// output HTML
b26adbef 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');
58 }
59 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
60 $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;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));
4fa7dc61 63 echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'), new moodle_url('delete.php',$optionsyes), new moodle_url('index.php',$optionsno));
83e70cc2 64 echo '<br />';
65 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
3c1d69dd 66 echo $OUTPUT->footer();
db4ff7f8 67}
5a2a5331 68?>