2009-09-29 03:52:43 +00:00
|
|
|
<?php
|
2007-08-31 04:05:11 +00:00
|
|
|
|
2009-09-29 03:52:43 +00:00
|
|
|
require_once('../config.php');
|
|
|
|
require_once('lib.php');
|
|
|
|
require_once('edit_form.php');
|
2007-08-31 04:35:42 +00:00
|
|
|
|
|
|
|
/// retrieve parameters
|
2009-09-29 03:52:43 +00:00
|
|
|
$noteid = optional_param('id', 0, PARAM_INT);
|
2007-08-31 04:35:42 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/notes/edit.php');
|
2009-09-29 03:52:43 +00:00
|
|
|
|
|
|
|
if ($noteid) {
|
|
|
|
//existing note
|
|
|
|
$url->param('id', $noteid);
|
|
|
|
if (!$note = note_load($noteid)) {
|
|
|
|
print_error('invalidid', 'notes');
|
2007-08-31 04:35:42 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 03:52:43 +00:00
|
|
|
} else {
|
|
|
|
// adding new note
|
|
|
|
$courseid = required_param('courseid', PARAM_INT);
|
|
|
|
$userid = required_param('userid', PARAM_INT);
|
|
|
|
$state = optional_param('publishstate', NOTES_STATE_PUBLIC, PARAM_ALPHA);
|
|
|
|
|
2010-09-21 08:19:28 +00:00
|
|
|
$note = new stdClass();
|
2009-09-29 03:52:43 +00:00
|
|
|
$note->courseid = $courseid;
|
|
|
|
$note->userid = $userid;
|
|
|
|
$note->publishstate = $state;
|
|
|
|
|
|
|
|
$url->param('courseid', $courseid);
|
|
|
|
$url->param('userid', $userid);
|
2010-05-04 13:04:35 +00:00
|
|
|
if ($state !== NOTES_STATE_PUBLIC) {
|
|
|
|
$url->param('publishstate', $state);
|
2007-08-31 04:35:42 +00:00
|
|
|
}
|
2009-09-29 03:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$PAGE->set_url($url);
|
|
|
|
|
|
|
|
/// locate course information
|
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
|
|
|
|
print_error('invalidcourseid');
|
|
|
|
}
|
|
|
|
|
2007-08-31 04:35:42 +00:00
|
|
|
/// require login to access notes
|
2009-09-29 03:52:43 +00:00
|
|
|
require_login($course);
|
2007-08-31 04:35:42 +00:00
|
|
|
|
2014-07-10 10:57:39 +08:00
|
|
|
if (empty($CFG->enablenotes)) {
|
|
|
|
print_error('notesdisabled', 'notes');
|
|
|
|
}
|
|
|
|
|
2007-08-31 04:35:42 +00:00
|
|
|
/// locate context information
|
2012-08-02 11:20:48 +08:00
|
|
|
$context = context_course::instance($course->id);
|
2009-09-29 03:52:43 +00:00
|
|
|
require_capability('moodle/notes:manage', $context);
|
2007-08-31 04:35:42 +00:00
|
|
|
|
2014-07-10 10:57:39 +08:00
|
|
|
if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
|
|
|
|
print_error('invaliduserid');
|
2009-09-29 03:52:43 +00:00
|
|
|
}
|
2008-08-26 05:45:07 +00:00
|
|
|
|
2007-08-31 04:35:42 +00:00
|
|
|
/// create form
|
2009-09-29 03:52:43 +00:00
|
|
|
$noteform = new note_edit_form();
|
2007-08-31 04:35:42 +00:00
|
|
|
|
2008-08-21 21:40:29 +00:00
|
|
|
/// set defaults
|
2009-09-29 03:52:43 +00:00
|
|
|
$noteform->set_data($note);
|
2008-08-21 21:40:29 +00:00
|
|
|
|
2007-08-31 04:35:42 +00:00
|
|
|
/// if form was cancelled then return to the notes list of the note
|
2009-09-29 03:52:43 +00:00
|
|
|
if ($noteform->is_cancelled()) {
|
|
|
|
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid);
|
|
|
|
}
|
2007-08-31 04:35:42 +00:00
|
|
|
|
|
|
|
/// if data was submitted and validated, then save it to database
|
2009-09-29 03:52:43 +00:00
|
|
|
if ($note = $noteform->get_data()){
|
2013-03-05 15:17:11 +08:00
|
|
|
if ($noteid) {
|
|
|
|
// A noteid has been used, we don't allow editing of course or user so
|
|
|
|
// lets unset them to be sure we never change that by accident.
|
|
|
|
unset($note->courseid);
|
|
|
|
unset($note->userid);
|
|
|
|
}
|
2013-01-07 12:01:22 +08:00
|
|
|
note_save($note);
|
2009-09-29 03:52:43 +00:00
|
|
|
// redirect to notes list that contains this note
|
|
|
|
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid);
|
|
|
|
}
|
2007-08-31 04:35:42 +00:00
|
|
|
|
2009-09-29 03:52:43 +00:00
|
|
|
if ($noteid) {
|
|
|
|
$strnotes = get_string('editnote', 'notes');
|
|
|
|
} else {
|
|
|
|
$strnotes = get_string('addnewnote', 'notes');
|
|
|
|
}
|
2007-08-31 04:35:42 +00:00
|
|
|
|
|
|
|
/// output HTML
|
2009-09-29 03:52:43 +00:00
|
|
|
$link = null;
|
2012-08-02 11:20:48 +08:00
|
|
|
if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
|
2010-01-16 15:39:56 +00:00
|
|
|
$link = new moodle_url('/user/index.php',array('id'=>$course->id));
|
2009-09-29 03:52:43 +00:00
|
|
|
}
|
|
|
|
$PAGE->navbar->add(get_string('participants'), $link);
|
2010-01-16 15:39:56 +00: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-29 03:52:43 +00:00
|
|
|
$PAGE->navbar->add($strnotes);
|
|
|
|
$PAGE->set_title($course->shortname . ': ' . $strnotes);
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo $OUTPUT->heading(fullname($user));
|
|
|
|
|
|
|
|
$noteform->display();
|
2009-11-01 12:22:45 +00:00
|
|
|
echo $OUTPUT->footer();
|