forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
notes MDL-19818 Upgrade deprecated calls and added set_url calls
- Loading branch information
samhemelryk
committed
Sep 29, 2009
1 parent
93c91ee
commit 2f4a2f2
Showing
3 changed files
with
203 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,102 @@ | ||
<?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(); |
Oops, something went wrong.