Some improvements to strings - translators should probably wait because there
[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
294ce987 35if (data_submitted() && confirm_sesskey()) {
83e70cc2 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 {
38eac4d5 41 print_error('cannotdeletepost', 'notes', $returnurl);
83e70cc2 42 }
43 redirect($returnurl);
241bcec5 44
83e70cc2 45} else {
46// if data was not submitted yet, then show note data with a delete confirmation form
47 $strnotes = get_string('notes', 'notes');
241bcec5 48 $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey());
49 $optionsno = array('course'=>$course->id, 'user'=>$note->userid);
83e70cc2 50
51// output HTML
b26adbef 52 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
53 $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
54 }
55 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
56 $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $user->id, 'type' => 'misc');
57 $nav[] = array('name' => get_string('delete'), 'link' => '', 'type' => 'activity');
58 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
83e70cc2 59 notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
60 echo '<br />';
61 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
62 print_footer();
db4ff7f8 63}
5a2a5331 64?>