file check_defaults.class.php was added on branch MOODLE_19_STABLE on 2008-05-15...
[moodle-linuxchix.git] / user / addnote.php
blobfbf6861231f518f6e841772cc6f810ba0237e118
1 <?php // $Id$
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);
24 $note = new object();
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])) {
29 continue;
31 $note->id = 0;
32 $note->content = $contents[$k];
33 $note->publishstate = $states[$k];
34 $note->userid = $v;
35 if (note_save($note)) {
36 add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');
39 redirect("$CFG->wwwroot/user/index.php?id=$id");
42 /// Print headers
44 $straddnote = get_string('addnewnote', 'notes');
46 $navlinks = array();
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, "&nbsp;", 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.'" />';
59 echo '</fieldset>';
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
68 if (empty($users)) {
69 foreach ($_POST as $k => $v) {
70 if (preg_match('/^user(\d+)$/',$k,$m)) {
71 $users[] = $m[1];
76 foreach ($users as $k => $v) {
77 if(!$user = get_record('user', 'id', $v)) {
78 continue;
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>',
84 $checkbox
87 print_table($table);
88 echo '<div style="width:100%;text-align:center;"><input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
89 print_footer($course);