$string['cantexportentry'] = 'Could not export the entry to the main glossary';
$string['cantinsertcat'] = 'Can\'t insert category';
$string['cantinsertrec'] = 'Can\'t insert record';
-$string['cantinsertent'] = 'Could not insert this new entry';
$string['cantinsertrel'] = 'Can\'t insert relation category-entry';
-$string['cantupdateglossary'] = 'Could not update your glossary';
$string['casesensitive'] = 'This entry is case sensitive';
$string['cat'] = 'cat';
$string['categories'] = 'Categories';
$newentry->approved = 1;
$newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
- if (! $DB->update_record("glossary_entries", $newentry)) {
- print_error('cantupdateglossary', 'glossary');
- } else {
- add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid",$cm->id);
- }
+ $DB->update_record("glossary_entries", $newentry);
+ add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid",$cm->id);
redirect("view.php?id=$cm->id&mode=$mode&hook=$hook",get_string("entryapproved","glossary"),1);
die;
?>
$entry->glossaryid = $entry->sourceglossaryid;
$entry->sourceglossaryid = 0;
- if (!$DB->update_record('glossary_entries', $entry)) {
- print_error('cantupdateglossary', 'glossary');
- }
+ $DB->update_record('glossary_entries', $entry);
// move attachments too
$fs = get_file_storage();
require_once('lib.php');
require_once('edit_form.php');
-global $CFG, $USER;
-
$cmid = required_param('cmid', PARAM_INT); // Course Module ID
$id = optional_param('id', 0, PARAM_INT); // EntryID
print_error('coursemisconf');
}
-require_login($course->id, false, $cm);
+require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// TODO: this fetches cats from both main and secondary glossary :-(
$entry->categories = array_values($categoriesarr);
}
- $entry->cmid = $cm->id;
} else { // new entry
require_capability('mod/glossary:write', $context);
$entry = new object();
- $entry->cmid = $cm->id;
+ $entry->id = null;
+ $entry->definition = '';
+ $entry->format = FORMAT_HTML; // TODO: better default value
}
+$entry->cmid = $cm->id;
+
+$draftid_editor = file_get_submitted_draft_itemid('entry');
+$currenttext = file_prepare_draft_area($draftid_editor, $context->id, 'glossary_entry', $entry->id, true, $entry->definition);
+$entry->entry = array('text'=>$currenttext, 'format'=>$entry->format, 'itemid'=>$draftid_editor);
+
+$draftitemid = file_get_submitted_draft_itemid('attachments');
+file_prepare_draft_area($draftitemid, $context->id, 'glossary_attachment', $entry->id , false);
+$entry->attachements = $draftitemid;
+
// set form initial data
$mform->set_data($entry);
}
} else if ($data = $mform->get_data()) {
- trusttext_after_edit($data->definition, $context);
-
$timenow = time();
if (empty($entry->id)) {
}
$entry->concept = trim($data->concept);
- $entry->definition = $data->definition;
- $entry->format = $data->format;
+ $entry->definition = ''; // updated later
+ $entry->format = FORMAT_HTML; // updated later
$entry->timemodified = $timenow;
$entry->approved = 0;
$entry->usedynalink = isset($data->usedynalink) ? $data->usedynalink : 0;
if (empty($entry->id)) {
//new entry
- if ($entry->id = $DB->insert_record('glossary_entries', $entry)) {
- add_to_log($course->id, "glossary", "add entry",
- "view.php?id=$cm->id&mode=entry&hook=$enty->id", $entry->id, $cm->id);
- } else {
- print_error('cantinsertent', 'glossary');
- }
- //refetch complete entry
- $entry = $DB->get_record('glossary_entries', array('id'=>$entry->id));
+ $entry->id = $DB->insert_record('glossary_entries', $entry);
+ add_to_log($course->id, "glossary", "add entry",
+ "view.php?id=$cm->id&mode=entry&hook=$enty->id", $entry->id, $cm->id);
} else {
//existing entry
- if ($DB->update_record('glossary_entries', $entry)) {
- add_to_log($course->id, "glossary", "update entry",
- "view.php?id=$cm->id&mode=entry&hook=$entry->id",
- $entry->id, $cm->id);
- } else {
- print_error('cantupdateglossary', 'glossary');
- }
+ $DB->update_record('glossary_entries', $entry);
+ add_to_log($course->id, "glossary", "update entry",
+ "view.php?id=$cm->id&mode=entry&hook=$entry->id",
+ $entry->id, $cm->id);
}
- // save attachment
- $filename = $mform->get_new_filename('attachment');
+ // save and relink embedded images
+ $entry->format = $data->entry['format'];
+ $entry->definition = file_save_draft_area_files($draftid_editor, $context->id, 'glossary_entry', $entry->id, true, $data->entry['text']);
+ trusttext_after_edit($entry->definition, $context);
- if ($filename !== false) {
- $filearea = 'glossary_attachment';
- $fs = get_file_storage();
+ // save attachments
+ $info = file_get_draft_area_info($draftitemid);
+ $entry->attachment = ($info['filecount']>0) ? '1' : '';
+ file_save_draft_area_files($draftitemid, $context->id, 'glossary_attachment', $entry->id, false);
- $fs->delete_area_files($context->id, $filearea, $entry->id);
+ // store the final values
+ $DB->update_record('glossary_entries', $entry);
- if ($mform->save_stored_file('attachment', $context->id, $filearea, $entry->id, '/', $filename, true, $USER->id)) {
- $entry->attachment = '1';
- } else {
- $entry->attachment = '';
- }
- $DB->update_record('glossary_entries', $entry);
- }
+ //refetch complete entry
+ $entry = $DB->get_record('glossary_entries', array('id'=>$entry->id));
// update entry categories
$DB->delete_records('glossary_entries_categories', array('entryid'=>$entry->id));
$mform->setType('concept', PARAM_TEXT);
$mform->addRule('concept', null, 'required', null, 'client');
- $mform->addElement('htmleditor', 'definition', get_string('definition', 'glossary'), array('rows'=>20));
- $mform->setType('definition', PARAM_RAW);
- $mform->addRule('definition', null, 'required', null, 'client');
- $mform->setHelpButton('definition', array('writing', 'richtext2'), false, 'editorhelpbutton');
-
- $mform->addElement('format');
+ $mform->addElement('editor', 'entry', get_string('definition', 'glossary'),
+ array('maxfiles' => EDITOR_UNLIMITED_FILES, 'filearea' => 'glossary_entry'));
+ $mform->setType('entry', PARAM_RAW);
+ $mform->addRule('entry', get_string('required'), 'required', null, 'client');
+ $mform->setHelpButton('entry', array('reading', 'writing', 'questions', 'richtext2'), false, 'editorhelpbutton');
if ($categories = $DB->get_records_menu('glossary_categories', array('glossaryid'=>$glossary->id), 'name ASC', 'id, name')){
$categories = array(0 => get_string('notcategorised', 'glossary')) + $categories;
$mform->setType('aliases', PARAM_TEXT);
$mform->setHelpButton('aliases', array('aliases2', strip_tags(get_string('aliases', 'glossary')), 'glossary'));
- $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
- $mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'glossary'), 'glossary'));
+ $mform->addElement('filemanager', 'attachments', get_string('attachment', 'glossary'),
+ array('subdirs'=>0,
+// 'maxbytes'=>$glossary->maxbytes,
+// 'maxfiles'=>-1,
+ 'filetypes'=>'*',
+ 'returnvalue'=>'ref_id'
+ ));
+ $mform->setHelpButton('attachments', array('attachment2', get_string('attachment', 'glossary'), 'glossary'));
if (!$glossary->usedynalink) {
$mform->addElement('hidden', 'usedynalink', $CFG->glossary_linkentries);
//Use this function to show the definition
//Comments: Configuration not supported
- glossary_print_entry_definition($entry);
+ glossary_print_entry_definition($entry, $glossary, $cm);
//Line separator to show this template fine. :-)
echo "<br />\n";
echo '<div class="concept">';
glossary_print_entry_concept($entry);
echo ':</div> ';
- glossary_print_entry_definition($entry);
+ glossary_print_entry_definition($entry, $glossary, $cm);
$entry->alias = '';
echo '</td></tr>';
echo '<div class="concept">';
glossary_print_entry_concept($entry);
echo ':</div> ';
- glossary_print_entry_definition($entry);
+ glossary_print_entry_definition($entry, $glossary, $cm);
echo '</td></tr>';
echo '<tr valign="top"><td class="entrylowersection">';
$return = glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, $printicons, $ratings, $aliases);
}
glossary_print_entry_attachment($entry, $cm, null,$align,false);
}
- glossary_print_entry_definition($entry);
+ glossary_print_entry_definition($entry, $glossary, $cm);
if ($printicons or $ratings or $aliases) {
echo '</td></tr>';
echo '<b>';
glossary_print_entry_concept($entry);
echo ':</b> ';
- glossary_print_entry_definition($entry);
+ glossary_print_entry_definition($entry, $glossary, $cm);
$return = glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, false, false, false);
echo '</td>';
echo '</tr>';
echo '<td colspan="2" class="entry">';
echo '<b>'.get_string('answer','glossary').':</b> ';
- glossary_print_entry_definition($entry);
+ glossary_print_entry_definition($entry, $glossary, $cm);
echo '</td></tr>';
echo '<tr valign="top"><td colspan="3" class="entrylowersection">';
echo '<td class="left"> </td>';
echo '<td colspan="2" class="entry">';
- glossary_print_entry_definition($entry);
+ glossary_print_entry_definition($entry, $glossary, $cm);
echo '</td></tr>';
echo '<tr valign="top">';
echo '<tr valign="top">';
echo '<td width="100%" colspan="2" class="entry">';
- glossary_print_entry_definition($entry);
+ glossary_print_entry_definition($entry, $glossary, $cm);
echo '</td></tr>';
echo '<tr valign="top"><td colspan="2" class="entrylowersection">';
$return = $functionname($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings);
} else if ($printview) {
//If the glossary_print_entry_XXXX function doesn't exist, print default (old) print format
- $return = glossary_print_entry_default($entry);
+ $return = glossary_print_entry_default($entry, $glossary, $cm);
}
}
}
}
//Default (old) print format used if custom function doesn't exist in format
-function glossary_print_entry_default ($entry) {
+function glossary_print_entry_default ($entry, $glossary, $cm) {
echo '<h3>'. strip_tags($entry->concept) . ': </h3>';
$definition = $entry->definition;
$definition = trusttext_strip($definition); //make 100% sure TRUSTTEXT marker was not created
}
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $definition = file_rewrite_pluginfile_urls($definition, 'pluginfile.php', $context->id, 'glossary_entry', $entry->id);
+
$options = new object();
$options->para = false;
$options->trusttext = true;
echo $text;
}
-function glossary_print_entry_definition($entry) {
+function glossary_print_entry_definition($entry, $glossary, $cm) {
global $DB;
$definition = $entry->definition;
$definition = trusttext_strip($definition); //make 100% sure TRUSTTEXT marker was not created
}
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $definition = file_rewrite_pluginfile_urls($definition, 'pluginfile.php', $context->id, 'glossary_entry', $entry->id);
+
$text = format_text($definition, $entry->format, $options);
// Stop excluding concepts from autolinking
// finally send the file
send_stored_file($file, $lifetime, 0);
- } else if ($filearea === 'glossary_attachment') {
+ } else if ($filearea === 'glossary_attachment' or $filearea === 'glossary_entry') {
$entryid = (int)array_shift($args);
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) {
return sha1(serialize($this->entry));
}
}
-
-?>