MDL-35576 - Right padding is missing on Date field/element, when in RTL mode (minor...
[moodle.git] / user / groupaddnote.php
blobe036140923eb44d889bf05533669ed67d8eedc91
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This file is part of the User section Moodle
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package user
26 require_once("../config.php");
27 require_once($CFG->dirroot .'/notes/lib.php');
29 $id = required_param('id', PARAM_INT); // course id
30 $users = optional_param_array('userid', array(), PARAM_INT); // array of user id
31 $content = optional_param('content', '', PARAM_RAW); // note content
32 $state = optional_param('state', '', PARAM_ALPHA); // note publish state
34 $url = new moodle_url('/user/groupaddnote.php', array('id'=>$id));
35 if ($content !== '') {
36 $url->param('content', $content);
38 if ($state !== '') {
39 $url->param('state', $state);
41 $PAGE->set_url($url);
43 if (! $course = $DB->get_record('course', array('id'=>$id))) {
44 print_error('invalidcourseid');
47 $context = get_context_instance(CONTEXT_COURSE, $id);
48 require_login($course->id);
50 // to create notes the current user needs a capability
51 require_capability('moodle/notes:manage', $context);
53 if (empty($CFG->enablenotes)) {
54 print_error('notesdisabled', 'notes');
57 if (!empty($users) && !empty($content) && confirm_sesskey()) {
58 $note = new stdClass();
59 $note->courseid = $id;
60 $note->format = FORMAT_PLAIN;
61 $note->content = $content;
62 $note->publishstate = $state;
63 foreach ($users as $k => $v) {
64 if(!$user = $DB->get_record('user', array('id'=>$v))) {
65 continue;
67 $note->id = 0;
68 $note->userid = $v;
69 if (note_save($note)) {
70 add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');
74 redirect("$CFG->wwwroot/user/index.php?id=$id");
77 $straddnote = get_string('groupaddnewnote', 'notes');
79 $PAGE->navbar->add($straddnote);
80 $PAGE->set_title("$course->shortname: ".get_string('extendenrol'));
81 $PAGE->set_heading($course->fullname);
83 /// Print headers
84 echo $OUTPUT->header();
86 // this will contain all available the based On select options, but we'll disable some on them on a per user basis
88 echo $OUTPUT->heading($straddnote);
89 echo '<form method="post" action="groupaddnote.php" >';
90 echo '<div style="width:100%;text-align:center;">';
91 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
92 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
93 $state_names = note_get_state_names();
95 // the first time list hack
96 if (empty($users) and $post = data_submitted()) {
97 foreach ($post as $k => $v) {
98 if (preg_match('/^user(\d+)$/',$k,$m)) {
99 $users[] = $m[1];
104 $userlist = array();
105 foreach ($users as $k => $v) {
106 if (!$user = $DB->get_record('user', array('id'=>$v))) {
107 continue;
109 echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />';
110 $userlist[] = fullname($user, true);
112 echo '<p>';
113 echo get_string('users'). ': ' . implode(', ', $userlist) . '.';
114 echo '</p>';
116 echo '<p>' . get_string('content', 'notes');
117 echo '<br /><textarea name="content" rows="5" cols="50">' . strip_tags(@$content) . '</textarea></p>';
119 echo '<p>';
120 echo html_writer::label(get_string('publishstate', 'notes'), 'menustate');
121 echo $OUTPUT->help_icon('publishstate', 'notes');
122 echo html_writer::select($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, false);
123 echo '</p>';
125 echo '<input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
126 echo $OUTPUT->footer();