2 require_once("../config.php");
3 require_once($CFG->dirroot
.'/notes/lib.php');
5 $id = required_param('id', PARAM_INT
); // course id
6 $users = optional_param('userid', array(), PARAM_INT
); // array of user id
7 $content = optional_param('content', '', PARAM_RAW
); // note content
8 $state = optional_param('state', '', PARAM_ALPHA
); // note publish state
10 if (! $course = get_record('course', 'id', $id)) {
11 error("Course ID is incorrect");
14 $context = get_context_instance(CONTEXT_COURSE
, $id);
15 require_login($course->id
);
17 // to create notes the current user needs a capability
18 require_capability('moodle/notes:manage', $context);
20 if (!empty($users) && !empty($content) && confirm_sesskey()) {
22 $note->courseid
= $id;
23 $note->format
= FORMAT_PLAIN
;
24 $note->content
= $content;
25 $note->publishstate
= $state;
26 foreach ($users as $k => $v) {
27 if(!$user = get_record('user', 'id', $v)) {
32 if (note_save($note)) {
33 add_to_log($note->courseid
, 'notes', 'add', 'index.php?course='.$note->courseid
.'&user='.$note->userid
. '#note-' . $note->id
, 'add note');
37 redirect("$CFG->wwwroot/user/index.php?id=$id");
42 $straddnote = get_string('groupaddnewnote', 'notes');
43 if ($course->id
!= SITEID
) {
44 print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname
,
45 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> -> ".
46 $straddnote, "", "", true, " ", navmenu($course));
48 print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname
,
49 $straddnote, "", "", true, " ", navmenu($course));
52 // this will contain all available the based On select options, but we'll disable some on them on a per user basis
54 print_heading($straddnote);
55 echo '<form method="post" action="groupaddnote.php" >';
56 echo '<div style="width:100%;text-align:center;">';
57 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
58 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
59 $state_names = note_get_state_names();
61 // the first time list hack
63 foreach ($_POST as $k => $v) {
64 if (preg_match('/^user(\d+)$/',$k,$m)) {
70 $strpublishstate = get_string('publishstate', 'notes');
73 foreach ($users as $k => $v) {
74 if(!$user = get_record('user', 'id', $v)) {
77 echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />';
78 $userlist[] = fullname($user, true);
81 echo get_string('users'). ': ' . implode(', ', $userlist) . '.';
84 echo '<p>' . get_string('content', 'notes');
85 helpbutton('writing', get_string('helpwriting'));
86 echo '<br /><textarea name="content" rows="5" cols="50">' . strip_tags(@$content) . '</textarea></p>';
88 echo '<p>' . $strpublishstate;
89 helpbutton('status', $strpublishstate, 'notes');
90 choose_from_menu($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC
: $state, '');
93 echo '<input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
94 print_footer($course);