MDL-16164 improved use of forms in notes code and some other minor cleanup

This commit is contained in:
skodak 2008-08-21 21:40:29 +00:00
parent 5b4b959b5a
commit 241bcec5fa
6 changed files with 50 additions and 136 deletions

View file

@ -89,18 +89,18 @@ function note_save(&$note) {
$note->module = 'notes';
$note->lastmodified = time();
$note->usermodified = $USER->id;
if(empty($note->format)) {
if (empty($note->format)) {
$note->format = FORMAT_PLAIN;
}
if(empty($note->publishstate)) {
if (empty($note->publishstate)) {
$note->publishstate = NOTES_STATE_PUBLIC;
}
// save data
if(empty($note->id)) {
if (empty($note->id)) {
// insert new note
$note->created = $note->lastmodified;
if ($id = $DB->insert_record('post', $note)) {
$note->id = $id;
$note = $DB->get_record('post', array('id'=>$id));
$result = true;
} else {
$result = false;
@ -175,7 +175,7 @@ function note_print($note, $detail = NOTES_SHOW_FULL) {
return;
}
$context = get_context_instance(CONTEXT_COURSE, $note->courseid);
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$authoring = new object();
$authoring->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$author->id.'&amp;course='.$note->courseid.'">'.fullname($author).'</a>';
@ -186,7 +186,7 @@ function note_print($note, $detail = NOTES_SHOW_FULL) {
'" id="note-'. $note->id .'">';
// print note head (e.g. author, user refering to, etc)
if($detail & NOTES_SHOW_HEAD) {
if ($detail & NOTES_SHOW_HEAD) {
echo '<div class="header">';
echo '<div class="user">';
print_user_picture($user, $note->courseid, $user->picture);
@ -198,19 +198,19 @@ function note_print($note, $detail = NOTES_SHOW_FULL) {
}
// print note content
if($detail & NOTES_SHOW_BODY) {
if ($detail & NOTES_SHOW_BODY) {
echo '<div class="content">';
echo format_text($note->content, $note->format);
echo '</div>';
}
// print note options (e.g. delete, edit)
if($detail & NOTES_SHOW_FOOT) {
if (has_capability('moodle/notes:manage', $sitecontext) && $note->publishstate == NOTES_STATE_SITE ||
if ($detail & NOTES_SHOW_FOOT) {
if (has_capability('moodle/notes:manage', $systemcontext) && $note->publishstate == NOTES_STATE_SITE ||
has_capability('moodle/notes:manage', $context) && ($note->publishstate == NOTES_STATE_PUBLIC || $note->usermodified == $USER->id)) {
echo '<div class="footer"><p>';
echo '<a href="'.$CFG->wwwroot.'/notes/edit.php?note='.$note->id. '">'. get_string('edit') .'</a> | ';
echo '<a href="'.$CFG->wwwroot.'/notes/delete.php?note='.$note->id. '">'. get_string('delete') .'</a>';
echo '<a href="'.$CFG->wwwroot.'/notes/edit.php?id='.$note->id. '">'. get_string('edit') .'</a> | ';
echo '<a href="'.$CFG->wwwroot.'/notes/delete.php?id='.$note->id. '">'. get_string('delete') .'</a>';
echo '</p></div>';
}
}
@ -253,7 +253,7 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei
}
if ($addcourseid) {
if ($userid) {
echo '<p><a href="'. $CFG->wwwroot .'/notes/add.php?course=' . $addcourseid . '&amp;user=' . $userid . '&amp;state=' . $state . '">' . get_string('addnewnote', 'notes') . '</a></p>';
echo '<p><a href="'. $CFG->wwwroot .'/notes/edit.php?courseid=' . $addcourseid . '&amp;userid=' . $userid . '&amp;publishstate=' . $state . '">' . get_string('addnewnote', 'notes') . '</a></p>';
} else {
echo '<p><a href="'. $CFG->wwwroot .'/user/index.php?id=' . $addcourseid. '">' . get_string('addnewnoteselect', 'notes') . '</a></p>';
}