forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.php
88 lines (69 loc) · 3.26 KB
/
edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php // $Id$
require_once('../config.php');
require_once('lib.php');
/// retrieve parameters
$noteid = required_param('note', PARAM_INT);
/// locate note information
if (!$note = note_load($noteid)) {
print_error('invalidid', 'notes');
}
/// locate course information
if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
print_error('invalidcourseid');
}
/// locate user information
if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
print_error('invaliduserid');
}
/// require login to access notes
require_login($course->id);
/// locate context information
$context = get_context_instance(CONTEXT_COURSE, $course->id);
/// check capability
require_capability('moodle/notes:manage', $context);
/// build-up form
require_once('edit_form.php');
/// get option values for the user select
/// create form
$noteform = new note_edit_form();
/// if form was cancelled then return to the notes list of the note
if ($noteform->is_cancelled()) {
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid);
}
/// if data was submitted and validated, then save it to database
if ($formdata = $noteform->get_data()){
$note->courseid = $formdata->course;
$note->userid = $formdata->user;
$note->content = $formdata->content;
$note->format = FORMAT_PLAIN;
$note->publishstate = $formdata->publishstate;
if (note_save($note)) {
add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id, 'update note');
}
// redirect to notes list that contains this note
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid);
}
if ($noteform->is_submitted()) {
// if data was submitted with errors, then use it as default for new form
$note = $noteform->get_submitted_data();
} else {
// if data was not submitted yet, then used values retrieved from the database
$note->user = $note->userid;
$note->course = $note->courseid;
$note->note = $note->id;
}
$noteform->set_data($note);
$strnotes = get_string('editnote', 'notes');
/// output HTML
$nav = array();
if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
$nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
}
$nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&course=' . $course->id, 'type' => 'misc');
$nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $user->id, 'type' => 'misc');
$nav[] = array('name' => $strnotes, 'link' => '', 'type' => 'activity');
print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
print_heading(fullname($user));
$noteform->display();
print_footer();
?>