libdir.'/filelib.php'); define("GLOSSARY_SHOW_ALL_CATEGORIES", 0); define("GLOSSARY_SHOW_NOT_CATEGORISED", -1); define("GLOSSARY_NO_VIEW", -1); define("GLOSSARY_STANDARD_VIEW", 0); define("GLOSSARY_CATEGORY_VIEW", 1); define("GLOSSARY_DATE_VIEW", 2); define("GLOSSARY_AUTHOR_VIEW", 3); define("GLOSSARY_ADDENTRY_VIEW", 4); define("GLOSSARY_IMPORT_VIEW", 5); define("GLOSSARY_EXPORT_VIEW", 6); define("GLOSSARY_APPROVAL_VIEW", 7); //Check for global configure default variables if (!isset($CFG->glossary_studentspost)) { set_config("glossary_studentspost", 1); // Students can post entries. } if (!isset($CFG->glossary_dupentries)) { set_config("glossary_dupentries", 0); // Duplicate entries are not allowed. } if (!isset($CFG->glossary_allowcomments)) { set_config("glossary_allowcomments", 0); // Comments are not allowed. } if (!isset($CFG->glossary_linkbydefault)) { set_config("glossary_linkbydefault", 1); // Linking entries is enabled. } if (!isset($CFG->glossary_defaultapproval)) { set_config("glossary_defaultapproval", 1); // Entries are approved. } if (!isset($CFG->glossary_entbypage)) { set_config("glossary_entbypage", 10); // 10 entries are showed. } /// STANDARD FUNCTIONS /////////////////////////////////////////////////////////// function glossary_add_instance($glossary) { /// Given an object containing all the necessary data, /// (defined by the form in mod.html) this function /// will create a new instance and return the id number /// of the new instance. if (!isset($glossary->userating) || !$glossary->userating) { $glossary->assessed = 0; } if (empty($glossary->ratingtime)) { $glossary->assesstimestart = 0; $glossary->assesstimefinish = 0; } if ( !isset($glossary->globalglossary) ) { $glossary->globalglossary = 0; } elseif (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID))) { $glossary->globalglossary = 0; } $glossary->timecreated = time(); $glossary->timemodified = $glossary->timecreated; //Check displayformat is a valid one $formats = get_list_of_plugins('mod/glossary/formats','TEMPLATE'); if (!in_array($glossary->displayformat, $formats)) { error("This format doesn't exist!"); } return insert_record("glossary", $glossary); } function glossary_update_instance($glossary) { /// Given an object containing all the necessary data, /// (defined by the form in mod.html) this function /// will update an existing instance with new data. global $CFG; if (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID))) { unset($glossary->globalglossary); } if (empty($glossary->globalglossary)) { $glossary->globalglossary = 0; } $glossary->timemodified = time(); $glossary->id = $glossary->instance; if (!isset($glossary->userating) || !$glossary->userating) { $glossary->assessed = 0; } if (empty($glossary->ratingtime)) { $glossary->assesstimestart = 0; $glossary->assesstimefinish = 0; } //Check displayformat is a valid one $formats = get_list_of_plugins('mod/glossary/formats','TEMPLATE'); if (!in_array($glossary->displayformat, $formats)) { error("This format doesn't exist!"); } $return = update_record("glossary", $glossary); if ($return and $glossary->defaultapproval) { execute_sql("update {$CFG->prefix}glossary_entries SET approved = 1 where approved != 1 and glossaryid = " . $glossary->id,false); } return $return; } function glossary_delete_instance($id) { /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. if (! $glossary = get_record("glossary", "id", "$id")) { return false; } $result = true; # Delete any dependent records here # if (! delete_records("glossary", "id", "$glossary->id")) { $result = false; } else { if ($categories = get_records("glossary_categories","glossaryid",$glossary->id)) { $cats = ""; foreach ( $categories as $cat ) { $cats .= "$cat->id,"; } $cats = substr($cats,0,-1); if ($cats) { delete_records_select("glossary_entries_categories", "categoryid in ($cats)"); delete_records("glossary_categories", "glossaryid", $glossary->id); } } if ( $entries = get_records("glossary_entries", "glossaryid", $glossary->id) ) { $ents = ""; foreach ( $entries as $entry ) { if ( $entry->sourceglossaryid ) { $entry->glossaryid = $entry->sourceglossaryid; $entry->sourceglossaryid = 0; update_record("glossary_entries",$entry); } else { $ents .= "$entry->id,"; } } $ents = substr($ents,0,-1); if ($ents) { delete_records_select("glossary_comments", "entryid in ($ents)"); delete_records_select("glossary_alias", "entryid in ($ents)"); delete_records_select("glossary_ratings", "entryid in ($ents)"); } } glossary_delete_attachments($glossary); delete_records("glossary_entries", "glossaryid", "$glossary->id"); } return $result; } function glossary_user_outline($course, $user, $mod, $glossary) { /// Return a small object with summary information about what a /// user has done with a given particular instance of this module /// Used for user activity reports. /// $return->time = the time they did it /// $return->info = a short text description if ($entries = glossary_get_user_entries($glossary->id, $user->id)) { $result->info = count($entries) . ' ' . get_string("entries", "glossary"); $lastentry = array_pop($entries); $result->time = $lastentry->timemodified; return $result; } return NULL; } function glossary_get_user_entries($glossaryid, $userid) { /// Get all the entries for a user in a glossary global $CFG; return get_records_sql("SELECT e.*, u.firstname, u.lastname, u.email, u.picture FROM {$CFG->prefix}glossary g, {$CFG->prefix}glossary_entries e, {$CFG->prefix}user u WHERE g.id = '$glossaryid' AND e.glossaryid = g.id AND e.userid = '$userid' AND e.userid = u.id ORDER BY e.timemodified ASC"); } function glossary_user_complete($course, $user, $mod, $glossary) { /// Print a detailed representation of what a user has done with /// a given particular instance of this module, for user activity reports. global $CFG; if ($entries = glossary_get_user_entries($glossary->id, $user->id)) { echo '
';
foreach ($entries as $entry) {
$cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id);
glossary_print_entry($course, $cm, $glossary, $entry,"","",0);
echo ' '; } echo ' |
' . get_string('aliases','glossary').': '.$aliases . ' |
'.$icons.' |
'; $return = glossary_print_entry_ratings($course, $entry, $ratings); echo ' |
\n"; } echo glossary_print_attachments($entry,$format,$align); if ($insidetable) { echo " |
';
}
echo '![]() |
|
'; if (has_capability('mod/glossary:managecategories', $context)) { $options['id'] = $cm->id; $options['mode'] = 'cat'; $options['hook'] = $hook; echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get"); } echo ' | '; echo ''; echo ''; $menu[GLOSSARY_SHOW_ALL_CATEGORIES] = get_string("allcategories","glossary"); $menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","glossary"); $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC"); $selected = ''; if ( $categories ) { foreach ($categories as $currentcategory) { $url = $currentcategory->id; if ( $category ) { if ($currentcategory->id == $category->id) { $selected = $url; } } $menu[$url] = clean_text($currentcategory->name); //Only clean, not filters } } if ( !$selected ) { $selected = GLOSSARY_SHOW_NOT_CATEGORISED; } if ( $category ) { echo format_text($category->name); } else { if ( $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) { echo get_string("entrieswithoutcategory","glossary"); $selected = GLOSSARY_SHOW_NOT_CATEGORISED; } elseif ( $hook == GLOSSARY_SHOW_ALL_CATEGORIES ) { echo get_string("allcategories","glossary"); $selected = GLOSSARY_SHOW_ALL_CATEGORIES; } } echo ' | '; echo ''; echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&mode=cat&hook=", $menu, "catmenu", $selected, "", "", "", false); echo ' | '; echo '
'; print_user_picture($user->id, $course->id, $user->picture); echo ' | '; echo ''; $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); $by->name = ''.$fullname.''; $by->date = userdate($comment->timemodified); echo ' '; echo ' |
'; echo ' '; echo ' | ';
$options = new object();
$options->trusttext = true;
echo format_text($comment->entrycomment, $comment->format, $options);
echo ' ';
$ineditperiod = ((time() - $comment->timemodified < $CFG->maxeditingtime) || $glossary->editalways);
if ( ($glossary->allowcomments && $ineditperiod && $USER->id == $comment->userid) || has_capability('mod/glossary:managecomments', $context)) {
echo "id&action=edit\"> |
'; if ( $entries ) { foreach ( $entries as $entry ) { if (! $glossary = get_record('glossary', 'id', $entry->glossaryid)) { error('Glossary ID was incorrect or no longer exists'); } if (! $course = get_record('course', 'id', $glossary->course)) { error('Glossary is misconfigured - don\'t know what course it\'s from'); } if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid, $glossary->course) ) { error('Glossary is misconfigured - don\'t know what course module it is'); } //If displayformat is present, override glossary->displayformat if ($displayformat < 0) { $dp = $glossary->displayformat; } else { $dp = $displayformat; } //Get popupformatname $format = get_record('glossary_formats','name',$dp); $displayformat = $format->popupformatname; //Check displayformat variable and set to default if necessary if (!$displayformat) { $displayformat = 'dictionary'; } $formatfile = $CFG->dirroot.'/mod/glossary/formats/'.$displayformat.'/'.$displayformat.'_format.php'; $functionname = 'glossary_show_entry_'.$displayformat; if (file_exists($formatfile)) { include_once($formatfile); if (function_exists($functionname)) { $functionname($course, $cm, $glossary, $entry,'','','',''); } } } } echo ' | '; echo '
".get_string("page").":";
$maxpage = (int)(($totalcount-1)/$perpage);
//Lower and upper limit of page
if ($page < 0) {
$page = 0;
}
if ($page > $maxpageallowed) {
$page = $maxpageallowed;
}
if ($page > $maxpage) {
$page = $maxpage;
}
//Calculate the window of pages
$pagefrom = $page - ((int)($maxdisplay / 2));
if ($pagefrom < 0) {
$pagefrom = 0;
}
$pageto = $pagefrom + $maxdisplay - 1;
if ($pageto > $maxpageallowed) {
$pageto = $maxpageallowed;
}
if ($pageto > $maxpage) {
$pageto = $maxpage;
}
//Some movements can be necessary if don't see enought pages
if ($pageto - $pagefrom < $maxdisplay - 1) {
if ($pageto - $maxdisplay + 1 > 0) {
$pagefrom = $pageto - $maxdisplay + 1;
}
}
//Calculate first and last if necessary
$firstpagecode = '';
$lastpagecode = '';
if ($pagefrom > 0) {
$firstpagecode = "$separator1";
if ($pagefrom > 1) {
$firstpagecode .= "$separator...";
}
}
if ($pageto < $maxpage) {
if ($pageto < $maxpage -1) {
$lastpagecode = "$separator...";
}
$lastpagecode .= "$separator".($maxpage+1)."";
}
//Previous
if ($page > 0 && $previousandnext) {
$pagenum = $page - 1;
$code .= " (".get_string("previous").") ";
}
//Add first
$code .= $firstpagecode;
$pagenum = $pagefrom;
//List of maxdisplay pages
while ($pagenum <= $pageto) {
$pagetoshow = $pagenum +1;
if ($pagenum == $page && !$specialselected) {
$code .= "$separator$pagetoshow";
} else {
$code .= "$separator$pagetoshow";
}
$pagenum++;
}
//Add last
$code .= $lastpagecode;
//Next
if ($page < $maxpage && $page < $maxpageallowed && $previousandnext) {
$pagenum = $page + 1;
$code .= "$separator(".get_string("next").")";
}
//Add special
if ($showspecial) {
$code .= '
';
if ($specialselected) {
$code .= $specialtext;
} else {
$code .= "$separator$specialtext";
}
}
//End html
$code .= "