From b1918034709bdcafe625646982d4851d3822c812 Mon Sep 17 00:00:00 2001 From: willcast Date: Tue, 18 Nov 2003 00:41:35 +0000 Subject: [PATCH] - Now you can override the display format of a glossary (useful to certain display format -asked by Tom Murdock-, automatic linking, etc) --- mod/glossary/lib.php | 20 +++++++++-------- mod/glossary/showentry.php | 3 ++- mod/glossary/view.php | 44 +++++++++++++++++++++----------------- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index e9d0bc3e17..9c31a2b772 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -317,16 +317,18 @@ global $CFG; (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) $where $orderby"); } -function glossary_print_entry($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons = 1) { +function glossary_print_entry($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons = 1, $displayformat = -1) { global $THEME, $USER, $CFG; - + if ( $displayformat < 0 ) { + $displayformat = $glossary->displayformat; + } if ($entry->approved or ($USER->id == $entry->userid and !isteacher($course->id)) or $mode == 'approval') { $permissiongranted = 0; - $formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php"; + $formatfile = "$CFG->dirroot/mod/glossary/formats/$displayformat.php"; $functionname = "glossary_print_entry_by_format"; - $basicformat = ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or - $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS); + $basicformat = ($displayformat == GLOSSARY_FORMAT_SIMPLE or + $displayformat == GLOSSARY_FORMAT_CONTINUOUS); if ( !$basicformat ) { if ( file_exists($formatfile) ) { include_once($formatfile); @@ -338,10 +340,10 @@ function glossary_print_entry($course, $cm, $glossary, $entry, $mode="",$hook="" $permissiongranted = 1; } - if ( !$basicformat and $permissiongranted ) { + if ( !$basicformat and $permissiongranted or $displayformat >= 2) { glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode,$hook,$printicons); } else { - switch ( $glossary->displayformat ) { + switch ( $displayformat ) { case GLOSSARY_FORMAT_SIMPLE: glossary_print_entry_by_default($course, $cm, $glossary, $entry,$mode,$hook,$printicons); break; @@ -1206,7 +1208,7 @@ function glossary_print_comment($course, $cm, $glossary, $entry, $comment) { echo ""; } -function glossary_print_dynaentry($courseid, $entries) { +function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) { global $THEME, $USER; $colour = $THEME->cellheading2; @@ -1224,7 +1226,7 @@ function glossary_print_dynaentry($courseid, $entries) { if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $glossary->course) ) { error("Glossary is misconfigured - don't know what course module it is "); } - glossary_print_entry($course, $cm, $glossary, $entry); + glossary_print_entry($course, $cm, $glossary, $entry, "","",0,$displayformat); } } echo ""; diff --git a/mod/glossary/showentry.php b/mod/glossary/showentry.php index c7fd7c3dd3..626fd0c01d 100644 --- a/mod/glossary/showentry.php +++ b/mod/glossary/showentry.php @@ -5,6 +5,7 @@ optional_variable($concept); optional_variable($courseid,0); optional_variable($eid,0); + optional_variable($displayformat,-1); print_header(); if ( $eid ) { @@ -19,7 +20,7 @@ " e.usedynalink != 0 and g.usedynalink != 0"); } if ( $entries ) { - glossary_print_dynaentry($courseid, $entries); + glossary_print_dynaentry($courseid, $entries, $displayformat); } close_window_button(); diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 4d72b6fc7a..dcb2276d11 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -3,7 +3,8 @@ require_once("../../config.php"); require_once("lib.php"); $debug = 0; - +// $CFG->startpagetime = microtime(); + require_variable($id); // Course Module ID optional_variable($tab,GLOSSARY_NO_VIEW); // browsing entries by categories? @@ -18,9 +19,10 @@ // concept | timecreated | ... ] optional_variable($sortorder,""); // it defines the order of the sorting (ASC or DESC) - optional_variable($offset,0); // entries to bypass (for paging purpouses) + optional_variable($offset,0); // entries to bypass (for paging purpouses) - optional_variable($show,""); // [ concept | alias ] => mode=term hook=$show + optional_variable($show,""); // [ concept | alias ] => mode=term hook=$show + optional_variable($displayformat,-1); // override of the glossary display format if ( $show ) { $mode = 'term'; @@ -229,7 +231,10 @@ // global $db; // $db->debug = true; - + $userid = ''; + if ( $USER->id ) { + $userid = "OR ge.userid = $USER->id"; + } switch ($tab) { case GLOSSARY_CATEGORY_VIEW: if ($hook == GLOSSARY_SHOW_ALL_CATEGORIES ) { @@ -240,7 +245,7 @@ {$CFG->prefix}glossary_categories gc"; $sqlwhere = "WHERE (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND ge.id = gec.entryid AND gc.id = gec.categoryid AND - (ge.approved != 0 OR ge.userid = $USER->id)"; + (ge.approved != 0 $userid)"; if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) { $sqlorderby = ' ORDER BY gc.name, ge.timecreated'; @@ -254,7 +259,7 @@ $sqlselect = "SELECT concept pivot, ge.*"; $sqlfrom = "FROM {$CFG->prefix}glossary_entries ge"; $sqlwhere = "WHERE (glossaryid = '$glossary->id' OR sourceglossaryid = '$glossary->id') AND - (ge.approved != 0 OR ge.userid = $USER->id)"; + (ge.approved != 0 $userid)"; $sqlorderby = ' ORDER BY concept'; @@ -267,7 +272,7 @@ $sqlwhere = "WHERE ge.id = ce.entryid AND ce.categoryid = $hook AND ce.categoryid = c.id AND ge.approved != 0 AND (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id) AND - (ge.approved != 0 OR ge.userid = $USER->id)"; + (ge.approved != 0 $userid)"; $sqlorderby = ' ORDER BY c.name, ge.concept'; @@ -306,7 +311,7 @@ $sqlselect = "SELECT ge.id, $usernamefield pivot, $usernametoshow uname, u.id uid, ge.*"; $sqlfrom = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}user u"; $sqlwhere = "WHERE ge.userid = u.id AND - ge.approved != 0 + (ge.approved != 0 $userid) $where AND (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id)"; $sqlorderby = "ORDER BY $usernamefield $sortorder, ge.concept"; @@ -403,7 +408,7 @@ } $sqlwhere = "WHERE (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) AND - (ge.approved != 0 OR ge.userid = $USER->id) + (ge.approved != 0 $userid) $where"; switch ( $tab ) { case GLOSSARY_DATE_VIEW: @@ -422,15 +427,8 @@ break; } -/* - print_simple_box_start("center","85%"); - print_object($allentries); - print_simple_box_end(); - $db->debug=false; -*/ /// printing the entries - $entriesshown = 0; $currentpivot = ''; if ( $hook == 'SPECIAL' ) { @@ -457,8 +455,6 @@ $paging = "
" . get_string ("jumpto") . " $paging
"; } echo "$paging"; - glossary_debug($debug,'
SELECT normal:' . count($allentries) . '
',0); - glossary_debug($debug,'
SELECT count(*):' . $count . '
',0); if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) { $printpivot = 0; @@ -572,11 +568,12 @@ } /// and finally print the entry. - glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook); + glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat); + $entriesshown++; -// echo '

'; } } + echo '

'; if ( $tableisopen ) { if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS OR $glossary->displayformat == GLOSSARY_FORMAT_SIMPLE ) { @@ -598,4 +595,11 @@ /// Finish the page print_footer($course); +/* + if (isadmin()) { + echo "

"; + echo microtime_diff($CFG->startpagetime, microtime()); + echo "

"; + } +*/ ?> \ No newline at end of file -- 2.39.5