From 86183b0716191805c0c829e658ce1e5c9e315971 Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 8 Oct 2003 03:13:12 +0000 Subject: [PATCH] Started out reformatting the code a little and ended up simplifying the interface a bit ... hope you like it, Will! --- lang/en/glossary.php | 27 ++- mod/glossary/lib.php | 16 +- mod/glossary/view.php | 491 ++++++++++++++++++++++-------------------- 3 files changed, 272 insertions(+), 262 deletions(-) diff --git a/lang/en/glossary.php b/lang/en/glossary.php index 913e26ae63..01f9b3afd9 100644 --- a/lang/en/glossary.php +++ b/lang/en/glossary.php @@ -6,11 +6,11 @@ $string['allentries'] = "ALL"; $string['allcategories'] = "All Categories"; $string['allowduplicatedentries'] = "Duplicated entries allowed"; $string['alphabet'] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"; -$string['areyousuredelete'] = "Are you sure you want to delete it?"; +$string['areyousuredelete'] = "Are you sure you want to delete this entry?"; $string['attachment'] = "Attachment"; $string['back'] = "Back"; $string['categories'] = "Categories"; -$string['categoryview'] = "By category"; +$string['categoryview'] = "Browse by category"; $string['category'] = "Category"; $string['categorydeleted'] = "Category deleted"; $string['concept'] = "Concept"; @@ -18,7 +18,7 @@ $string['concepts'] = "Concepts"; $string['definition'] = "Definition"; $string['definitions'] = "Definitions"; $string['deleteentry'] = "Delete entry"; -$string['deletingnoneemptycategory'] = "If a non empty category is deleted, its relations with their entries will also be deleted. If you wish to delete the entries, you will have to do so manually."; +$string['deletingnoneemptycategory'] = "Deleting this category will not delete the entries it contains - they will be marked as uncategorised."; $string['displayformat'] = "Display format"; $string['displayformatdefault'] = "Simple, dictionary style"; $string['displayformat1'] = "Full without author"; @@ -29,12 +29,12 @@ $string['editcategories'] = "Edit categories"; $string['entries'] = "Entries"; $string['entrieswithoutcategory'] = "Entries without category"; $string['entry'] = "Entry"; -$string['entryalreadyexist'] = "Entry already exists."; -$string['entrydeleted'] = "Entry deleted."; -$string['entryexported'] = "Entry succesfully exported."; -$string['explainspecial'] = "Special will show all concepts that do not begin with a letter.
"; -$string['explainalphabet'] = "Select the letter you want to look for.

"; -$string['explainall'] = "ALL will show all entries in one page."; +$string['entryalreadyexist'] = "Entry already exists"; +$string['entrydeleted'] = "Entry deleted"; +$string['entryexported'] = "Entry succesfully exported"; +$string['explainspecial'] = "Shows entries that do not begin with a letter"; +$string['explainalphabet'] = "Browse the glossary using this index"; +$string['explainall'] = "Shows ALL entries on one page"; $string['exportedentry'] = "Exported entry"; $string['exporttomainglossary'] = "Export to main glossary"; $string['glossarytype'] = "Glossary Type"; @@ -42,19 +42,18 @@ $string['mainglossary'] = "Main glossary"; $string['modulename'] = "Glossary"; $string['modulenameplural'] = "Glossaries"; $string['newglossaryentries'] = "New glossary entries:"; -$string['nocategorized'] = "Not categorized"; +$string['nocategorized'] = "Not categorised"; $string['noentries'] = "No entries found in this section"; $string['noentry'] = "No entry found."; -$string['searchconcept'] = "Search:"; -$string['searchindefinition'] = "Search in concept AND definitions?"; +$string['searchindefinition'] = "Search definitions too"; $string['secondaryglossary'] = "Secondary glossary"; $string['showspecial'] = "Show 'Special' link"; $string['showalphabet'] = "Show alphabet"; $string['showall'] = "Show 'ALL' link"; $string['special'] = "Special"; -$string['standardview'] = "Standard View"; +$string['standardview'] = "Browse by alphabet"; $string['studentcanpost'] = "Students can add entries"; $string['warningstudentcapost'] = "(This apply only if the glossary is not the main one)"; -$string['writtenby'] = "By"; +$string['writtenby'] = "by"; ?> diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 98465296ce..1b2fdb5b24 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -655,22 +655,17 @@ global $CFG, $THEME; $strallentries = get_string("allentries", "glossary"); if ($glossary->showalphabet) { - $output .= get_string("explainalphabet","glossary"); - } - if ($glossary->showspecial) { - $output .= get_string("explainspecial","glossary"); - } - if ($glossary->showall) { - $output .= get_string("explainall","glossary"); + $output .= get_string("explainalphabet","glossary").'
'; } - echo "

