MDL-12221 - use theme variables so it doesn't break on my setup ;)
[moodle.git] / notes / delete.php
CommitLineData
83e70cc2 1<?php // $Id$
2
3require_once('../config.php');
4require_once('lib.php');
5
6// retrieve parameters
7$noteid = required_param('note', PARAM_INT);
8
9// locate note information
10if (!$note = note_load($noteid)) {
11 error('Incorrect note id specified');
12}
13
14// locate course information
15if (!$course = get_record('course', 'id', $note->courseid)) {
16 error('Incorrect course id found');
17}
18// require login to access notes
19require_login($course->id);
20
21// locate context information
22$context = get_context_instance(CONTEXT_COURSE, $course->id);
23
24// check capability
25if (!has_capability('moodle/notes:manage', $context)) {
26 error('You may not delete this note');
27}
28
29if (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 . '&amp;user=' . $note->userid;
32 if (note_delete($noteid)) {
33 add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'delete note');
34 } else {
35 error('Error occured while deleting post', $returnurl);
36 }
37 redirect($returnurl);
38} else {
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);
43
44// output HTML
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');
48 echo '<br />';
49 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
50 print_footer();
db4ff7f8 51}
52?>