|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 require_once('../config.php'); 00004 require_once('lib.php'); 00005 00006 // retrieve parameters 00007 $noteid = required_param('id', PARAM_INT); 00008 00009 $PAGE->set_url('/notes/delete.php', array('id'=>$noteid)); 00010 00011 // locate note information 00012 if (!$note = note_load($noteid)) { 00013 print_error('invalidid'); 00014 } 00015 00016 // locate course information 00017 if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) { 00018 print_error('invalidcourseid'); 00019 } 00020 00021 // locate user information 00022 if (!$user = $DB->get_record('user', array('id'=>$note->userid))) { 00023 print_error('invaliduserid'); 00024 } 00025 00026 // require login to access notes 00027 require_login($course); 00028 00029 // locate context information 00030 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00031 00032 // check capability 00033 if (!has_capability('moodle/notes:manage', $context)) { 00034 print_error('nopermissiontodelete', 'notes'); 00035 } 00036 00037 if (empty($CFG->enablenotes)) { 00038 print_error('notesdisabled', 'notes'); 00039 } 00040 00041 if (data_submitted() && confirm_sesskey()) { 00042 //if data was submitted and is valid, then delete note 00043 $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $note->userid; 00044 if (note_delete($noteid)) { 00045 add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'delete note'); 00046 } else { 00047 print_error('cannotdeletepost', 'notes', $returnurl); 00048 } 00049 redirect($returnurl); 00050 00051 } else { 00052 // if data was not submitted yet, then show note data with a delete confirmation form 00053 $strnotes = get_string('notes', 'notes'); 00054 $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey()); 00055 $optionsno = array('course'=>$course->id, 'user'=>$note->userid); 00056 00057 // output HTML 00058 $link = null; 00059 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) { 00060 $link = new moodle_url('/user/index.php',array('id'=>$course->id)); 00061 } 00062 $PAGE->navbar->add(get_string('participants'), $link); 00063 $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$course->id))); 00064 $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user'=>$user->id,'course'=>$course->id))); 00065 $PAGE->navbar->add(get_string('delete')); 00066 $PAGE->set_title($course->shortname . ': ' . $strnotes); 00067 $PAGE->set_heading($course->fullname); 00068 echo $OUTPUT->header(); 00069 echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'), new moodle_url('delete.php',$optionsyes), new moodle_url('index.php',$optionsno)); 00070 echo '<br />'; 00071 note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD); 00072 echo $OUTPUT->footer(); 00073 }