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');
18 // require login to access notes
19 require_login($course->id
);
21 // locate context information
22 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
25 if (!has_capability('moodle/notes:manage', $context)) {
26 error('You may not modify notes');
30 require_once('edit_form.php');
31 // get option values for the user select
32 $extradata['userlist'] = array();
33 if ($course->id
== SITEID
) {
34 $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id={$userid}";
36 $usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})";
38 $userlist = get_records_sql($usersincourse);
39 // format userdata using fullname
41 foreach($userlist as $user) {
42 $extradata['userlist'][$user->id
] = fullname($user);
46 $noteform = new note_edit_form(null, $extradata);
48 // if form was cancelled then return to the notes list of the note
49 if ($noteform->is_cancelled()) {
50 redirect($CFG->wwwroot
. '/notes/index.php?course=' . $note->courseid
. '&user=' . $note->userid
);
53 // if data was submitted and validated, then save it to database
54 if ($formdata = $noteform->get_data()){
55 $note->courseid
= $formdata->course
;
56 $note->userid
= $formdata->user
;
57 $note->content
= $formdata->content
;
58 $note->format
= FORMAT_PLAIN
;
59 $note->publishstate
= $formdata->publishstate
;
60 if (note_save($note)) {
61 add_to_log($note->courseid
, 'notes', 'update', 'index.php?course='.$note->courseid
.'&user='.$note->userid
. '#note-' . $note->id
, 'update note');
63 // redirect to notes list that contains this note
64 redirect($CFG->wwwroot
. '/notes/index.php?course=' . $note->courseid
. '&user=' . $note->userid
);
68 if($noteform->is_submitted()) {
69 // if data was submitted with errors, then use it as default for new form
70 $note = $noteform->get_submitted_data(false);
72 // if data was not submitted yet, then used values retrieved from the database
73 $note->user
= $note->userid
;
74 $note->course
= $note->courseid
;
75 $note->note
= $note->id
;
77 $noteform->set_data($note);
78 $strnotes = get_string('editnote', 'notes');
81 $crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));
82 print_header($course->shortname
. ': ' . $strnotes, $course->fullname
, build_navigation($crumbs));