Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/notes/edit.php
Go to the documentation of this file.
00001 <?php
00002 
00003 require_once('../config.php');
00004 require_once('lib.php');
00005 require_once('edit_form.php');
00006 
00008 $noteid = optional_param('id', 0, PARAM_INT);
00009 
00010 $url = new moodle_url('/notes/edit.php');
00011 
00012 if ($noteid) {
00013     //existing note
00014     $url->param('id', $noteid);
00015     if (!$note = note_load($noteid)) {
00016         print_error('invalidid', 'notes');
00017     }
00018 
00019 } else {
00020     // adding new note
00021     $courseid = required_param('courseid', PARAM_INT);
00022     $userid   = required_param('userid', PARAM_INT);
00023     $state    = optional_param('publishstate', NOTES_STATE_PUBLIC, PARAM_ALPHA);
00024 
00025     $note = new stdClass();
00026     $note->courseid     = $courseid;
00027     $note->userid       = $userid;
00028     $note->publishstate = $state;
00029 
00030     $url->param('courseid', $courseid);
00031     $url->param('userid', $userid);
00032     if ($state !== NOTES_STATE_PUBLIC) {
00033         $url->param('publishstate', $state);
00034     }
00035 }
00036 
00037 $PAGE->set_url($url);
00038 
00040 if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
00041     print_error('invalidcourseid');
00042 }
00043 
00045 if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
00046     print_error('invaliduserid');
00047 }
00048 
00050 require_login($course);
00051 
00053 $context = get_context_instance(CONTEXT_COURSE, $course->id);
00054 require_capability('moodle/notes:manage', $context);
00055 
00056 if (empty($CFG->enablenotes)) {
00057     print_error('notesdisabled', 'notes');
00058 }
00059 
00061 $noteform = new note_edit_form();
00062 
00064 $noteform->set_data($note);
00065 
00067 if ($noteform->is_cancelled()) {
00068     redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
00069 }
00070 
00072 if ($note = $noteform->get_data()){
00073     if (note_save($note)) {
00074         add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id, 'update note');
00075     }
00076     // redirect to notes list that contains this note
00077     redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
00078 }
00079 
00080 if ($noteid) {
00081     $strnotes = get_string('editnote', 'notes');
00082 } else {
00083     $strnotes = get_string('addnewnote', 'notes');
00084 }
00085 
00087 $link = null;
00088 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
00089     $link = new moodle_url('/user/index.php',array('id'=>$course->id));
00090 }
00091 $PAGE->navbar->add(get_string('participants'), $link);
00092 $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
00093 $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
00094 $PAGE->navbar->add($strnotes);
00095 $PAGE->set_title($course->shortname . ': ' . $strnotes);
00096 $PAGE->set_heading($course->fullname);
00097 
00098 echo $OUTPUT->header();
00099 echo $OUTPUT->heading(fullname($user));
00100 
00101 $noteform->display();
00102 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations