2009-09-29 03:52:43 +00:00
|
|
|
<?php
|
2014-07-10 16:16:26 +08:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2007-08-31 04:05:11 +00:00
|
|
|
|
|
|
|
require_once('../config.php');
|
|
|
|
require_once('lib.php');
|
2017-08-30 15:11:20 +08:00
|
|
|
require_once($CFG->dirroot . '/course/lib.php');
|
2007-08-31 04:05:11 +00:00
|
|
|
|
2008-08-21 21:40:29 +00:00
|
|
|
$noteid = required_param('id', PARAM_INT);
|
2007-08-31 04:05:11 +00:00
|
|
|
|
2014-07-10 16:16:26 +08:00
|
|
|
$PAGE->set_url('/notes/delete.php', array('id' => $noteid));
|
2009-09-29 03:52:43 +00:00
|
|
|
|
2007-08-31 04:05:11 +00:00
|
|
|
if (!$note = note_load($noteid)) {
|
2008-06-13 06:50:06 +00:00
|
|
|
print_error('invalidid');
|
2007-08-31 04:05:11 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 16:16:26 +08:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $note->courseid))) {
|
2008-06-13 06:50:06 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-08-31 04:05:11 +00:00
|
|
|
}
|
2008-01-10 10:58:16 +00:00
|
|
|
|
2008-08-21 21:40:29 +00:00
|
|
|
require_login($course);
|
2007-08-31 04:05:11 +00:00
|
|
|
|
2014-07-10 10:57:39 +08:00
|
|
|
if (empty($CFG->enablenotes)) {
|
|
|
|
print_error('notesdisabled', 'notes');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
|
|
|
|
print_error('invaliduserid');
|
|
|
|
}
|
|
|
|
|
2012-08-02 11:20:48 +08:00
|
|
|
$context = context_course::instance($course->id);
|
2007-08-31 04:05:11 +00:00
|
|
|
|
|
|
|
if (!has_capability('moodle/notes:manage', $context)) {
|
2008-06-13 06:50:06 +00:00
|
|
|
print_error('nopermissiontodelete', 'notes');
|
2007-08-31 04:05:11 +00:00
|
|
|
}
|
|
|
|
|
2008-06-09 16:53:30 +00:00
|
|
|
if (data_submitted() && confirm_sesskey()) {
|
2014-07-10 16:16:26 +08:00
|
|
|
// If data was submitted and is valid, then delete note.
|
2007-08-31 04:05:11 +00:00
|
|
|
$returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $note->userid;
|
2015-07-13 15:05:16 +02:00
|
|
|
note_delete($note);
|
2007-08-31 04:05:11 +00:00
|
|
|
redirect($returnurl);
|
2008-08-21 21:40:29 +00:00
|
|
|
|
2007-08-31 04:05:11 +00:00
|
|
|
} else {
|
2014-07-10 16:16:26 +08:00
|
|
|
// If data was not submitted yet, then show note data with a delete confirmation form.
|
2007-08-31 04:05:11 +00:00
|
|
|
$strnotes = get_string('notes', 'notes');
|
2014-07-10 16:16:26 +08:00
|
|
|
$optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
|
|
|
|
$optionsno = array('course' => $course->id, 'user' => $note->userid);
|
2007-08-31 04:05:11 +00:00
|
|
|
|
2014-07-10 16:16:26 +08:00
|
|
|
// Output HTML.
|
2009-09-07 05:31:58 +00:00
|
|
|
$link = null;
|
2017-08-30 15:11:20 +08:00
|
|
|
if (course_can_view_participants($context) || course_can_view_participants(context_system::instance())) {
|
2014-07-10 16:16:26 +08:00
|
|
|
$link = new moodle_url('/user/index.php', array('id' => $course->id));
|
2008-01-10 10:58:16 +00:00
|
|
|
}
|
2009-09-07 05:31:58 +00:00
|
|
|
$PAGE->navbar->add(get_string('participants'), $link);
|
2014-07-10 16:16:26 +08:00
|
|
|
$PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));
|
|
|
|
$PAGE->navbar->add(get_string('notes', 'notes'),
|
|
|
|
new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $course->id)));
|
2009-09-07 05:31:58 +00:00
|
|
|
$PAGE->navbar->add(get_string('delete'));
|
|
|
|
$PAGE->set_title($course->shortname . ': ' . $strnotes);
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
echo $OUTPUT->header();
|
2014-07-10 16:16:26 +08:00
|
|
|
echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'),
|
|
|
|
new moodle_url('delete.php', $optionsyes),
|
|
|
|
new moodle_url('index.php', $optionsno));
|
2007-08-31 04:05:11 +00:00
|
|
|
echo '<br />';
|
|
|
|
note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
|
2009-08-06 14:25:20 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-09-28 07:21:48 +00:00
|
|
|
}
|