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 '<fieldset class="invisiblefieldset">';
57 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
58 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
60 $table->head
= array (get_string('fullname'),
61 get_string('content', 'notes') . helpbutton('writing', get_string('helpwriting'), 'moodle', true, false, '', true),
62 get_string('publishstate', 'notes') . helpbutton('status', get_string('publishstate', 'notes'), 'notes', true, false, '', true),
64 $table->align
= array ('left', 'center', 'center');
65 $state_names = note_get_state_names();
67 // the first time list hack
69 foreach ($_POST as $k => $v) {
70 if (preg_match('/^user(\d+)$/',$k,$m)) {
76 foreach ($users as $k => $v) {
77 if(!$user = get_record('user', 'id', $v)) {
80 $checkbox = choose_from_menu($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC
: $states[$k], '', '', '0', true);
81 $table->data
[] = array(
82 '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true),
83 '<textarea name="contents['. $k . ']" rows="2" cols="40">' . strip_tags(@$contents[$k]) . '</textarea>',
88 echo '<div style="width:100%;text-align:center;"><input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
89 print_footer($course);