/** * Edit existing comments */ function glossary_comment_edit() { global $CFG, $USER; $cid = optional_param('cid', 0, PARAM_INT); // Comment ID if (!($comment = get_record('glossary_comments', 'id', $cid))) { error('Comment is incorrect'); } if (!($entry = get_record('glossary_entries', 'id', $comment->entryid))) { error('Entry is incorrect'); } if (!($glossary = get_record('glossary', 'id', $entry->glossaryid))) { error('Incorrect glossary'); } if (!($cm = get_coursemodule_from_instance('glossary', $glossary->id))) { error('Course Module ID was incorrect'); } if (!($course = get_record('course', 'id', $cm->course))) { error('Course is misconfigured'); } require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!$glossary->allowcomments and !has_capability('mod/glossary:managecomments', $context)) { error('You can\'t edit comments in this glossary!'); } if ($comment->userid != $USER->id and !has_capability('mod/glossary:managecomments', $context)) { error('You can\'t edit other people\'s comments!'); } $ineditperiod = time() - $comment->timemodified < $CFG->maxeditingtime || $glossary->editalways; if ((!has_capability('mod/glossary:comment', $context) or !$ineditperiod) and !has_capability('mod/glossary:managecomments', $context)) { error('You can\'t edit this. Time expired!'); } $mform = new mod_glossary_comment_form(); trusttext_prepare_edit($comment->entrycomment, $comment->format, can_use_html_editor(), $context); $mform->set_data(array('cid' => $cid, 'action' => 'edit', 'entrycomment' => $comment->entrycomment, 'format' => $comment->format)); if ($data = $mform->get_data()) { trusttext_after_edit($data->entrycomment, $context); $updatedcomment = new object(); $updatedcomment->id = $cid; $updatedcomment->entrycomment = $data->entrycomment; $updatedcomment->format = $data->format; $updatedcomment->timemodified = time(); if (!update_record('glossary_comments', $updatedcomment)) { error('Could not update this comment'); } else { add_to_log($course->id, 'glossary', 'update comment', "comments.php?id={$cm->id}&eid={$entry->id}", "{$updatedcomment->id}", $cm->id); } redirect("comments.php?id={$cm->id}&eid={$entry->id}"); } else { glossary_comment_print_header($course, $cm, $glossary, $entry, 'edit'); $mform->display(); print_footer($course); die; } }