/** * Add new comment */ function glossary_comment_add() { global $USER; $eid = optional_param('eid', 0, PARAM_INT); // Entry ID if (!($entry = get_record('glossary_entries', 'id', $eid))) { 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); /// Both the configuration and capability must allow comments if (!$glossary->allowcomments or !has_capability('mod/glossary:comment', $context)) { error('You can\'t add comments to this glossary!'); } $mform = new mod_glossary_comment_form(); $mform->set_data(array('eid' => $eid, 'action' => 'add')); if ($mform->is_cancelled()) { redirect("comments.php?id={$cm->id}&eid={$entry->id}"); } if ($data = $mform->get_data()) { trusttext_after_edit($data->entrycomment, $context); $newcomment = new object(); $newcomment->entryid = $entry->id; $newcomment->entrycomment = $data->entrycomment; $newcomment->format = $data->format; $newcomment->timemodified = time(); $newcomment->userid = $USER->id; if (!($newcomment->id = insert_record('glossary_comments', $newcomment))) { error('Could not insert this new comment'); } else { add_to_log($course->id, 'glossary', 'add comment', "comments.php?id={$cm->id}&eid={$entry->id}", "{$newcomment->id}", $cm->id); } redirect("comments.php?id={$cm->id}&eid={$entry->id}"); } else { glossary_comment_print_header($course, $cm, $glossary, $entry, 'add'); $mform->display(); print_footer($course); die; } }
/** * Add new comment */ function glossary_comment_add() { global $USER, $DB; $entryid = optional_param('entryid', 0, PARAM_INT); // Entry ID if (!($entry = $DB->get_record('glossary_entries', array('id' => $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); /// Both the configuration and capability must allow comments if (!$glossary->allowcomments or !has_capability('mod/glossary:comment', $context)) { print_error('nopermissiontocomment'); } $commentoptions = array('trusttext' => true, 'maxfiles' => 0); $comment = new object(); $comment->id = null; $comment->action = 'edit'; $comment->entryid = $entry->id; $comment = file_prepare_standard_editor($comment, 'entrycomment', $commentoptions, $context); $mform = new mod_glossary_comment_form(array('current' => $comment, 'commentoptions' => $commentoptions)); if ($mform->is_cancelled()) { redirect("comments.php?id={$cm->id}&eid={$entry->id}"); } if ($newcomment = $mform->get_data()) { $newcomment = file_postupdate_standard_editor($newcomment, 'entrycomment', $newcommentoptions, $context); //no files - can be used before insert $newcomment->timemodified = time(); $newcomment->userid = $USER->id; $newcomment->id = $DB->insert_record('glossary_comments', $newcomment); add_to_log($course->id, 'glossary', 'add comment', "comments.php?id={$cm->id}&eid={$entry->id}", "{$newcomment->id}", $cm->id); redirect("comments.php?id={$cm->id}&eid={$entry->id}"); } else { glossary_comment_print_header($course, $cm, $glossary, $entry, 'add'); $mform->display(); print_footer($course); die; } }