/** * 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; } }
} } redirect("view.php?id={$cm->id}&mode=entry&hook={$todb->id}"); } else { if ($e) { $fromdb = get_record("glossary_entries", "id", $e); $toform = new object(); if ($categoriesarr = get_records_menu("glossary_entries_categories", "entryid", $e, '', 'id, categoryid')) { $toform->categories = array_values($categoriesarr); } else { $toform->categories = array(0); } $toform->concept = $fromdb->concept; $toform->definition = $fromdb->definition; $toform->format = $fromdb->format; trusttext_prepare_edit($toform->definition, $toform->format, can_use_html_editor(), $context); $toform->approved = $glossary->defaultapproval or has_capability('mod/glossary:approve', $context); $toform->usedynalink = $fromdb->usedynalink; $toform->casesensitive = $fromdb->casesensitive; $toform->fullmatch = $fromdb->fullmatch; $toform->aliases = ''; $ineditperiod = time() - $fromdb->timecreated < $CFG->maxeditingtime || $glossary->editalways; if (!$ineditperiod || $USER->id != $fromdb->userid and !has_capability('mod/glossary:manageentries', $context)) { if ($USER->id != $fromdb->userid) { print_error('errcannoteditothers', 'glossary'); } elseif (!$ineditperiod) { print_error('erredittimeexpired', 'glossary'); } die; } if ($aliases = get_records_menu("glossary_alias", "entryid", $e, '', 'id, alias')) {
} else { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); } if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) { if (time() - $post->created > $CFG->maxeditingtime and !has_capability('mod/forum:editanypost', $modcontext)) { error(get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime))); } } if ($post->userid != $USER->id and !has_capability('mod/forum:editanypost', $modcontext)) { error("You can't edit other people's posts!"); } // Load up the $post variable. $post->edit = $edit; $post->course = $course->id; $post->forum = $forum->id; trusttext_prepare_edit($post->message, $post->format, can_use_html_editor(), $modcontext); unset($SESSION->fromdiscussion); } else { if (!empty($delete)) { // User is deleting a post if (!($post = forum_get_post_full($delete))) { error("Post ID was incorrect"); } if (!($discussion = get_record("forum_discussions", "id", $post->discussion))) { error("This post is not part of a discussion!"); } if (!($forum = get_record("forum", "id", $discussion->forum))) { error("The forum number was incorrect ({$discussion->forum})"); } if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course))) { error('Could not get the course module for the forum instance.');