// something is wrong here, try again } $updatedcomment = new object(); $updatedcomment->id = $formadata->commentid; $updatedcomment->content = $formadata->content; $updatedcomment->format = $formadata->format; $updatedcomment->modified = time(); if ($DB->update_record('data_comments', $updatedcomment)) { redirect('view.php?rid=' . $record->id . '&page=' . $page); } else { print_error('cannotsavecomment'); } break; case 'delete': //deletes single comment from db if ($confirm and confirm_sesskey() and $comment) { $DB->delete_records('data_comments', array('id' => $comment->id)); redirect('view.php?rid=' . $record->id . '&page=' . $page, get_string('commentdeleted', 'data')); } else { //print confirm delete form print_header(); data_print_comment($data, $comment, $page); notice_yesno(get_string('deletecomment', 'data'), 'comment.php?rid=' . $record->id . '&commentid=' . $comment->id . '&page=' . $page . '&sesskey=' . sesskey() . '&mode=delete&confirm=1', 'view.php?rid=' . $record->id . '&page=' . $page); print_footer(); } die; break; } print_header(); data_print_comments($data, $record, $page, $mform); print_footer();
function data_print_comments($data, $record, $page = 0, $mform = false) { global $CFG; $cm = get_coursemodule_from_instance('data', $data->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); $cancomment = has_capability('mod/data:comment', $context); echo '<a name="comments"></a>'; if ($comments = get_records('data_comments', 'recordid', $record->id)) { foreach ($comments as $comment) { data_print_comment($data, $comment, $page); } echo '<br />'; } if (!isloggedin() or isguest() or !$cancomment) { return; } $editor = optional_param('addcomment', 0, PARAM_BOOL); if (!$mform and !$editor) { echo '<div class="newcomment" style="text-align:center">'; echo '<a href="view.php?d=' . $data->id . '&rid=' . $record->id . '&mode=single&addcomment=1">' . get_string('addcomment', 'data') . '</a>'; echo '</div>'; } else { if (!$mform) { require_once 'comment_form.php'; $mform = new mod_data_comment_form('comment.php'); $mform->set_data(array('mode' => 'add', 'page' => $page, 'rid' => $record->id)); } echo '<div class="newcomment" style="text-align:center">'; $mform->display(); echo '</div>'; } }