Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / notes / delete.php
blobdc17409b3ccaf8fae2db5a4cdde28f262d62c7a4
1 <?php // $Id$
3 require_once('../config.php');
4 require_once('lib.php');
6 // retrieve parameters
7 $noteid = required_param('note', PARAM_INT);
9 // locate note information
10 if (!$note = note_load($noteid)) {
11 error('Incorrect note id specified');
14 // locate course information
15 if (!$course = get_record('course', 'id', $note->courseid)) {
16 error('Incorrect course id found');
19 // locate user information
20 if (!$user = get_record('user', 'id', $note->userid)) {
21 error('Incorrect user id found');
24 // require login to access notes
25 require_login($course->id);
27 // locate context information
28 $context = get_context_instance(CONTEXT_COURSE, $course->id);
30 // check capability
31 if (!has_capability('moodle/notes:manage', $context)) {
32 error('You may not delete this note');
35 if (data_submitted() && confirm_sesskey()) {
36 //if data was submitted and is valid, then delete note
37 $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $note->userid;
38 if (note_delete($noteid)) {
39 add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'delete note');
40 } else {
41 error('Error occured while deleting post', $returnurl);
43 redirect($returnurl);
44 } else {
45 // if data was not submitted yet, then show note data with a delete confirmation form
46 $strnotes = get_string('notes', 'notes');
47 $optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey());
48 $optionsno = array('course'=>$course->id, 'user'=>$note->userid);
50 // output HTML
51 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
52 $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
54 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
55 $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $user->id, 'type' => 'misc');
56 $nav[] = array('name' => get_string('delete'), 'link' => '', 'type' => 'activity');
57 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
58 notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
59 echo '<br />';
60 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
61 print_footer();