file AutoFormat.RemoveSpansWithoutAttributes.txt was added on branch MOODLE_19_STABLE...
[moodle.git] / notes / edit.php
blob5eaa5f51daae440c2ebbaf817f4a50c811420753
1 <?php // $Id$
3 require_once('../config.php');
4 require_once('lib.php');
5 require_once('edit_form.php');
7 /// retrieve parameters
8 $noteid = optional_param('id', 0, PARAM_INT);
10 if ($noteid) {
11 //existing note
12 if (!$note = note_load($noteid)) {
13 print_error('invalidid', 'notes');
16 } else {
17 // adding new note
18 $courseid = required_param('courseid', PARAM_INT);
19 $userid = required_param('userid', PARAM_INT);
20 $state = optional_param('publishstate', NOTES_STATE_PUBLIC, PARAM_ALPHA);
22 $note = new object();
23 $note->courseid = $courseid;
24 $note->userid = $userid;
25 $note->publishstate = $state;
28 /// locate course information
29 if (!$course = get_record('course', 'id', $note->courseid)) {
30 error('Incorrect course id found');
33 /// locate user information
34 if (!$user = get_record('user', 'id', $note->userid)) {
35 error('Incorrect user id found');
38 /// require login to access notes
39 require_login($course);
41 /// locate context information
42 $context = get_context_instance(CONTEXT_COURSE, $course->id);
43 require_capability('moodle/notes:manage', $context);
45 if (empty($CFG->enablenotes)) {
46 print_error('notesdisabled', 'notes');
49 /// create form
50 $noteform = new note_edit_form();
52 /// set defaults
53 $noteform->set_data($note);
55 /// if form was cancelled then return to the notes list of the note
56 if ($noteform->is_cancelled()) {
57 redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
60 /// if data was submitted and validated, then save it to database
61 if ($note = $noteform->get_data()){
62 if (note_save($note)) {
63 add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id, 'update note');
65 // redirect to notes list that contains this note
66 redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
69 if ($noteid) {
70 $strnotes = get_string('editnote', 'notes');
71 } else {
72 $strnotes = get_string('addnewnote', 'notes');
75 /// output HTML
76 $nav = array();
77 if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
78 $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
80 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
81 $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $user->id, 'type' => 'misc');
82 $nav[] = array('name' => $strnotes, 'link' => '', 'type' => 'activity');
84 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
86 print_heading(fullname($user));
88 $noteform->display();
89 print_footer();