]> git.mjollnir.org Git - moodle.git/commitdiff
- Improved printer-friendly version
authorwillcast <willcast>
Tue, 18 Nov 2003 13:49:31 +0000 (13:49 +0000)
committerwillcast <willcast>
Tue, 18 Nov 2003 13:49:31 +0000 (13:49 +0000)
- Cosmetic change in the main view of a glossary.

mod/glossary/print.php
mod/glossary/sql.php [new file with mode: 0644]
mod/glossary/view.php

index 11ddc74909707e6cc1710b6a5b7da05b04665daf..ad2ee87d5e9ad3d32ae6ee969bdc1795913ae47a 100644 (file)
@@ -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");
         error("Course module is incorrect");
     } 
     
+    global $CFG;
+    if ( !$entriesbypage = $glossary->entbypage ) {
+        $entriesbypage = $CFG->glossary_entbypage;
+    }
+
     if ($course->category) {
         require_login($course->id);    
         if (isguest()) {
         } 
     }
 
-    if ( $eid ) {
-        $mode = 'entry';
+/// stablishing flag variables
+    if ( $sortorder = strtolower($sortorder) ) {
+        if ($sortorder != 'asc' and $sortorder != 'desc') {
+            $sortorder = '';
+        }
     }
-/// 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;
-            }
+    if ( $sortkey = strtoupper($sortkey) ) {
+        if ($sortkey != 'CREATION' and 
+            $sortkey != 'UPDATE' and 
+            $sortkey != 'FIRSTNAME' and 
+            $sortkey != 'LASTNAME'
+            ) {
+            $sortkey = '';
         }
-        $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");
+    }
 
+    switch ( $mode = strtolower($mode) ) {
+    case 'entry':  /// Looking for a certain entry id
+        $tab = GLOSSARY_STANDARD_VIEW;
     break;
-
-    case "date":
-    //// Valid sorting values
-        switch ($sortkey) {
-        case 'CREATION':
-            $sortkey = 'timecreated';
-        break;
-
-        case 'UPDATE':
-        default:
-            $sortkey = 'timemodified';
-        break;
-        }
-        if ($sortorder != 'asc' and $sortorder != 'desc') {
-            $sortorder = 'asc';
+    
+    case 'cat':    /// Looking for a certain cat
+        $tab = GLOSSARY_CATEGORY_VIEW;
+        if ( $hook > 0 ) {
+            $category = get_record("glossary_categories","id",$hook);
         }
+    break;
 
-        $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");
+    case 'approval':    /// Looking for entries waiting for approval
+        $tab = GLOSSARY_APPROVAL_VIEW;
+        if ( !$hook and !$sortkey and !$sortorder) {
+            $hook = 'ALL';
+        }
+    break;
 
+    case 'term':   /// Looking for entries that include certain term in its concept, definition or aliases
+        $tab = GLOSSARY_STANDARD_VIEW;
     break;
-    case "letter":
-    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";
+    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.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");
     break;
-    } 
 
-    echo '<p><STRONG>' . get_string("course") . ': <i>' . $course->fullname . '</i><br />';
-    echo get_string("modulename","glossary") . ': <i>' . $glossary->name . '</i></STRONG></p>';
+    case 'letter':  /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
+    default:
+        $tab = GLOSSARY_STANDARD_VIEW;
+        if ( !$hook ) {
+            $hook = 'ALL';  
+        } 
+    break;
+    }  
 
