Updated the 19 build version to 20081122
[moodle.git] / notes / edit.php
blobbf6f36f3714be3722ca0b306864f813dee4c0c52
1 <?php // $Id$
3 require_once('../config.php');
4 require_once('lib.php');
6 /// retrieve parameters
7 $noteid = required_param('note', PARAM_INT);
9 /// locate note information
10 if (!$note = note_load($noteid)) {
11 error('Incorrect note id specified');
14 /// locate course information
15 if (!$course = get_record('course', 'id', $note->courseid)) {
16 error('Incorrect course id found');
19 /// locate user information
20 if (!$user = get_record('user', 'id', $note->userid)) {
21 error('Incorrect user id found');
24 /// require login to access notes
25 require_login($course->id);
27 /// locate context information
28 $context = get_context_instance(CONTEXT_COURSE, $course->id);
30 /// check capability
31 require_capability('moodle/notes:manage', $context);
33 /// build-up form
34 require_once('edit_form.php');
36 /// get option values for the user select
38 /// create form
39 $noteform = new note_edit_form();
41 /// if form was cancelled then return to the notes list of the note
42 if ($noteform->is_cancelled()) {
43 redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
46 /// if data was submitted and validated, then save it to database
47 if ($formdata = $noteform->get_data()){
48 $note->courseid = $formdata->course;
49 $note->userid = $formdata->user;
50 $note->content = $formdata->content;
51 $note->format = FORMAT_PLAIN;
52 $note->publishstate = $formdata->publishstate;
53 if (note_save($note)) {
54 add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id, 'update note');
56 // redirect to notes list that contains this note
57 redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
61 if ($noteform->is_submitted()) {
62 // if data was submitted with errors, then use it as default for new form
63 $note = $noteform->get_submitted_data(false);
64 } else {
65 // if data was not submitted yet, then used values retrieved from the database
66 $note->user = $note->userid;
67 $note->course = $note->courseid;
68 $note->note = $note->id;
70 $noteform->set_data($note);
71 $strnotes = get_string('editnote', 'notes');
73 /// output HTML
74 $nav = array();
75 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
76 $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
78 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
79 $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $user->id, 'type' => 'misc');
80 $nav[] = array('name' => $strnotes, 'link' => '', 'type' => 'activity');
82 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
84 print_heading(fullname($user));
86 $noteform->display();
87 print_footer();