$output

"; + echo "

$output

"; if ( $glossary->showspecial ) { if ( $l == "SPECIAL" ) { echo "$strspecial | "; } else { - echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL\">$strspecial | "; + $strexplainspecial = get_string("explainspecial","glossary"); + echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL\">$strspecial | "; } } @@ -695,7 +690,8 @@ global $CFG, $THEME; if ( $l == "ALL" ) { echo "$strallentries

"; } else { - echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries

"; + $strexplainall = get_string("explainall","glossary"); + echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries

"; } } } diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 7e0c772f54..105eb0f7b3 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -1,283 +1,298 @@ -course)) { error("Course is misconfigured"); - } - + } + if (! $glossary = get_record("glossary", "id", $cm->instance)) { error("Course module is incorrect"); - } - + } + require_login($course->id); + if (!$cm->visible and !isteacher($course->id)) { notice(get_string("activityiscurrentlyhidden")); - } - + } + add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id"); - + $search = trim(strip_tags($search)); - if ($search and !$entryid ) { - $l = ""; - $searchterms = explode(" ", $search); // Search for words independently + if ($search and !$entryid) { + $l = ""; + $searchterms = explode(" ", $search); // Search for words independently foreach ($searchterms as $key => $searchterm) { if (strlen($searchterm) < 2) { unset($searchterms[$key]); - } - } + } + } $search = trim(implode(" ", $searchterms)); $currentview = ""; - } elseif ( $eid ) { - $search = ""; - } - if ($l == "" and $search == "" and ($eid == "" or $eid == 0) ) { - $l = "A"; - } elseif ( $eid ) { - $l = ""; - } - if ( $currentview ) { - $l = ""; - $currentview = strtolower($currentview); - if ( $currentview ) { - if ( $cat > 0 ) { - $category = get_record("glossary_categories","id",$cat); - if ( !$category ) { - $cat = ""; - } - } - } - } - + } elseif ($eid) { + $search = ""; + } + + if ($l == "" and $search == "" and ($eid == "" or $eid == 0)) { + $l = "A"; + } elseif ($eid) { + $l = ""; + } + + if ($currentview) { + $l = ""; + $currentview = strtolower($currentview); + if ($currentview) { + if ($cat > 0) { + $category = get_record("glossary_categories", "id", $cat); + if (!$category) { + $cat = ""; + } + } + } + } + /// Printing the page header - if ($course->category) { - $navigation = "id\">$course->shortname ->"; - } - - $strglossaries = get_string("modulenameplural", "glossary"); - $strglossary = get_string("modulename", "glossary"); - $strallcategories= get_string("allcategories", "glossary"); - $straddentry = get_string("addentry", "glossary"); - $strnoentries = get_string("noentries", "glossary"); + $navigation = "id\">$course->shortname ->"; + } + + $strglossaries = get_string("modulenameplural", "glossary"); + $strglossary = get_string("modulename", "glossary"); + $strallcategories = get_string("allcategories", "glossary"); + $straddentry = get_string("addentry", "glossary"); + $strnoentries = get_string("noentries", "glossary"); + $strsearchconcept = get_string("searchconcept", "glossary"); + $strsearchindefinition = get_string("searchindefinition", "glossary"); + $strsearch = get_string("search"); + print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname", - "$navigation id>$strglossaries -> $glossary->name", - "", "", true, update_module_button($cm->id, $course->id, $strglossary), - navmenu($course, $cm)); - -/// Printing the header of the glossary - - echo "

$glossary->name

" ; - - print_simple_box_start("center", "70%"); - echo "
"; - ?> -
-
- " name="searchbutton"> - -
-
"; - if (isteacher($course->id) or ($glossary->studentcanpost) and !isguest($course->id)) { - $options = array ("id" => "$cm->id"); - print_single_button("edit.php", $options, $straddentry ); - } - echo "
"; + "$navigation id>$strglossaries -> $glossary->name", + "", "", true, update_module_button($cm->id, $course->id, $strglossary), + navmenu($course, $cm)); + + print_heading($glossary->name); + + +/// Add button + + if (isteacher($course->id) or ($glossary->studentcanpost) and !isguest($course->id)) { + $options = array ("id" => "$cm->id"); + echo '

'; + print_single_button("edit.php", $options, $straddentry); + echo '

'; + } + + +/// Search box + + print_simple_box_start("center", "", $THEME->cellheading); + echo '

'; + echo '

'; + echo ' '; + echo ' '; + echo ''; + echo $strsearchindefinition; + echo ''; + echo '
'; + echo '

'; print_simple_box_end(); - echo "

"; - $data[0]->link = "view.php?id=$id"; - $data[0]->caption = get_string("standardview","glossary"); - - $data[1]->link = "view.php?id=$id¤tview=categories"; - $data[1]->caption = get_string("categoryview","glossary"); - if ( $currentview ) { - $CurrentTab = 1; - } else { - $CurrentTab = 0; - } - glossary_print_tabbed_table_start($data, $CurrentTab, $tCFG); - echo "

"; - if ( $currentview ) { - glossary_print_categories_menu($course, $cm, $glossary, $cat, $category); - $currentcategory = ""; - } else { - glossary_print_alphabet_menu($cm, $glossary, $l); - - if ($l) { - $CurrentLetter = ""; - } elseif( $search ) { - echo "

" . get_string("search") . ": $search

"; - } - - echo "
"; - } +/// Tabbed browsing sections + + echo '

'; + $data[0]->link = "view.php?id=$id"; + $data[0]->caption = get_string("standardview", "glossary"); + + $data[1]->link = "view.php?id=$id¤tview=categories"; + $data[1]->caption = get_string("categoryview", "glossary"); + + if ($currentview) { + $CurrentTab = 1; + } else { + $CurrentTab = 0; + } + + glossary_print_tabbed_table_start($data, $CurrentTab, $tCFG); + echo "

"; + if ($currentview) { + glossary_print_categories_menu($course, $cm, $glossary, $cat, $category); + $currentcategory = ""; + + } else { + glossary_print_alphabet_menu($cm, $glossary, $l); + if ($l) { + $CurrentLetter = ""; + } elseif ($search) { + echo "

$strsearch: $search

"; + } + echo "
"; + } + /// Printing the entries - if ( $search ) { // looking for a term - $allentries = glossary_search_entries($searchterms, $glossary, $includedefinition); - } elseif ( $eid ) { // looking for an entry - $allentries = get_records("glossary_entries", "id", $eid); - } elseif ( $currentview and $cat == -1 ) { // Browsing all categories + if ($search) { // looking for a term + $allentries = glossary_search_entries($searchterms, $glossary, $includedefinition); + } elseif ($eid) { // looking for an entry + $allentries = get_records("glossary_entries", "id", $eid); + } elseif ($currentview and $cat == -1) { // Browsing all categories $sql = "SELECT gec.id gecid, gc.name, gc.id CID, ge.* - FROM {$CFG->prefix}glossary_entries ge, - {$CFG->prefix}glossary_entries_categories gec, - {$CFG->prefix}glossary_categories gc - WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND - gec.entryid = ge.id AND - gc.id = gec.categoryid - ORDER BY gc.name, ge.concept"; - $allentries = get_records_sql( $sql ); - } else { // looking for terms that begin with a specify letter or entries with no category associated - $ownentries = get_records("glossary_entries", "glossaryid", $glossary->id,"concept ASC"); - $importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id,"concept ASC"); - - if ( $ownentries and $importedentries ) { - $allentries = array_merge($ownentries, $importedentries); - usort($allentries, glossary_sort_entries); - } elseif ( $importedentries ) { - $allentries = $importedentries; - } elseif ( $ownentries ) { - $allentries = $ownentries; - } - } - - if ( $allentries ) { - $DumpedDefinitions= 0; + FROM {$CFG->prefix}glossary_entries ge, + {$CFG->prefix}glossary_entries_categories gec, + {$CFG->prefix}glossary_categories gc + WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND + gec.entryid = ge.id AND + gc.id = gec.categoryid + ORDER BY gc.name, ge.concept"; + $allentries = get_records_sql($sql); + } else { // looking for terms that begin with a specify letter or entries with no category associated + $ownentries = get_records("glossary_entries", "glossaryid", $glossary->id, "concept ASC"); + $importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id, "concept ASC"); + + if ($ownentries and $importedentries) { + $allentries = array_merge($ownentries, $importedentries); + usort($allentries, glossary_sort_entries); + } elseif ($importedentries) { + $allentries = $importedentries; + } elseif ($ownentries) { + $allentries = $ownentries; + } + } + + if ($allentries) { + $DumpedDefinitions = 0; foreach ($allentries as $entry) { $DumpToScreen = 0; - $FirstLetter = strtoupper( substr(ltrim($entry->concept),0,strlen($l) ) ); - if ( $l ) { - if ( $l == "ALL" or $FirstLetter == $l) { - if ( $CurrentLetter != $FirstLetter[0] ) { - $CurrentLetter = $FirstLetter[0]; - - if ( $glossary->displayformat == 0 ) { - if ( $DumpedDefinitions > 0) { - echo "

"; - } - echo "\n

cellheading2\">"; - } - if ( $l == "ALL" ) { - echo "$CurrentLetter"; - } - - if ( $glossary->displayformat == 0 ) { - echo "\n
"; - if ( $DumpedDefinitions > 0) { - echo "\n
"; - } - } - } - $DumpToScreen = 1; - } elseif ( $l == "SPECIAL" and ord($FirstLetter) != ord("Ñ") and (ord($FirstLetter)ord("Z")) ) { - $DumpToScreen = 1; - } + $FirstLetter = strtoupper(substr(ltrim($entry->concept), 0, strlen($l))); + if ($l) { + if ($l == "ALL" or $FirstLetter == $l) { + if ($CurrentLetter != $FirstLetter[0]) { + $CurrentLetter = $FirstLetter[0]; + + if ($glossary->displayformat == 0) { + if ($DumpedDefinitions > 0) { + echo "

"; + } + echo "\n

cellheading2\">"; + } + if ($l == "ALL") { + echo "$CurrentLetter"; + } + + if ($glossary->displayformat == 0) { + echo "\n
"; + if ($DumpedDefinitions > 0) { + echo "\n
"; + } + } + } + $DumpToScreen = 1; + } elseif ($l == "SPECIAL" and ord($FirstLetter) != ord("Ñ") and + (ord($FirstLetter) < ord("A") or ord($FirstLetter) > ord("Z"))) { + $DumpToScreen = 1; + } } else { - if ( $currentview ) { - if ( $category ) { - if ( record_exists("glossary_entries_categories","entryid",$entry->id, "categoryid",$category->id) ) { - $DumpToScreen = 1; - } + if ($currentview) { + if ($category) { + if (record_exists("glossary_entries_categories", "entryid", $entry->id, "categoryid", $category->id)) { + $DumpToScreen = 1; + } } else { - if ( $cat < 0 ) { // No categorized - if ( ! record_exists("glossary_entries_categories","entryid",$entry->id) ) { + if ($cat < 0) { // No categorized + if (! record_exists("glossary_entries_categories", "entryid", $entry->id)) { $DumpToScreen = 1; - } - } else { // All categories - if ( $currentcategory != $entry->CID ) { + } + } else { // All categories + if ($currentcategory != $entry->CID) { $currentcategory = $entry->CID; - if ( $glossary->displayformat == 0 ) { - if ( $DumpedDefinitions > 0) { - echo "

"; - } - echo "\n

cellheading2\">"; - } + if ($glossary->displayformat == 0) { + if ($DumpedDefinitions > 0) { + echo "

"; + } + echo "\n

cellheading2\">"; + } echo "$entry->name"; - } - - if ( $glossary->displayformat == 0 ) { - echo "\n
"; - if ( $DumpedDefinitions > 0) { - echo "\n
"; - } - } - + } + + if ($glossary->displayformat == 0) { + echo "\n
"; + if ($DumpedDefinitions > 0) { + echo "\n
"; + } + } + $DumpToScreen = 1; - } - } + } + } } else { $DumpToScreen = 1; - } - } - - if ( $DumpToScreen ) { - $DumpedDefinitions++; - - $concept = $entry->concept; - $definition = $entry->definition; - - if ( $DumpedDefinitions == 1 ) { - if ( $glossary->displayformat == 0 ) { - echo "\n
"; - } - } - if ($search) { - $entry->concept = highlight($search,$concept); - $entry->definition = highlight($search,$definition); - } - if ( !$glossary->mainglossary ) { - $entry->definition = glossary_dynamic_link($course->id,$definition); - } - - glossary_print_entry($course, $cm, $glossary, $entry,$currentview,$cat); - - if ( $glossary->displayformat != 0 ) { - echo "

"; - } - } - } - } - if ( ! $DumpedDefinitions ) { - print_simple_box_start("center", "70%","$THEME->cellheading"); - if ( !$search ) { - echo "

$strnoentries
"; - } else { - echo "
"; - print_string("searchhelp"); - echo "
"; - } - print_simple_box_end(); - } else { - if ( $glossary->displayformat == 0 ) { - echo "\n
"; - } - } - - echo "
"; - glossary_print_tabbed_table_end(); + } + } + + if ($DumpToScreen) { + $DumpedDefinitions++; + + $concept = $entry->concept; + $definition = $entry->definition; + + if ($DumpedDefinitions == 1) { + if ($glossary->displayformat == 0) { + echo "\n
"; + } + } + if ($search) { + $entry->concept = highlight($search, $concept); + $entry->definition = highlight($search, $definition); + } + if (!$glossary->mainglossary) { + $entry->definition = glossary_dynamic_link($course->id, $definition); + } + + glossary_print_entry($course, $cm, $glossary, $entry, $currentview, $cat); + + if ($glossary->displayformat != 0) { + echo "

"; + } + } + } + } + if (! $DumpedDefinitions) { + print_simple_box_start("center", "70%", "$THEME->cellheading"); + if (!$search) { + echo "

$strnoentries
"; + } else { + echo "
"; + print_string("searchhelp"); + echo "
"; + } + print_simple_box_end(); + } else { + if ($glossary->displayformat == 0) { + echo "\n
"; + } + } + + echo "
"; + glossary_print_tabbed_table_end(); /// Finish the page print_footer($course); - + ?> -- 2.39.5