Merge branch 'MDL-29572_moodle26' of https://github.com/jrchamp/moodle into MOODLE_26...
[moodle.git] / user / groupaddnote.php
blob3d63e65f36f6fd6d0ca5d47e7daf730fe0c87185
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 = context_course::instance($id);
48 require_login($course);
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 note_save($note);
72 redirect("$CFG->wwwroot/user/index.php?id=$id");
75 $straddnote = get_string('groupaddnewnote', 'notes');
77 $PAGE->navbar->add($straddnote);
78 $PAGE->set_title("$course->shortname: ".get_string('extendenrol'));
79 $PAGE->set_heading($course->fullname);
81 /// Print headers
82 echo $OUTPUT->header();
84 // this will contain all available the based On select options, but we'll disable some on them on a per user basis
86 echo $OUTPUT->heading($straddnote);
87 echo '<form method="post" action="groupaddnote.php" >';
88 echo '<div style="width:100%;text-align:center;">';
89 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
90 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
91 $state_names = note_get_state_names();
93 // the first time list hack
94 if (empty($users) and $post = data_submitted()) {
95 foreach ($post as $k => $v) {
96 if (preg_match('/^user(\d+)$/',$k,$m)) {
97 $users[] = $m[1];
102 $userlist = array();
103 foreach ($users as $k => $v) {
104 if (!$user = $DB->get_record('user', array('id'=>$v))) {
105 continue;
107 echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />';
108 $userlist[] = fullname($user, true);
110 echo '<p>';
111 echo get_string('users'). ': ' . implode(', ', $userlist) . '.';
112 echo '</p>';
114 echo '<p>' . get_string('content', 'notes');
115 echo '<br /><textarea name="content" rows="5" cols="50" spellcheck="true">' . strip_tags(@$content) . '</textarea></p>';
117 echo '<p>';
118 echo html_writer::label(get_string('publishstate', 'notes'), 'menustate');
119 echo $OUTPUT->help_icon('publishstate', 'notes');
120 echo html_writer::select($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, false);
121 echo '</p>';
123 echo '<input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
124 echo $OUTPUT->footer();