3 require_once('../config.php');
4 require_once('lib.php');
7 $noteid = required_param('note', PARAM_INT
);
9 // locate note information
10 if (!$note = note_load($noteid)) {
11 error('Incorrect note id specified');
14 // locate course information
15 if (!$course = get_record('course', 'id', $note->courseid
)) {
16 error('Incorrect course id found');
19 // locate context information
20 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
23 if (!has_capability('moodle/notes:manage', $context)) {
24 error('You may not modify notes');
28 require_once('edit_form.php');
29 // get option values for the user select
30 $extradata['userlist'] = array();
31 if ($course->id
== SITEID
) {
32 $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id={$userid}";
34 $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})";
36 $userlist = get_records_sql($usersincourse);
37 // format userdata using fullname
39 foreach($userlist as $user) {
40 $extradata['userlist'][$user->id
] = fullname($user);
44 $noteform = new note_edit_form(null, $extradata);
46 // if form was cancelled then return to the notes list of the note
47 if ($noteform->is_cancelled()) {
48 redirect($CFG->wwwroot
. '/notes/index.php?course=' . $note->courseid
. '&user=' . $note->userid
);
51 // if data was submitted and validated, then save it to database
52 if ($formdata = $noteform->get_data()){
53 $note->courseid
= $formdata->course
;
54 $note->userid
= $formdata->user
;
55 $note->content
= $formdata->content
;
56 $note->format
= FORMAT_PLAIN
;
57 $note->rating
= $formdata->rating
;
58 $note->publishstate
= $formdata->publishstate
;
59 if (note_save($note)) {
60 add_to_log($note->courseid
, 'notes', 'update', 'index.php?course='.$note->courseid
.'&user='.$note->userid
. '#note-' . $note->id
, 'update note');
62 // redirect to notes list that contains this note
63 redirect($CFG->wwwroot
. '/notes/index.php?course=' . $note->courseid
. '&user=' . $note->userid
);
67 if($noteform->is_submitted()) {
68 // if data was submitted with errors, then use it as default for new form
69 $note = $noteform->get_submitted_data(false);
71 // if data was not submitted yet, then used values retrieved from the database
72 $note->user
= $note->userid
;
73 $note->course
= $note->courseid
;
74 $note->note
= $note->id
;
76 $noteform->set_data($note);
77 $strnotes = get_string('notes', 'notes');
80 print_header($course->shortname
. ': ' . $strnotes, $course->fullname
);