3 require_once('../config.php');
4 require_once('lib.php');
6 /// retrieve parameters
7 $courseid = required_param('course', PARAM_INT
);
8 $userid = required_param('user', PARAM_INT
);
10 /// locate course information
11 if (!($course = get_record('course', 'id', $courseid))) {
12 error('Incorrect course id found');
15 /// require login to access notes
16 require_login($course->id
);
18 /// locate context information
19 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
22 require_capability('moodle/notes:manage', $context);
25 /// locate user information
26 if (!($user = get_record('user', 'id', $userid))) {
27 error('Incorrect user id found');
31 require_once('edit_form.php');
34 $noteform = new note_edit_form();
36 /// if form was cancelled then return to the previous notes list
37 if ($noteform->is_cancelled()) {
38 redirect($CFG->wwwroot
. '/notes/index.php?course=' . $courseid . '&user=' . $userid);
41 /// if data was submitted and validated, then save it to database
42 if ($formdata = $noteform->get_data()) {
44 $note->courseid
= $formdata->course
;
45 $note->content
= $formdata->content
;
46 $note->format
= FORMAT_PLAIN
;
47 $note->userid
= $formdata->user
;
48 $note->publishstate
= $formdata->publishstate
;
49 if (note_save($note)) {
50 add_to_log($note->courseid
, 'notes', 'add', 'index.php?course='.$note->courseid
.'&user='.$note->userid
. '#note-' . $note->id
, 'add note');
52 // redirect to notes list that contains this note
53 redirect($CFG->wwwroot
. '/notes/index.php?course=' . $note->courseid
. '&user=' . $note->userid
);
56 if($noteform->is_submitted()) {
57 // if data was submitted with errors, then use it as default for new form
58 $note = $noteform->get_submitted_data(false);
60 // if data was not submitted yet, then use default values
63 $note->course
= $courseid;
64 $note->user
= $userid;
65 $note->publishstate
= optional_param('state', NOTES_STATE_PUBLIC
, PARAM_ALPHA
);
67 $noteform->set_data($note);
68 $strnotes = get_string('addnewnote', 'notes');
72 if (has_capability('moodle/course:viewparticipants', $context) ||
has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM
))) {
73 $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot
. '/user/index.php?id=' . $course->id
, 'type' => 'misc');
75 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot
. '/user/view.php?id=' . $user->id
. '&course=' . $course->id
, 'type' => 'misc');
76 $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot
. '/notes/index.php?course=' . $course->id
. '&user=' . $user->id
, 'type' => 'misc');
77 $nav[] = array('name' => $strnotes, 'link' => '', 'type' => 'activity');
79 print_header($course->shortname
. ': ' . $strnotes, $course->fullname
, build_navigation($nav));
81 print_heading(fullname($user));