3 require_once('../config.php');
4 require_once('lib.php');
5 require_once('edit_form.php');
7 /// retrieve parameters
8 $noteid = optional_param('id', 0, PARAM_INT);
10 $url = new moodle_url('/notes/edit.php');
14 $url->param('id', $noteid);
15 if (!$note = note_load($noteid)) {
16 print_error('invalidid', 'notes');
21 $courseid = required_param('courseid', PARAM_INT);
22 $userid = required_param('userid', PARAM_INT);
23 $state = optional_param('publishstate', NOTES_STATE_PUBLIC, PARAM_ALPHA);
25 $note = new stdClass();
26 $note->courseid = $courseid;
27 $note->userid = $userid;
28 $note->publishstate = $state;
30 $url->param('courseid', $courseid);
31 $url->param('userid', $userid);
32 if ($state !== NOTES_STATE_PUBLIC) {
33 $url->param('publishstate', $state);
39 /// locate course information
40 if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
41 print_error('invalidcourseid');
44 /// require login to access notes
45 require_login($course);
47 if (empty($CFG->enablenotes)) {
48 print_error('notesdisabled', 'notes');
51 /// locate context information
52 $context = context_course::instance($course->id);
53 require_capability('moodle/notes:manage', $context);
55 if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
56 print_error('invaliduserid');
60 $noteform = new note_edit_form();
63 $noteform->set_data($note);
65 /// if form was cancelled then return to the notes list of the note
66 if ($noteform->is_cancelled()) {
67 redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid);
70 /// if data was submitted and validated, then save it to database
71 if ($note = $noteform->get_data()){
73 // A noteid has been used, we don't allow editing of course or user so
74 // lets unset them to be sure we never change that by accident.
75 unset($note->courseid);
79 // redirect to notes list that contains this note
80 redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid);
84 $strnotes = get_string('editnote', 'notes');
86 $strnotes = get_string('addnewnote', 'notes');
91 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
92 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
94 $PAGE->navbar->add(get_string('participants'), $link);
95 $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
96 $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
97 $PAGE->navbar->add($strnotes);
98 $PAGE->set_title($course->shortname . ': ' . $strnotes);
99 $PAGE->set_heading($course->fullname);
101 echo $OUTPUT->header();
102 echo $OUTPUT->heading(fullname($user));
104 $noteform->display();
105 echo $OUTPUT->footer();