if (!isset($options['subdirs'])) {
$options['subdirs'] = false;
}
+ if (!isset($options['maxfiles'])) {
+ $options['maxfiles'] = 0; // no files by default
+ }
if (empty($data->id) or empty($context)) {
$contextid = null;
$contextid = $context->id;
}
- $draftid_editor = file_get_submitted_draft_itemid($field);
- $currenttext = file_prepare_draft_area($draftid_editor, $contextid, $filearea, $data->id, $options['subdirs'], $data->{$field}, $options['forcehttps']);
- $data->{$field.'_editor'} = array('text'=>$currenttext, 'format'=>$data->{$field.'format'}, 'itemid'=>$draftid_editor);
+ if ($options['maxfiles'] != 0) {
+ $draftid_editor = file_get_submitted_draft_itemid($field);
+ $currenttext = file_prepare_draft_area($draftid_editor, $contextid, $filearea, $data->id, $options['subdirs'], $data->{$field}, $options['forcehttps']);
+ $data->{$field.'_editor'} = array('text'=>$currenttext, 'format'=>$data->{$field.'format'}, 'itemid'=>$draftid_editor);
+ } else {
+ $data->{$field.'_editor'} = array('text'=>$data->{$field}, 'format'=>$data->{$field.'format'}, 0);
+ }
return $data;
}
* @param int $itemid item id, required if item exists
* @return object modified data object
*/
-function file_postupdate_standard_editor($data, $field, array $options, $context, $filearea, $itemid) {
+function file_postupdate_standard_editor($data, $field, array $options, $context, $filearea=null, $itemid=null) {
$options = (array)$options;
if (!isset($options['trusttext'])) {
$options['trusttext'] = false;
$editor = $data->{$field.'_editor'};
- $data->{$field} = file_save_draft_area_files($editor['itemid'], $context->id, $filearea, $itemid, $options, $editor['text'], $options['forcehttps']);
+ if ($options['maxfiles'] != 0 or is_null($filearea) or is_null($itemid)) {
+ $data->{$field} = file_save_draft_area_files($editor['itemid'], $context->id, $filearea, $itemid, $options, $editor['text'], $options['forcehttps']);
+ } else {
+ $data->{$field} = $editor['text'];
+ }
$data->{$field.'format'} = $editor['format'];
return $data;
function glossary_comment_add() {
global $USER, $DB;
- $eid = optional_param('eid', 0, PARAM_INT); // Entry ID
+ $entryid = optional_param('entryid', 0, PARAM_INT); // Entry ID
- if (!$entry = $DB->get_record('glossary_entries', array('id'=>$eid))) {
+ 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('coursemisconf');
}
- require_login($course->id, false, $cm);
+ 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');
}
- $mform = new mod_glossary_comment_form();
- $mform->set_data(array('eid'=>$eid, 'action'=>'add'));
+ $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 ($data = $mform->get_data()) {
- $newcomment = new object();
- $newcomment->entryid = $entry->id;
- $newcomment->entrycomment = $data->entrycomment;
- $newcomment->entrycommentformat = $data->entrycommentformat;
- $newcomment->entrycommenttrust = trusttext_trusted($context);
- $newcomment->timemodified = time();
- $newcomment->userid = $USER->id;
-
- if (!$newcomment->id = $DB->insert_record('glossary_comments', $newcomment)) {
- print_error('cannotinsertcomment');
- } else {
- add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&eid=$entry->id", "$newcomment->id", $cm->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 {
function glossary_comment_delete() {
global $USER, $DB;
- $cid = optional_param('cid', 0, PARAM_INT); // Comment ID
+ $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'=>$cid))) {
+ 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('coursemisconf');
}
- require_login($course->id, false, $cm);
+ 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 (data_submitted() and $confirm) {
- $DB->delete_records('glossary_comments', array('id'=>$cid));
+ $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', 'cid'=>$cid, 'confirm'=>1);
+ $optionsyes = array('action'=>'delete', 'id'=>$id, 'confirm'=>1);
$linkno = 'comments.php';
- $optionsno = array('id'=>$cm->id, 'eid'=>$entry->id);
+ $optionsno = array('id'=>$cm->id, 'entryid'=>$entry->id);
$strdeletewarning = get_string('areyousuredeletecomment','glossary');
glossary_comment_print_header($course, $cm, $glossary, $entry, 'delete');
function glossary_comment_edit() {
global $CFG, $USER, $DB;
- $cid = optional_param('cid', 0, PARAM_INT); // Comment ID
+ $id = optional_param('id', 0, PARAM_INT); // Comment ID
- if (!$comment = $DB->get_record('glossary_comments', array('id'=>$cid))) {
+ 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('coursemisconf');
}
- require_login($course->id, false, $cm);
+ require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!$glossary->allowcomments and !has_capability('mod/glossary:managecomments', $context)) {
print_error('nopermissiontodelinglossary', 'glossary');
print_error('cannoteditcommentexpired');
}
- // clean up existing text if needed
- $comment = trusttext_pre_edit($comment, 'entrycomment', $context);
+ $commentoptions = array('trusttext'=>true, 'maxfiles'=>0);
+
+ $comment->action = 'edit';
+ $comment = file_prepare_standard_editor($comment, 'entrycomment', $commentoptions, $context);
- $mform = new mod_glossary_comment_form();
- $mform->set_data(array('cid'=>$cid, 'action'=>'edit', 'entrycomment'=>$comment->entrycomment, 'entrycommentformat'=>$comment->entrycommentformat));
+ $mform = new mod_glossary_comment_form(array('current'=>$comment, 'commentoptions'=>$commentoptions));
- if ($data = $mform->get_data()) {
+ if ($updatedcomment = $mform->get_data()) {
- $updatedcomment = new object();
- $updatedcomment->id = $cid;
- $updatedcomment->entrycomment = $data->entrycomment;
- $updatedcomment->entrycommentformat = $data->entrycommentformat;
- $updatedcomment->entrycommenttrust = trusttext_trusted($context);
- $updatedcomment->timemodified = time();
+ $updatedcomment = file_postupdate_standard_editor($updatedcomment, 'entrycomment', $commentoptions, $context);
+ $updatedcomment->timemodified = time();
$DB->update_record('glossary_comments', $updatedcomment);
add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&eid=$entry->id", "$updatedcomment->id",$cm->id);
function definition() {
$mform =& $this->_form;
+ $current = $this->_customdata['current'];
+ $commentoptions = $this->_customdata['commentoptions'];
+
// visible elements
- $mform->addElement('htmleditor', 'entrycomment',get_string('comment', 'glossary'));
- $mform->addRule('entrycomment', get_string('required'), 'required', null, 'client');
- $mform->setType('entrycomment', PARAM_RAW); // processed by trust text or cleaned before the display
- $mform->setHelpButton('entrycomment', array('writing', 'richtext2'), false, 'editorhelpbutton');
-
- $mform->addElement('format', 'entrycommentformat', get_string('format'));
- $mform->setHelpButton('entrycommentformat', array('textformat', get_string('helpformatting')));
+ $mform->addElement('editor', 'entrycomment_editor', get_string('comment', 'glossary'), $commentoptions);
+ $mform->addRule('entrycomment_editor', get_string('required'), 'required', null, 'client');
+ $mform->setType('entrycomment_editor', PARAM_RAW); // processed by trust text or cleaned before the display
// hidden optional params
- $mform->addElement('hidden', 'cid', 0);
- $mform->setType('cid', PARAM_INT);
+ $mform->addElement('hidden', 'id', 0);
+ $mform->setType('id', PARAM_INT);
- $mform->addElement('hidden', 'eid', 0);
- $mform->setType('eid', PARAM_INT);
+ $mform->addElement('hidden', 'entryid', 0);
+ $mform->setType('entryid', PARAM_INT);
$mform->addElement('hidden', 'action', '');
$mform->setType('action', PARAM_ACTION);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons(false);
+
+//-------------------------------------------------------------------------------
+ $this->set_data($current);
}
}
?>
\ No newline at end of file