Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/addnote.php
Go to the documentation of this file.
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 $contents = optional_param_array('contents', array(), PARAM_RAW); // array of user notes
00032 $states = optional_param_array('states', array(), PARAM_ALPHA); // array of notes states
00033 
00034 $PAGE->set_url('/user/addnote.php', array('id'=>$id));
00035 
00036 if (! $course = $DB->get_record('course', array('id'=>$id))) {
00037     print_error('invalidcourseid');
00038 }
00039 
00040 $context = get_context_instance(CONTEXT_COURSE, $id);
00041 require_login($course->id);
00042 
00043 // to create notes the current user needs a capability
00044 require_capability('moodle/notes:manage', $context);
00045 
00046 if (empty($CFG->enablenotes)) {
00047     print_error('notesdisabled', 'notes');
00048 }
00049 
00050 if (!empty($users) && confirm_sesskey()) {
00051     if (count($users) != count($contents) || count($users) != count($states)) {
00052         print_error('invalidformdata', '', $CFG->wwwroot.'/user/index.php?id='.$id);
00053     }
00054 
00055     $note = new stdClass();
00056     $note->courseid = $id;
00057     $note->format = FORMAT_PLAIN;
00058     foreach ($users as $k => $v) {
00059         if (!$user = $DB->get_record('user', array('id'=>$v)) || empty($contents[$k])) {
00060             continue;
00061         }
00062         $note->id = 0;
00063         $note->content = $contents[$k];
00064         $note->publishstate = $states[$k];
00065         $note->userid = $v;
00066         if (note_save($note)) {
00067             add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');
00068         }
00069     }
00070     redirect("$CFG->wwwroot/user/index.php?id=$id");
00071 }
00072 
00074 
00075 $straddnote = get_string('addnewnote', 'notes');
00076 
00077 $PAGE->navbar->add($straddnote);
00078 $PAGE->set_title("$course->shortname: ".get_string('extendenrol'));
00079 $PAGE->set_heading($course->fullname);
00080 
00081 echo $OUTPUT->header();
00082 
00083 // this will contain all available the based On select options, but we'll disable some on them on a per user basis
00084 
00085 echo $OUTPUT->heading($straddnote);
00086 echo '<form method="post" action="addnote.php">';
00087 echo '<fieldset class="invisiblefieldset">';
00088 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
00089 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
00090 echo '</fieldset>';
00091 $table = new html_table();
00092 $table->head  = array (get_string('fullnameuser'),
00093     get_string('content', 'notes'),
00094     get_string('publishstate', 'notes') . $OUTPUT->help_icon('publishstate', 'notes'),
00095     );
00096 $table->align = array ('left', 'center', 'center');
00097 $state_names = note_get_state_names();
00098 
00099 // the first time list hack
00100 if (empty($users) and $post = data_submitted()) {
00101     foreach ($post as $k => $v) {
00102         if (preg_match('/^user(\d+)$/',$k,$m)) {
00103             $users[] = $m[1];
00104         }
00105     }
00106 }
00107 
00108 foreach ($users as $k => $v) {
00109     if(!$user = $DB->get_record('user', array('id'=>$v))) {
00110         continue;
00111     }
00112     $checkbox = html_writer::select($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], false);
00113     $table->data[] = array(
00114         '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true),
00115         '<textarea name="contents['. $k . ']" rows="2" cols="40">' . strip_tags(@$contents[$k]) . '</textarea>',
00116         $checkbox
00117     );
00118 }
00119 echo html_writer::table($table);
00120 echo '<div style="width:100%;text-align:center;"><input type="submit" value="' . get_string('savechanges'). '" /></div></form>';
00121 echo $OUTPUT->footer();
00122 
 All Data Structures Namespaces Files Functions Variables Enumerations