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 $contents = optional_param('contents', array(), PARAM_RAW
); // array of user notes
8 $states = optional_param('states', array(), PARAM_ALPHA
); // array of notes states
9 if (! $course = get_record('course', 'id', $id)) {
10 error("Course ID is incorrect");
13 $context = get_context_instance(CONTEXT_COURSE
, $id);
14 require_login($course->id
);
16 // to create notes the current user needs a capability
17 require_capability('moodle/notes:manage', $context);
19 if (!empty($users) && confirm_sesskey()) {
20 if (count($users) != count($contents) ||
count($users) != count($states)) {
21 error('Parameters malformation', $CFG->wwwroot
.'/user/index.php?id='.$id);
25 $note->courseid
= $id;
26 $note->format
= FORMAT_PLAIN
;
27 foreach ($users as $k => $v) {
28 if(!$user = get_record('user', 'id', $v) ||
empty($contents[$k])) {
32 $note->content
= $contents[$k];
33 $note->publishstate
= $states[$k];
35 if (note_save($note)) {
36 add_to_log($note->courseid
, 'notes', 'add', 'index.php?course='.$note->courseid
.'&user='.$note->userid
. '#note-' . $note->id
, 'add note');
39 redirect("$CFG->wwwroot/user/index.php?id=$id");
44 $straddnote = get_string('addnewnote', 'notes');
47 $navlinks[] = array('name' => $straddnote, 'link' => null, 'type' => 'misc');
48 $navigation = build_navigation($navlinks);
50 print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname
, $navigation, "", "", 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="addnote.php">';
56 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
57 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
58 $table->head
= array (get_string('fullname'),
59 get_string('content', 'notes') . helpbutton('writing', get_string('helpwriting'), 'moodle', true, false, '', true),
60 get_string('publishstate', 'notes') . helpbutton('status', get_string('publishstate', 'notes'), 'notes', true, false, '', true),
62 $table->align
= array ('left', 'center', 'center');
63 $state_names = note_get_state_names();
65 // the first time list hack
67 foreach ($_POST as $k => $v) {
68 if (preg_match('/^user(\d+)$/',$k,$m)) {
74 foreach ($users as $k => $v) {
75 if(!$user = get_record('user', 'id', $v)) {
78 $checkbox = choose_from_menu($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC
: $states[$k], '', '', '0', true);
79 $table->data
[] = array(
80 '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true),
81 '<textarea name="contents['. $k . ']" rows="2" cols="40">' . strip_tags(@$contents[$k]) . '</textarea>',
86 echo '<div style="width:100%;text-align:center;"><input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
87 print_footer($course);