$strglossaries = get_string("modulenameplural", "glossary"); $strglossary = get_string("modulename", "glossary"); $strallcategories = get_string("allcategories", "glossary"); $straddentry = get_string("addentry", "glossary"); $strnoentries = get_string("noentries", "glossary"); $strsearchconcept = get_string("searchconcept", "glossary"); $strsearchindefinition = get_string("searchindefinition", "glossary"); $strsearch = get_string("search"); $strcomments = get_string("comments", "glossary"); $straddcomment = get_string("addcomment", "glossary"); $navigation = build_navigation($strcomments, $cm); print_header_simple(strip_tags("{$strcomments}: {$entry->concept}"), "", $navigation, "", "", true, update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm)); /// original glossary entry echo "<div class=\"boxaligncenter\">"; glossary_print_entry($course, $cm, $glossary, $entry, "", "", false); echo "</div>"; /// comments echo $OUTPUT->heading(format_string(get_string('commentson', 'glossary') . " <b>\"{$entry->concept}\"</b>")); if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) { echo $OUTPUT->heading("<a href=\"comment.php?action=add&entryid={$entry->id}\">{$straddcomment} <img title=\"{$straddcomment}\" src=\"comment.gif\" class=\"iconsmall\" alt=\"{$straddcomment}\" /></a>"); } if ($comments = $DB->get_records("glossary_comments", array("entryid" => $entry->id), "timemodified ASC")) { foreach ($comments as $comment) { glossary_print_comment($course, $cm, $glossary, $entry, $comment); echo '<br />'; } } else { echo $OUTPUT->heading(get_string("nocomments", "glossary")); } /// Finish the page echo $OUTPUT->footer();
/** * Deleting existing comments */ function glossary_comment_delete() { global $USER; $cid = optional_param('cid', 0, PARAM_INT); // Comment ID $confirm = optional_param('confirm', 0, PARAM_BOOL); // delete confirmation 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 ($comment->userid != $USER->id and !has_capability('mod/glossary:managecomments', $context)) { error('You can\'t delete other people\'s comments!'); } if (!$glossary->allowcomments and !has_capability('mod/glossary:managecomments', $context)) { error('You can\'t delete comments in this glossary!'); } if (data_submitted() and $confirm) { delete_records('glossary_comments', 'id', $cid); add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id={$cm->id}&eid={$entry->id}", "{$comment->id}", $cm->id); redirect("comments.php?id={$cm->id}&eid={$entry->id}"); } else { $linkyes = 'comment.php'; $optionsyes = array('action' => 'delete', 'cid' => $cid, 'confirm' => 1); $linkno = 'comments.php'; $optionsno = array('id' => $cm->id, 'eid' => $entry->id); $strdeletewarning = get_string('areyousuredeletecomment', 'glossary'); glossary_comment_print_header($course, $cm, $glossary, $entry, 'delete'); glossary_print_comment($course, $cm, $glossary, $entry, $comment); notice_yesno($strdeletewarning, $linkyes, $linkno, $optionsyes, $optionsno, 'post', 'get'); print_footer($course); die; } }
/** * Deleting existing comments */ function glossary_comment_delete() { global $USER, $DB; $id = optional_param('id', 0, PARAM_INT); // Comment ID $confirm = optional_param('confirm', 0, PARAM_BOOL); // delete confirmation if (!($comment = $DB->get_record('glossary_comments', array('id' => $id)))) { print_error('invalidcomment'); } if (!($entry = $DB->get_record('glossary_entries', array('id' => $comment->entryid)))) { print_error('invalidentry'); } if (!($glossary = $DB->get_record('glossary', array('id' => $entry->glossaryid)))) { print_error('invalidid', 'glossary'); } if (!($cm = get_coursemodule_from_instance('glossary', $glossary->id))) { print_error('invalidcoursemodule'); } if (!($course = $DB->get_record('course', array('id' => $cm->course)))) { print_error('coursemisconf'); } require_login($course, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); if ($comment->userid != $USER->id and !has_capability('mod/glossary:managecomments', $context)) { print_error('nopermissiontodelcomment', 'glossary'); } if (!$glossary->allowcomments and !has_capability('mod/glossary:managecomments', $context)) { print_error('nopermissiontodelinglossary', 'glossary'); } if (data_submitted() and $confirm) { $DB->delete_records('glossary_comments', array('id' => $id)); add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id={$cm->id}&eid={$entry->id}", "{$comment->id}", $cm->id); redirect("comments.php?id={$cm->id}&eid={$entry->id}"); } else { $linkyes = 'comment.php'; $optionsyes = array('action' => 'delete', 'id' => $id, 'confirm' => 1); $linkno = 'comments.php'; $optionsno = array('id' => $cm->id, 'entryid' => $entry->id); $strdeletewarning = get_string('areyousuredeletecomment', 'glossary'); glossary_comment_print_header($course, $cm, $glossary, $entry, 'delete'); glossary_print_comment($course, $cm, $glossary, $entry, $comment); notice_yesno($strdeletewarning, $linkyes, $linkno, $optionsyes, $optionsno, 'post', 'get'); print_footer($course); die; } }