-<?php // $Id$
+<?php
- require_once('../config.php');
- require_once('lib.php');
- require_once('edit_form.php');
+require_once('../config.php');
+require_once('lib.php');
+require_once('edit_form.php');
/// retrieve parameters
- $noteid = optional_param('id', 0, PARAM_INT);
-
- if ($noteid) {
- //existing note
- if (!$note = note_load($noteid)) {
- print_error('invalidid', 'notes');
- }
-
- } else {
- // adding new note
- $courseid = required_param('courseid', PARAM_INT);
- $userid = required_param('userid', PARAM_INT);
- $state = optional_param('publishstate', NOTES_STATE_PUBLIC, PARAM_ALPHA);
-
- $note = new object();
- $note->courseid = $courseid;
- $note->userid = $userid;
- $note->publishstate = $state;
- }
+$noteid = optional_param('id', 0, PARAM_INT);
-/// locate course information
- if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
- print_error('invalidcourseid');
+$url = new moodle_url($CFG->wwwroot.'/notes/edit.php');
+
+if ($noteid) {
+ //existing note
+ $url->param('id', $noteid);
+ if (!$note = note_load($noteid)) {
+ print_error('invalidid', 'notes');
}
-/// locate user information
- if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
- print_error('invaliduserid');
+} else {
+ // adding new note
+ $courseid = required_param('courseid', PARAM_INT);
+ $userid = required_param('userid', PARAM_INT);
+ $state = optional_param('publishstate', NOTES_STATE_PUBLIC, PARAM_ALPHA);
+
+ $note = new object();
+ $note->courseid = $courseid;
+ $note->userid = $userid;
+ $note->publishstate = $state;
+
+ $url->param('courseid', $courseid);
+ $url->param('userid', $userid);
+ if ($publishstate !== NOTES_STATE_PUBLIC) {
+ $url->param('publishstate', $publishstate);
}
+}
+
+$PAGE->set_url($url);
+
+/// 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);
+require_login($course);
/// locate context information
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- require_capability('moodle/notes:manage', $context);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+require_capability('moodle/notes:manage', $context);
- if (empty($CFG->enablenotes)) {
- print_error('notesdisabled', 'notes');
- }
+if (empty($CFG->enablenotes)) {
+ print_error('notesdisabled', 'notes');
+}
/// create form
- $noteform = new note_edit_form();
+$noteform = new note_edit_form();
/// set defaults
- $noteform->set_data($note);
+$noteform->set_data($note);
/// 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 ($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 ($note = $noteform->get_data()){
- 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 ($note = $noteform->get_data()){
+ 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 ($noteid) {
- $strnotes = get_string('editnote', 'notes');
- } else {
- $strnotes = get_string('addnewnote', 'notes');
- }
+if ($noteid) {
+ $strnotes = get_string('editnote', 'notes');
+} else {
+ $strnotes = get_string('addnewnote', 'notes');
+}
/// output HTML
- $link = null;
- if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
- $link = new moodle_url($CFG->wwwroot.'/user/index.php',array('id'=>$course->id));
- }
- $PAGE->navbar->add(get_string('participants'), $link);
- $PAGE->navbar->add(fullname($user), new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
- $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url($CFG->wwwroot.'/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
- $PAGE->navbar->add($strnotes);
- $PAGE->set_title($course->shortname . ': ' . $strnotes);
- $PAGE->set_heading($course->fullname);
-
- echo $OUTPUT->header();
- echo $OUTPUT->heading(fullname($user));
-
- $noteform->display();
- echo $OUTPUT->footer();
-?>
+$link = null;
+if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
+ $link = new moodle_url($CFG->wwwroot.'/user/index.php',array('id'=>$course->id));
+}
+$PAGE->navbar->add(get_string('participants'), $link);
+$PAGE->navbar->add(fullname($user), new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
+$PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url($CFG->wwwroot.'/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
+$PAGE->navbar->add($strnotes);
+$PAGE->set_title($course->shortname . ': ' . $strnotes);
+$PAGE->set_heading($course->fullname);
+
+echo $OUTPUT->header();
+echo $OUTPUT->heading(fullname($user));
+
+$noteform->display();
+echo $OUTPUT->footer();
\ No newline at end of file
-<?php // $Id$
+<?php
- /**
- * file index.php
- * index page to view notes.
- * if a course id is specified then the entries from that course are shown
- * if a user id is specified only notes related to that user are shown
- */
- require_once('../config.php');
- require_once('lib.php');
+/**
+ * file index.php
+ * index page to view notes.
+ * if a course id is specified then the entries from that course are shown
+ * if a user id is specified only notes related to that user are shown
+ */
+require_once('../config.php');
+require_once('lib.php');
/// retrieve parameters
- $courseid = optional_param('course', SITEID, PARAM_INT);
- $userid = optional_param('user', 0, PARAM_INT);
- $filtertype = optional_param('filtertype', '', PARAM_ALPHA);
- $filterselect = optional_param('filterselect', 0, PARAM_INT);
+$courseid = optional_param('course', SITEID, PARAM_INT);
+$userid = optional_param('user', 0, PARAM_INT);
+$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
+$filterselect = optional_param('filterselect', 0, PARAM_INT);
+
+$url = new moodle_url($CFG->wwwroot.'/notes/index.php');
+if ($courseid !== SITEID) {
+ $url->param('course', $courseid);
+}
+if ($userid !== 0) {
+ $url->param('user', $userid);
+}
+if ($filtertype !== '') {
+ $url->param('filtertype', $filtertype);
+}
+if ($filterselect !== '') {
+ $url->param('filterselect', $filterselect);
+}
+$PAGE->set_url($url);
/// tabs compatibility
- switch($filtertype) {
- case 'course':
- $courseid = $filterselect;
- break;
- case 'site':
- $courseid = SITEID;
- break;
- }
+switch($filtertype) {
+ case 'course':
+ $courseid = $filterselect;
+ break;
+ case 'site':
+ $courseid = SITEID;
+ break;
+}
/// locate course information
- if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
- print_error('invalidcourseid');
- }
+if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
+ print_error('invalidcourseid');
+}
/// locate user information
- if ($userid) {
- if (!$user = $DB->get_record('user', array('id'=>$userid))) {
- print_error('invaliduserid');
- }
- $filtertype = 'user';
- $filterselect = $user->id;
-
- if ($user->deleted) {
- echo $OUTPUT->header();
- echo $OUTPUT->heading(get_string('userdeleted'));
- echo $OUTPUT->footer();
- die;
- }
-
- } else {
- $filtertype = 'course';
- $filterselect = $course->id;
+if ($userid) {
+ if (!$user = $DB->get_record('user', array('id'=>$userid))) {
+ print_error('invaliduserid');
+ }
+ $filtertype = 'user';
+ $filterselect = $user->id;
+
+ if ($user->deleted) {
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('userdeleted'));
+ echo $OUTPUT->footer();
+ die;
}
+} else {
+ $filtertype = 'course';
+ $filterselect = $course->id;
+}
+
/// require login to access notes
- require_login($course);
- add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&user='.$userid, 'view notes');
+require_login($course);
+add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&user='.$userid, 'view notes');
- if (empty($CFG->enablenotes)) {
- print_error('notesdisabled', 'notes');
- }
+if (empty($CFG->enablenotes)) {
+ print_error('notesdisabled', 'notes');
+}
/// output HTML
- if ($course->id == SITEID) {
- $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
- } else {
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
- }
- $systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
-
- $strnotes = get_string('notes', 'notes');
- $link = null;
- if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
- $link = new moodle_url($CFG->wwwroot.'/user/index.php',array('id'=>$course->id));
- }
- $PAGE->navbar->add(get_string('participants'), $link);
- if ($userid) {
- $PAGE->navbar->add(fullname($user), new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
- }
- $PAGE->navbar->add($strnotes);
- $PAGE->set_title($course->shortname . ': ' . $strnotes);
- $PAGE->set_heading($course->fullname);
-
- echo $OUTPUT->header();
- echo $OUTPUT->heading(fullname($user));
-
- $showroles = 1;
- $currenttab = 'notes';
- require($CFG->dirroot .'/user/tabs.php');
-
- $strsitenotes = get_string('sitenotes', 'notes');
- $strcoursenotes = get_string('coursenotes', 'notes');
- $strpersonalnotes = get_string('personalnotes', 'notes');
- $straddnewnote = get_string('addnewnote', 'notes');
-
- echo $OUTPUT->box_start();
-
- if ($courseid != SITEID) {
- //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
- $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
- $view = has_capability('moodle/notes:view', $context);
- note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
- note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
- note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
-
- } else { // Normal course
- //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
- $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
- note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
- echo '<a name="coursenotes"></a>';
-
- if (!empty($userid)) {
- $courses = get_my_courses($userid);
- foreach($courses as $c) {
- $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
- if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
- $addid = $c->id;
- } else {
- $addid = 0;
- }
- note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
+if ($course->id == SITEID) {
+ $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
+} else {
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
+}
+$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
+
+$strnotes = get_string('notes', 'notes');
+$link = null;
+if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
+ $link = new moodle_url($CFG->wwwroot.'/user/index.php',array('id'=>$course->id));
+}
+$PAGE->navbar->add(get_string('participants'), $link);
+if ($userid) {
+ $PAGE->navbar->add(fullname($user), new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
+}
+$PAGE->navbar->add($strnotes);
+$PAGE->set_title($course->shortname . ': ' . $strnotes);
+$PAGE->set_heading($course->fullname);
+
+echo $OUTPUT->header();
+echo $OUTPUT->heading(fullname($user));
+
+$showroles = 1;
+$currenttab = 'notes';
+require($CFG->dirroot .'/user/tabs.php');
+
+$strsitenotes = get_string('sitenotes', 'notes');
+$strcoursenotes = get_string('coursenotes', 'notes');
+$strpersonalnotes = get_string('personalnotes', 'notes');
+$straddnewnote = get_string('addnewnote', 'notes');
+
+echo $OUTPUT->box_start();
+
+if ($courseid != SITEID) {
+ //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
+ $context = get_context_instance(CONTEXT_COURSE, $courseid);
+ $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
+ $view = has_capability('moodle/notes:view', $context);
+ note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
+ note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
+ note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
+
+} else { // Normal course
+ //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
+ $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
+ note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
+ echo '<a name="coursenotes"></a>';
+
+ if (!empty($userid)) {
+ $courses = get_my_courses($userid);
+ foreach($courses as $c) {
+ $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
+ if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
+ $addid = $c->id;
+ } else {
+ $addid = 0;
}
+ note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
}
}
+}
- echo $OUTPUT->box_end();
+echo $OUTPUT->box_end();
- echo $OUTPUT->footer();
-?>
+echo $OUTPUT->footer();
\ No newline at end of file