Fixed some notices on some custom pages
[moodle.git] / notes / delete.php
CommitLineData
eca3af25 1<?php // $Id$\r
2\r
3require_once('../config.php');\r
4require_once('lib.php');\r
5\r
6// retrieve parameters\r
7$noteid = required_param('note', PARAM_INT);\r
8\r
9// locate note information\r
10if (!$note = note_load($noteid)) {\r
11 error('Incorrect note id specified');\r
12}\r
13\r
14// locate course information\r
15if (!$course = get_record('course', 'id', $note->courseid)) {\r
16 error('Incorrect course id found');\r
17}\r
c55dee3f 18// require login to access notes\r
19require_login($course->id);\r
eca3af25 20\r
21// locate context information\r
22$context = get_context_instance(CONTEXT_COURSE, $course->id);\r
23\r
24// check capability\r
25if (!has_capability('moodle/notes:manage', $context)) {\r
26 error('You may not delete this note');\r
27}\r
28\r
29if (data_submitted() && confirm_sesskey()) {\r
30//if data was submitted and is valid, then delete note\r
31 $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $note->userid;\r
32 if (note_delete($noteid)) {\r
33 add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'delete note');\r
34 } else {\r
35 error('Error occured while deleting post', $returnurl);\r
36 }\r
37 redirect($returnurl);\r
38} else {\r
39// if data was not submitted yet, then show note data with a delete confirmation form\r
40 $strnotes = get_string('notes', 'notes');\r
41 $optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey());\r
42 $optionsno = array('course'=>$course->id, 'user'=>$note->userid);\r
c55dee3f 43\r
44// output HTML\r
45 $crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));\r
46 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs));\r
eca3af25 47 notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');\r
48 echo '<br />';\r
49 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);\r
50 print_footer();\r
c55dee3f 51}