-    if ( !$entries ) {
-        echo get_string("noentries","glossary");
-        exit;
+    include_once("sql.php");
+    
+    $entriesshown = 0;
+    $currentpivot = '';
+    if ( $hook == 'SPECIAL' ) {
+        $alphabet = explode(",", get_string("alphabet"));
     }
-                                    
-    $groupheader = '';
     $tableisopen = 0;
-    foreach ($entries as $entry) {
+
+    $site = get_record("course","id",1);
+    echo '<p align="right"><font size=-1>' . userdate(time()) . '</font></p>';
+    echo '<strong>' . $site->fullname . '</strong><br>';
+    echo get_string("course") . ': <strong>' . $course->fullname . '</strong><br \>';
+    echo get_string("modulename","glossary") . ': <strong>' . $glossary->name . '</strong><p>';
+    
+    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];
-        }
+        }            
+        
+    /// 
+    /// Validating special cases not covered by the SQL statement
+    /// 
+
+    /// 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 ($mode != "date") {
-            if (strtoupper($groupheader) != strtoupper($pivot)) {
-            /// Printing th eheader of the group
-
-                if ($tableisopen) {
-                    echo '</table>';
-                    echo '</center>';
-                    $tableisopen = 0;
+    /// if we're browsing for letter, looking for special characters not covered
+    ///     in the alphabet 
+        if ( $showentry and $hook == 'SPECIAL' ) {
+            $initial = $entry->concept[0];
+            for ($i = 0; $i < count($alphabet); $i++) {
+                $curletter = $alphabet[$i];
+                if ( $curletter == $initial ) {
+
+                    $showentry = 0;
+                    break;
                 }
-                $groupheader = $pivot;
-                echo '<p align="center"><STRONG><font size="4" color="#0000FF">' . $groupheader . '</font></STRONG></p>';
             }
-        }
-        if ( !$tableisopen ) {
-            echo '<center>';
-            echo '<table border="1" cellpadding="5" cellspacing="0" width="95%">';
-            $tableisopen = 1;
-        }
+        } 
 
-        echo '<tr>';
-        echo '<td width="25%" align="right" valign="top"><b>'. $entry->concept . ': </b></td>';
-        echo '<td width="75%">';
+    /// if we're browsing categories, looking for entries not categorised.
+        if ( $showentry and $mode == 'cat' and $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {
+            if ( record_exists("glossary_entries_categories", "entryid", $entry->id)) {
+                $showentry = 0;
+            } 
+        }
 
-        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("<nolink>$entry->definition</nolink>",$entry->format);
+        /// ok, if it's a valid entry.. Print it.
+        if ( $showentry ) {
+
+            if ( $currentpivot != strtoupper($pivot) ) {  
+
+                // print the group break if apply
+                if ( $printpivot )  {
+                    $currentpivot = strtoupper($pivot);
+                    if ( !$tableisopen ) {
+                        echo '<table align="center" width="95%" bgcolor="#FFFFFF" style="border-style: solid; border-width: 1px;">';
+                        $tableisopen = 1;
+                    }
+
+                    echo '<tr>';
+                    $pivottoshow = $currentpivot;
+                    if ( isset($entry->uid) ) {
+                    // printing the user icon if defined (only when browsing authors)
+                        echo '<td colspan="2" align="left" style="border-style: solid; border-width: 1px;">';
+                        $pivottoshow = $entry->uname;
+                    } else {
+                        echo '<td colspan="2" align="center" style="border-style: solid; border-width: 1px;">';
+                    }
+
+                    echo "<strong><i>$pivottoshow</i></strong>" ;
+                    echo '</td>';
+                    echo '</tr>';
+                }
+            }
 
-        echo '</tr>';
+            echo '<tr>';
+            echo '<td width="25%" align="right" valign="top"><b>'. $entry->concept . ': </b></td>';
+            echo '<td width="75%" style="border-style: solid; border-width: 1px;">';
+    
+            if ( $entry->attachment) {
+                glossary_print_entry_attachment($entry);
+            }
+            echo strip_tags($entry->definition);
+    
+            echo '<br><br></tr>';
+        }
     }
     if ($tableisopen) {
         echo '</table>';
-        echo '</center>';
     }
+    echo '<center><font size=-1>' . userdate(time()) . '</font></center>'
 ?>
diff --git a/mod/glossary/sql.php b/mod/glossary/sql.php
new file mode 100644 (file)
index 0000000..030029b
--- /dev/null
@@ -0,0 +1,202 @@
+<?php
+
+/**
+ * SQL.PHP
+ *    This file is include from view.php and print.php
+ * @version $Id$
+ * @copyright 2003 
+ **/
+
+/// Creating the SQL statements
+
+/// Pivot is the field that set the break by groups (category, initial, author name, etc)
+
+/// fullpivot indicate if the whole pivot should be compared agasint the db or just the first letter
+/// printpivot indicate if the pivot should be printed or not
+    $fullpivot = 1;
+    $printpivot = 1;
+
+    $userid = '';
+    if ( $USER->id ) {
+        $userid = "OR ge.userid = $USER->id";
+    }
+    switch ($tab) {
+    case GLOSSARY_CATEGORY_VIEW:
+        if ($hook == GLOSSARY_SHOW_ALL_CATEGORIES  ) { 
+
+            $sqlselect = "SELECT gec.id, gc.name pivot, ge.*";
+            $sqlfrom   = "FROM {$CFG->prefix}glossary_entries ge,
+                         {$CFG->prefix}glossary_entries_categories gec,
+                         {$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 $userid)";
+
+            if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
+                $sqlorderby = ' ORDER BY gc.name, ge.timecreated';
+            } else {
+                $sqlorderby = ' ORDER BY gc.name, ge.concept';
+            }
+
+        } elseif ($hook == GLOSSARY_SHOW_NOT_CATEGORISED ) { 
+
+            $printpivot = 0;
+            $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 $userid)";
+
+
+            $sqlorderby = ' ORDER BY concept';
+
+        } else {
+
+            $printpivot = 0;
+            $sqlselect  = "SELECT ce.id, c.name pivot, ge.*";
+            $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories ce, {$CFG->prefix}glossary_categories c";
+            $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 $userid)";
+
+            $sqlorderby = ' ORDER BY c.name, ge.concept';
+
+        }
+    break;
+    case GLOSSARY_AUTHOR_VIEW:
+
+        $where = '';
+        switch ($CFG->dbtype) {
+        case 'postgres7':
+            $usernametoshow = "u.firstname || ' ' || u.lastname";
+            if ( $sortkey == 'FIRSTNAME' ) {
+                $usernamefield = "u.firstname || ' ' || u.lastname";
+            } else {
+                $usernamefield = "u.lastname || ' ' || u.firstname";
+            }
+            $where = "AND substr(ucase($usernamefield),1," .  strlen($hook) . ") = '" . strtoupper($hook) . "'";
+        break;
+        case 'mysql':
+            $usernametoshow = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
+            if ( $sortkey == 'FIRSTNAME' ) {
+                $usernamefield = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
+            } else {
+                $usernamefield = "CONCAT(CONCAT(u.lastname,' '), u.firstname)";
+            }
+            $where = "AND left(ucase($usernamefield)," .  strlen($hook) . ") = '$hook'";
+        break;
+        }
+        if ( $hook == 'ALL' ) {
+            $where = '';
+        }
+
+        $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 $userid)
+                             $where AND 
+                             (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id)";
+        $sqlorderby = "ORDER BY $usernamefield $sortorder, ge.concept";
+    break;
+    case GLOSSARY_APPROVAL_VIEW:
+        $fullpivot = 0;
+        $printpivot = 0;
+
+        $where = '';
+        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) . ") = '$hook'";
+            break;
+            }
+        }
+
+        $sqlselect  = "SELECT ge.concept pivot, ge.*";
+        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
+        $sqlwhere   = "WHERE (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id) AND
+                             ge.approved = 0 $where";
+                             
+        if ( $sortkey ) {
+            $sqlorderby = "ORDER BY $sortkey $sortorder";
+        } else {
+            $sqlorderby = "ORDER BY ge.concept";
+        }
+    break;
+    case GLOSSARY_DATE_VIEW:
+    case GLOSSARY_STANDARD_VIEW:
+    default:
+        $sqlselect  = "SELECT ge.concept pivot, ge.*";
+        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
+
+        $where = '';
+        $fullpivot = 0;
+        if ($CFG->dbtype == "postgres7") {
+            $LIKE = "ILIKE";   // case-insensitive
+        } else {
+            $LIKE = "LIKE";
+        }
+
+        switch ( $mode ) {
+        case 'search': 
+            $printpivot = 0;
+            $where = "AND ( ge.concept $LIKE '%$hook%'";
+            if ( $fullsearch ) {
+                $where .= "OR ge.definition $LIKE '%$hook%')";
+            } else {
+                $where .= ")";
+            }
+        break;
+        
+        case 'term': 
+            $printpivot = 0;
+            $sqlfrom .= ", {$CFG->prefix}glossary_alias ga";
+            $where = "AND ge.id = ga.entryid AND                            
+                          (ge.concept = '$hook' OR ga.alias = '$hook' )
+                     ";
+        break;
+
+        case 'entry': 
+            $printpivot = 0;
+            $where = "AND ge.id = $hook";
+        break;
+
+        case 'letter': 
+            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) . ") = '$hook'";
+                break;
+                }
+            }
+        break;
+        }
+        
+        $sqlwhere   = "WHERE (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) AND
+                             (ge.approved != 0 $userid)
+                              $where";
+        switch ( $tab ) {
+        case GLOSSARY_DATE_VIEW: 
+            $sqlorderby = "ORDER BY $sortkey $sortorder";
+        break;
+        
+        case GLOSSARY_STANDARD_VIEW: 
+            $sqlorderby = "ORDER BY ge.concept";
+        default:
+        break;
+        }
+    break;
+    } 
+    $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
+    $sqllimit = '';
+    if ( $offset >= 0 ) {
+        $sqllimit = " LIMIT $offset, $entriesbypage";
+    }
+    $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
+
+?>
\ No newline at end of file
index 62626c2166b795d6fc49bf317baf2e78f8e89920..49adb9526dd3cb995f9f90e0971e92b85e487cf3 100644 (file)
@@ -48,7 +48,7 @@
     global $CFG, $THEME, $USER;
     
     if ( !$entriesbypage = $glossary->entbypage ) {
-        $entriesbypage = 10;
+        $entriesbypage = $CFG->glossary_entbypage;
     }
 
 /// setting the right fram for a "Continuous" glossary
         navmenu($course, $cm));
     
     echo '<p align="center"><font size="3"><b>' . stripslashes_safe($glossary->name);
