moodle/mod/glossary/view.php
willcast 0a855df8f0 - Initial changes to categorize the entries..
- A new function in lib that perhaps could be used in other modules:
   print_tabbed_table_start and print_tabbed_table_end
2003-09-18 23:36:06 +00:00

263 lines
8.9 KiB
PHP
Raw Blame History

<?PHP // $Id$
/// This page prints a particular instance of glossary
require_once("../../config.php");
require_once("lib.php");
require_variable($id); // Course Module ID, or
optional_variable($l); // letter to look for
optional_variable($eid); // Entry ID
optional_variable($search, ""); // search string
optional_variable($includedefinition); // include definition in search function?
optional_variable($currentview); // browsing entries by categories?
optional_variable($cat); // categoryID
if ($l == "" and $search == "" and $eid == "") {
$l = "A";
}
if ( $currentview ) {
$currentview = strtolower($currentview);
if ( !$currentview ) {
$currentview = "";
} else {
if ( !$cat ) {
$cat = 1;
}
$category = get_record("glossary_categories","id",$cat);
}
}
$search = trim(strip_tags($search));
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));
} elseif ( $eid ) {
$search = "";
}
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
if (! $glossary = get_record("glossary", "id", $cm->instance)) {
error("Course module is incorrect");
}
require_login($course->id);
add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id");
/// Print the page header
if ($course->category) {
$navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
}
$strglossaries = get_string("modulenameplural", "glossary");
$strglossary = get_string("modulename", "glossary");
$strselectletter = get_string("selectletter", "glossary");
$strspecial = get_string("special", "glossary");
$strallentries = get_string("allentries", "glossary");
$strnoentries = get_string("noentries", "glossary");
$straddentry = get_string("addentry", "glossary");
$streditentry = get_string("editentry", "glossary");
$strdeleteentry = get_string("deleteentry", "glossary");
print_header("$course->shortname: $glossary->name", "$course->fullname",
"$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> $glossary->name",
"", "", true, update_module_button($cm->id, $course->id, $strglossary),
navmenu($course, $cm));
/// Print the main part of the page
/// Printing the navigation links (letters to look for)
echo "<p><center><b>$glossary->name<p>" ;
if ( !$course->visible ) {
notice(get_string("activityiscurrentlyhidden"));
}
print_simple_box_start("center", "70%");
echo "<CENTER>$strselectletter";
?>
<form method="POST" action="view.php">
<? p(get_string("searchconcept","glossary")) ?> <input type="text" name="search" size="20" value=""> <br><? p(get_string("searchindefinition","glossary")) ?> <input type="checkbox" name="includedefinition" value="1">
<input type="submit" value="Search" name="searchbutton">
<input type="hidden" name="id" value="<? p($cm->id) ?>">
</form>
<?
if ( $glossary->showspecial ) {
echo "<p><a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=SPECIAL\">$strspecial</a> | ";
}
if ( $glossary->showalphabet ) {
$alphabet = explode("|", get_string("alphabet","glossary"));
$letters_by_line = 14;
for ($i = 0; $i < count($alphabet); $i++) {
echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=$alphabet[$i]\">$alphabet[$i]</a>";
if ((int) ($i % $letters_by_line) != 0 or $i == 0) {
echo " | ";
} else {
echo "<br>";
}
}
}
if ( $glossary->showall ) {
echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=ALL\">$strallentries</a></p>";
}
if (isteacher($course->id) or $glossary->studentcanpost) {
$options = array ("id" => "$cm->id");
echo "<CENTER>";
print_single_button("edit.php", $options, $straddentry );
echo "</CENTER>";
}
print_simple_box_end();
echo "<p align=center>";
if ($l) {
$CurrentLetter = "";
if ($l == "ALL" or $l == "SPECIAL") {
if ( $l == "ALL" ) {
echo "<h2>$strallentries</h2><p>";
} elseif ($l == "SPECIAL") {
echo "<h2>$strspecial</h2><p>";
}
}
} elseif( $search ) {
echo get_string("search") . ": $search";
}
$data[0]->link = "view.php?id=$id&l=$l&eid=$eid&search=$search&includedefinition=$includedefinition";
$data[0]->caption = get_string("standardview","glossary");
$data[1]->link = "view.php?id=$id&l=$l&eid=$eid&search=$search&includedefinition=$includedefinition&currentview=categories&cat=$cat";
$data[1]->caption = get_string("categoryview","glossary");
$tCFG->TabTableBGColor = $THEME->cellcontent2;
$tCFG->TabTableWidth = "70%";
$tCFG->ActiveTabColor = $THEME->cellcontent2;
$tCFG->InactiveTabColor = $THEME->cellheading2;
$tCFG->TabsPerRow = 5;
$tCFG->TabSeparation = 4;
if ( $cat ) {
$CurrentTab = 1;
} else {
$CurrentTab = 0;
}
print_tabbed_table_start($data, $CurrentTab, $tCFG);
echo "<center>";
if ( $cat ) {
echo "<b>$category->name</b><hr>";
}
/// 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);
} else { // looking for terms that begin with a specify letter
$allentries = get_records("glossary_entries", "glossaryid", $glossary->id,"concept ASC");
}
if ( $allentries ) {
$DumpedDefinitions= 0;
foreach ($allentries as $entry) {
$DumpToScreen = 0;
$FirstLetter = strtoupper( ltrim( $entry->concept[0] ) );
if ( $l ) {
if ( $l == "ALL" or $FirstLetter == $l) {
if ( $CurrentLetter != $FirstLetter ) {
$CurrentLetter = $FirstLetter;
if ( $glossary->displayformat == 0 ) {
if ( $DumpedDefinitions > 0) {
echo "</table></center><p>";
}
echo "\n<center><TABLE BORDER=0 CELLSPACING=0 width=95% valign=top cellpadding=10><tr><td align=center BGCOLOR=\"$THEME->cellheading2\">";
}
echo "<b>$CurrentLetter</b>";
if ( $glossary->displayformat == 0 ) {
echo "\n</center></td></tr></TABLE></center>";
if ( $DumpedDefinitions > 0) {
echo "\n<center><TABLE BORDER=1 CELLSPACING=0 width=95% valign=top cellpadding=10>";
}
}
}
$DumpToScreen = 1;
} elseif ( $l == "SPECIAL" and ord($FirstLetter) != ord("<22>") and (ord($FirstLetter)<ord("A") or ord($FirstLetter)>ord("Z")) ) {
$DumpToScreen = 1;
}
} else {
$DumpToScreen = 1;
}
if ( $DumpToScreen ) {
$DumpedDefinitions++;
$concept = $entry->concept;
$definition = $entry->definition;
if ( $DumpedDefinitions == 1 ) {
if ( $glossary->displayformat == 0 ) {
echo "\n<center><TABLE BORDER=1 CELLSPACING=0 width=95% valign=top cellpadding=10>";
}
}
if ($search) {
$entry->concept = highlight($search,$concept);
$entry->definition = highlight($search,$definition);
}
glossary_print_entry($course, $cm, $glossary, $entry);
if ( $glossary->displayformat != 0 ) {
echo "<p>";
}
}
}
}
if ( ! $DumpedDefinitions ) {
print_simple_box_start("center", "70%","$THEME->cellheading");
if ( !$search ) {
echo "<center>$strnoentries</center>";
} else {
echo "<center>";
print_string("searchhelp");
echo "</center>";
}
print_simple_box_end();
} else {
if ( $glossary->displayformat == 0 ) {
echo "\n</TABLE></center>";
}
}
echo "</center>";
print_tabbed_table_end();
/// Finish the page
print_footer($course);
?>