|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 require_once("../config.php"); 00027 require_once($CFG->dirroot .'/notes/lib.php'); 00028 00029 $id = required_param('id', PARAM_INT); // course id 00030 $users = optional_param_array('userid', array(), PARAM_INT); // array of user id 00031 $content = optional_param('content', '', PARAM_RAW); // note content 00032 $state = optional_param('state', '', PARAM_ALPHA); // note publish state 00033 00034 $url = new moodle_url('/user/groupaddnote.php', array('id'=>$id)); 00035 if ($content !== '') { 00036 $url->param('content', $content); 00037 } 00038 if ($state !== '') { 00039 $url->param('state', $state); 00040 } 00041 $PAGE->set_url($url); 00042 00043 if (! $course = $DB->get_record('course', array('id'=>$id))) { 00044 print_error('invalidcourseid'); 00045 } 00046 00047 $context = get_context_instance(CONTEXT_COURSE, $id); 00048 require_login($course->id); 00049 00050 // to create notes the current user needs a capability 00051 require_capability('moodle/notes:manage', $context); 00052 00053 if (empty($CFG->enablenotes)) { 00054 print_error('notesdisabled', 'notes'); 00055 } 00056 00057 if (!empty($users) && !empty($content) && confirm_sesskey()) { 00058 $note = new stdClass(); 00059 $note->courseid = $id; 00060 $note->format = FORMAT_PLAIN; 00061 $note->content = $content; 00062 $note->publishstate = $state; 00063 foreach ($users as $k => $v) { 00064 if(!$user = $DB->get_record('user', array('id'=>$v))) { 00065 continue; 00066 } 00067 $note->id = 0; 00068 $note->userid = $v; 00069 if (note_save($note)) { 00070 add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'add note'); 00071 } 00072 } 00073 00074 redirect("$CFG->wwwroot/user/index.php?id=$id"); 00075 } 00076 00077 $straddnote = get_string('groupaddnewnote', 'notes'); 00078 00079 $PAGE->navbar->add($straddnote); 00080 $PAGE->set_title("$course->shortname: ".get_string('extendenrol')); 00081 $PAGE->set_heading($course->fullname); 00082 00084 echo $OUTPUT->header(); 00085 00086 // this will contain all available the based On select options, but we'll disable some on them on a per user basis 00087 00088 echo $OUTPUT->heading($straddnote); 00089 echo '<form method="post" action="groupaddnote.php" >'; 00090 echo '<div style="width:100%;text-align:center;">'; 00091 echo '<input type="hidden" name="id" value="'.$course->id.'" />'; 00092 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; 00093 $state_names = note_get_state_names(); 00094 00095 // the first time list hack 00096 if (empty($users) and $post = data_submitted()) { 00097 foreach ($post as $k => $v) { 00098 if (preg_match('/^user(\d+)$/',$k,$m)) { 00099 $users[] = $m[1]; 00100 } 00101 } 00102 } 00103 00104 $userlist = array(); 00105 foreach ($users as $k => $v) { 00106 if (!$user = $DB->get_record('user', array('id'=>$v))) { 00107 continue; 00108 } 00109 echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'; 00110 $userlist[] = fullname($user, true); 00111 } 00112 echo '<p>'; 00113 echo get_string('users'). ': ' . implode(', ', $userlist) . '.'; 00114 echo '</p>'; 00115 00116 echo '<p>' . get_string('content', 'notes'); 00117 echo '<br /><textarea name="content" rows="5" cols="50">' . strip_tags(@$content) . '</textarea></p>'; 00118 00119 echo '<p>'; 00120 echo get_string('publishstate', 'notes'); 00121 echo $OUTPUT->help_icon('publishstate', 'notes'); 00122 echo html_writer::select($state_names, 'state', empty($state) ? NOTES_STATE_PUBLIC : $state, false); 00123 echo '</p>'; 00124 00125 echo '<input type="submit" value="' . get_string('savechanges'). '" /></div></form>'; 00126 echo $OUTPUT->footer();