-    if ($isuserframe ) {
+    if ( $isuserframe and $mode != 'search') {
     /// the "Print" icon
-        echo " <a title =\"". get_string("printerfriendly","glossary") . "\" target=\"_blank\" href=\"print.php?id=$cm->id&tab=$tab&mode=$mode&hook=$hook&sortkey=$sortkey&sortorder=$sortorder\">";
+        echo " <a title =\"". get_string("printerfriendly","glossary") . "\" target=\"_blank\" href=\"print.php?id=$cm->id&mode=$mode&hook=$hook&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\">";
         echo '<img border=0 src="print.gif"/></a>';
     }
     echo '</b></font></p>';
 
 /// Info box
     if ( $glossary->intro ) {
-        print_simple_box_start('center','70%');
+        echo '<table align="center" width="70%" bgcolor="#FFFFFF" class="generaltab"><tr><td>';
         echo format_text($glossary->intro);
         print_simple_box_end();
     }
 
 /// Search box
-    echo '<p>';
-    print_simple_box_start("center", "", $THEME->cellheading);
-    echo '<p>';
+//    echo '<p>';
+    echo '<table align="center" width="70%" bgcolor="' . $THEME->cellheading .'" class="generalbox"><tr><td align=center>';
+    
+    echo '<p align="center>"';
     echo '<form method="POST" action="view.php">';
     echo '<input type="submit" value="'.$strsearch.'" name="searchbutton"> ';
     echo '<input type="text" name="hook" size="20" value=""> ';
     break;
     }
     
