if ($mform->save_files($dir) and $newfilename = $mform->get_new_filename()) { $todb->attachment = $newfilename; } if (update_record('glossary_entries', $todb)) { add_to_log($course->id, "glossary", "update entry", "view.php?id={$cm->id}&mode=entry&hook={$todb->id}", $todb->id, $cm->id); } else { error("Could not update your glossary"); } } else { $todb->userid = $USER->id; $todb->timecreated = $timenow; $todb->sourceglossaryid = 0; $todb->teacherentry = has_capability('mod/glossary:manageentries', $context); if ($todb->id = insert_record("glossary_entries", $todb)) { $e = $todb->id; $dir = glossary_file_area_name($todb); if ($mform->save_files($dir) and $newfilename = $mform->get_new_filename()) { set_field("glossary_entries", "attachment", $newfilename, "id", $todb->id); } add_to_log($course->id, "glossary", "add entry", "view.php?id={$cm->id}&mode=entry&hook={$todb->id}", $todb->id, $cm->id); } else { error("Could not insert this new entry"); } } delete_records("glossary_entries_categories", "entryid", $e); delete_records("glossary_alias", "entryid", $e); if (empty($fromform->notcategorised) && isset($fromform->categories)) { $newcategory->entryid = $e; foreach ($fromform->categories as $category) { if ($category > 0) { $newcategory->categoryid = $category;
function glossary_print_attachments($entry, $return = NULL, $align = "left") { // if return=html, then return a html string. // if return=text, then return a text-only string. // otherwise, print HTML for non-images, and return image HTML // if attachment is an image, $align set its aligment. global $CFG; $newentry = $entry; if ($newentry->sourceglossaryid) { $newentry->glossaryid = $newentry->sourceglossaryid; } $filearea = glossary_file_area_name($newentry); $imagereturn = ""; $output = ""; if ($basedir = glossary_file_area($newentry)) { if ($files = get_directory_list($basedir)) { $strattachment = get_string("attachment", "glossary"); foreach ($files as $file) { $icon = mimeinfo("icon", $file); $ffurl = get_file_url("{$filearea}/{$file}"); $image = "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"\" />"; if ($return == "html") { $output .= "<a href=\"{$ffurl}\">{$image}</a> "; $output .= "<a href=\"{$ffurl}\">{$file}</a><br />"; } else { if ($return == "text") { $output .= "{$strattachment} {$file}:\n{$ffurl}\n"; } else { if ($icon == "image.gif") { // Image attachments don't get printed as links $imagereturn .= "<img src=\"{$ffurl}\" align=\"{$align}\" alt=\"\" />"; } else { echo "<a href=\"{$ffurl}\">{$image}</a> "; echo "<a href=\"{$ffurl}\">{$file}</a><br />"; } } } } } } if ($return) { return $output; } return $imagereturn; }