diff --git a/mod/glossary/print.php b/mod/glossary/print.php index 11ddc749097..ad2ee87d5e9 100644 --- a/mod/glossary/print.php +++ b/mod/glossary/print.php @@ -2,15 +2,13 @@ require_once("../../config.php"); require_once("lib.php"); - global $CFG; require_variable($id); // Course Module ID - require_variable($mode,"letter"); // format to show the entries - optional_variable($sortkey,"UPDATE"); // Sorting key if TAB = GLOSSARY_DATE_VIEW - optional_variable($sortorder,"asc"); // Sorting order if TAB = GLOSSARY_DATE_VIEW - optional_variable($hook,"ALL"); - optional_variable($eid); - optional_variable($search); + require_variable($mode,"letter"); // mode to show the entries + optional_variable($hook,"ALL"); // what to show + optional_variable($sortkey,"UPDATE"); // Sorting key + optional_variable($sortorder,"asc"); // Sorting order + optional_variable($offset); // number of entries to bypass if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect"); @@ -24,6 +22,11 @@ error("Course module is incorrect"); } + global $CFG; + if ( !$entriesbypage = $glossary->entbypage ) { + $entriesbypage = $CFG->glossary_entbypage; + } + if ($course->category) { require_login($course->id); if (isguest()) { @@ -31,141 +34,184 @@ } } - if ( $eid ) { - $mode = 'entry'; - } -/// Generating the SQL based on the format to show - switch ($mode) { - case "cat": - $where = ''; - if ($hook) { - if ( $hook != GLOSSARY_SHOW_ALL_CATEGORIES and $hook != GLOSSARY_SHOW_NOT_CATEGORISED ) { - $where = 'and c.id = ' . $hook; - } +/// stablishing flag variables + if ( $sortorder = strtolower($sortorder) ) { + if ($sortorder != 'asc' and $sortorder != 'desc') { + $sortorder = ''; } - $entries = get_records_sql("SELECT ec.id, c.name pivot, e.* - FROM {$CFG->prefix}glossary_entries e, - {$CFG->prefix}glossary_entries_categories ec, - {$CFG->prefix}glossary_categories as c - WHERE e.id = ec.entryid AND ec.categoryid = c.id AND - (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id) - AND e.approved != 0 $where - ORDER BY c.name, e.concept"); + } + if ( $sortkey = strtoupper($sortkey) ) { + if ($sortkey != 'CREATION' and + $sortkey != 'UPDATE' and + $sortkey != 'FIRSTNAME' and + $sortkey != 'LASTNAME' + ) { + $sortkey = ''; + } + } + switch ( $mode = strtolower($mode) ) { + case 'entry': /// Looking for a certain entry id + $tab = GLOSSARY_STANDARD_VIEW; + break; + + case 'cat': /// Looking for a certain cat + $tab = GLOSSARY_CATEGORY_VIEW; + if ( $hook > 0 ) { + $category = get_record("glossary_categories","id",$hook); + } break; - case "date": - //// Valid sorting values - switch ($sortkey) { - case 'CREATION': - $sortkey = 'timecreated'; - break; - - case 'UPDATE': - default: - $sortkey = 'timemodified'; - break; + case 'approval': /// Looking for entries waiting for approval + $tab = GLOSSARY_APPROVAL_VIEW; + if ( !$hook and !$sortkey and !$sortorder) { + $hook = 'ALL'; } - if ($sortorder != 'asc' and $sortorder != 'desc') { + break; + + case 'term': /// Looking for entries that include certain term in its concept, definition or aliases + $tab = GLOSSARY_STANDARD_VIEW; + break; + + case 'date': + $tab = GLOSSARY_DATE_VIEW; + if ( !$sortkey ) { + $sortkey = 'UPDATE'; + } + if ( !$sortorder ) { + $sortorder = 'desc'; + } + break; + + case 'author': /// Looking for entries, browsed by author + $tab = GLOSSARY_AUTHOR_VIEW; + if ( !$hook ) { + $hook = 'ALL'; + } + if ( !$sortkey ) { + $sortkey = 'FIRSTNAME'; + } + if ( !$sortorder ) { $sortorder = 'asc'; } - - $entries = get_records_sql("SELECT e.timemodified pivot, e.* - FROM {$CFG->prefix}glossary_entries e - WHERE (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id) - AND e.approved != 0 - ORDER BY e.$sortkey $sortorder"); - break; - case "letter": + + case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters default: - switch ($CFG->dbtype) { - case "postgres7": - $pivot = "substring(e.concept, 1,1)"; - break; - - case "mysql": - $pivot = "left(e.concept,1)"; - break; - default: - $pivot = "e.concept"; - break; - } - - if ( $hook ) { - if ($hook != 'ALL' and $hook != 'SPECIAL') { - switch ($CFG->dbtype) { - case 'postgres7': - $where = 'and substr(ucase(concept),1,' . strlen($hook) . ') = \'' . strtoupper($hook) . '\''; - break; - case 'mysql': - $where = 'and left(ucase(concept),' . strlen($hook) . ") = '" . strtoupper($hook) . "'"; - break; - default: - $where = ''; - } - } - } elseif ($eid) { - $where = " and e.id = $eid"; - } - - $entries = get_records_sql("SELECT e.id, $pivot pivot, e.* - FROM {$CFG->prefix}glossary_entries e - WHERE (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id) - AND e.approved != 0 $where - ORDER BY e.concept $sortorder"); + $tab = GLOSSARY_STANDARD_VIEW; + if ( !$hook ) { + $hook = 'ALL'; + } break; - } + } - echo '
' . get_string("course") . ': ' . $course->fullname . '
';
- echo get_string("modulename","glossary") . ': ' . $glossary->name . '
' . userdate(time()) . '
'; + echo '' . $site->fullname . ''; + + foreach ($allentries as $entry) { + /// Setting the pivot for the current entry $pivot = $entry->pivot; - if ( $CFG->dbtype != "postgres7" and $CFG->dbtype != "mysql" and $mode != "cat") { + if ( !$fullpivot ) { $pivot = $pivot[0]; - } + } - if ($mode != "date") { - if (strtoupper($groupheader) != strtoupper($pivot)) { - /// Printing th eheader of the group + /// + /// Validating special cases not covered by the SQL statement + /// - if ($tableisopen) { - echo ''; - echo ''; - $tableisopen = 0; - } - $groupheader = $pivot; - echo '
' . $groupheader . '
'; + /// if we're browsing by alphabet and the current concept does not begin with + /// the letter we are look for. + $showentry = 1; + if ( $mode == 'letter' and $hook != 'SPECIAL' and $hook != 'ALL' ) { + if ( substr($entry->concept, 0, strlen($hook)) != $hook ) { + $showentry = 0; } - } - if ( !$tableisopen ) { - echo '| '. $entry->concept . ': | '; - echo '';
-
- if ( $entry->attachment) {
- glossary_print_entry_attachment($entry);
+ /// if the entry is not approved, deal with it based on the current view and
+ /// user.
+ if ( $showentry and $mode != 'approval' ) {
+ if ( !$entry->approved and isteacher($course->id, $entry->userid) ) {
+ $showentry = 0;
+ }
}
- echo format_text(" | ||
| '; + $pivottoshow = $entry->uname; + } else { + echo ' | '; + } + + echo "$pivottoshow" ; + echo ' | '; + echo '||
| '. $entry->concept . ': | '; + echo '';
+
+ if ( $entry->attachment) {
+ glossary_print_entry_attachment($entry);
+ }
+ echo strip_tags($entry->definition);
+
+ echo ' | ||
' . stripslashes_safe($glossary->name);
- if ($isuserframe ) {
+ if ( $isuserframe and $mode != 'search') {
/// the "Print" icon
- echo " id&tab=$tab&mode=$mode&hook=$hook&sortkey=$sortkey&sortorder=$sortorder\">";
+ echo " id&mode=$mode&hook=$hook&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\">";
echo '
';
}
echo '
| ';
echo format_text($glossary->intro);
print_simple_box_end();
}
/// Search box
- echo ' '; - print_simple_box_start("center", "", $THEME->cellheading); - echo ' '; +// echo ' '; + echo '
|