-/// Creating the SQL statements
-
-/// Pivot is the field that set the break by groups (category, initial, author name, etc)
-
-/// fullpivot indicate if the whole pivot should be compared agasint the db or just the first letter
-/// printpivot indicate if the pivot should be printed or not
-    $fullpivot = 1;
-    $printpivot = 1;
-
-//    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  ) { 
-
-            $sqlselect = "SELECT gec.id, gc.name pivot, ge.*";
-            $sqlfrom   = "FROM {$CFG->prefix}glossary_entries ge,
-                         {$CFG->prefix}glossary_entries_categories gec,
-                         {$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 $userid)";
-
-            if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
-                $sqlorderby = ' ORDER BY gc.name, ge.timecreated';
-            } else {
-                $sqlorderby = ' ORDER BY gc.name, ge.concept';
-            }
-
-        } elseif ($hook == GLOSSARY_SHOW_NOT_CATEGORISED ) { 
-
-            $printpivot = 0;
-            $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 $userid)";
-
-
-            $sqlorderby = ' ORDER BY concept';
-
-        } else {
-
-            $printpivot = 0;
-            $sqlselect  = "SELECT ce.id, c.name pivot, ge.*";
-            $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories ce, {$CFG->prefix}glossary_categories c";
-            $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 $userid)";
-
-            $sqlorderby = ' ORDER BY c.name, ge.concept';
-
-        }
-        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
-        $sqllimit = " LIMIT $offset, $entriesbypage";
-        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
-    break;
-    case GLOSSARY_AUTHOR_VIEW:
-
-        $where = '';
-        switch ($CFG->dbtype) {
-        case 'postgres7':
-            $usernametoshow = "u.firstname || ' ' || u.lastname";
-            if ( $sortkey == 'FIRSTNAME' ) {
-                $usernamefield = "u.firstname || ' ' || u.lastname";
-            } else {
-                $usernamefield = "u.lastname || ' ' || u.firstname";
-            }
-            $where = "AND substr(ucase($usernamefield),1," .  strlen($hook) . ") = '" . strtoupper($hook) . "'";
-        break;
-        case 'mysql':
-            $usernametoshow = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
-            if ( $sortkey == 'FIRSTNAME' ) {
-                $usernamefield = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
-            } else {
-                $usernamefield = "CONCAT(CONCAT(u.lastname,' '), u.firstname)";
-            }
-            $where = "AND left(ucase($usernamefield)," .  strlen($hook) . ") = '$hook'";
-        break;
-        }
-        if ( $hook == 'ALL' ) {
-            $where = '';
-        }
-
-        $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 $userid)
-                             $where AND 
-                             (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id)";
-        $sqlorderby = "ORDER BY $usernamefield $sortorder, ge.concept";
-
-        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
-        $sqllimit = " LIMIT $offset, $entriesbypage";
-        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
-    break;
-    case GLOSSARY_APPROVAL_VIEW:
-        $fullpivot = 0;
-        $printpivot = 0;
-
-        $where = '';
-        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) . ") = '$hook'";
-            break;
-            }
-        }
-
-        $sqlselect  = "SELECT ge.concept pivot, ge.*";
-        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
-        $sqlwhere   = "WHERE (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id) AND
-                             ge.approved = 0 $where";
-                             
-        if ( $sortkey ) {
-            $sqlorderby = "ORDER BY $sortkey $sortorder";
-        } else {
-            $sqlorderby = "ORDER BY ge.concept";
-        }
-        
-        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
-        $sqllimit   = " LIMIT $offset, $entriesbypage";
-        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
-    break;
-    case GLOSSARY_DATE_VIEW:
-    case GLOSSARY_STANDARD_VIEW:
-    default:
-        $sqlselect  = "SELECT ge.concept pivot, ge.*";
-        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
-
-        $where = '';
-        $fullpivot = 0;
-        if ($CFG->dbtype == "postgres7") {
-            $LIKE = "ILIKE";   // case-insensitive
-        } else {
-            $LIKE = "LIKE";
-        }
-
-        switch ( $mode ) {
-        case 'search': 
-            $printpivot = 0;
-            $where = "AND ( ge.concept $LIKE '%$hook%'";
-            if ( $fullsearch ) {
-                $where .= "OR ge.definition $LIKE '%$hook%')";
-            } else {
-                $where .= ")";
-            }
-        break;
-        
-        case 'term': 
-            $printpivot = 0;
-            $sqlfrom .= ", {$CFG->prefix}glossary_alias ga";
-            $where = "AND ge.id = ga.entryid AND                            
-                          (ge.concept = '$hook' OR ga.alias = '$hook' )
-                     ";
-//            $where = "AND ge.id = ga.entryid AND (
-//                           (ge.casesensitive != 0 and ( ge.concept LIKE BINARY '$hook' OR ga.alias LIKE BINARY '$hook' ) ) or
-//                           (ge.casesensitive = 0 and ( ucase(ge.concept) = ucase('$hook') OR ucase(ga.alias) = ucase('$hook') ) )
-//                       )";
-        break;
-
-        case 'entry': 
-            $printpivot = 0;
-            $where = "AND ge.id = $hook";
-        break;
-
-        case 'letter': 
-            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) . ") = '$hook'";
-                break;
-                }
-            }
-        break;
-        }
-        
-        $sqlwhere   = "WHERE (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) AND
-                             (ge.approved != 0 $userid)
-                              $where";
-        switch ( $tab ) {
-        case GLOSSARY_DATE_VIEW: 
-            $sqlorderby = "ORDER BY $sortkey $sortorder";
-        break;
-        
-        case GLOSSARY_STANDARD_VIEW: 
-            $sqlorderby = "ORDER BY ge.concept";
-        default:
-        break;
-        }
-
-        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
-        $sqllimit   = " LIMIT $offset, $entriesbypage";
-        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
-
-    break;
-    } 
+    include_once("sql.php");
 
 /// printing the entries
     $entriesshown = 0;
     }
     if ($allentries) {
         /// printing the paging links
-        $paging = '';
+        $paging = get_string("allentries","glossary");
+        if ( $offset < 0 ) {
+            $paging = '<strong>' . $paging . '</strong>';
+        } else {
+            $paging = "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=-1\">" . $paging . '</a>';
+        }
         if ($count > $entriesbypage ) {
             for ($i = 0; ($i*$entriesbypage) < $count  ; $i++   ) {
                 if ( $paging != '' ) {
-                    if ($i % 20 == 0) {
+                    if ($i % 20 == 0 and $i) {
                         $paging .= '<br>';
                     } else {
                         $paging .= ' | ';
                     }
                 }
+                $pagenumber = (string) ($i + 1 );
                 if ($offset / $entriesbypage == $i) {
-                    $paging .= '<strong>' . ($i + 1 ) . '</strong>';
+                    $paging .= '<strong>' . $pagenumber . '</strong>';
                 } else {
-                    $paging .= "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=" . ($i*$entriesbypage) . "\">" . ($i+1) . '</a>';
+                    $paging .= "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=" . ($i*$entriesbypage) . "\">" . $pagenumber . '</a>';
                 }
             }
             $paging  = "<font size=1><center>" . get_string ("jumpto") . " $paging</center></font>";
+        } else {
+            $paging = '';
         }
         echo $paging;