Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- Improved printer-friendly version

- Cosmetic change in the main view of a glossary.
  • Loading branch information...
commit 4f3e59c3a2f026e232bbf2482b22f36f3293b997 1 parent b694b2b
authored November 18, 2003
276  mod/glossary/print.php
@@ -2,15 +2,13 @@
2 2
 
3 3
     require_once("../../config.php");
4 4
     require_once("lib.php");
5  
-    global $CFG;
6 5
     
7 6
     require_variable($id);                         // Course Module ID
8  
-    require_variable($mode,"letter"); // format to show the entries
9  
-    optional_variable($sortkey,"UPDATE");          // Sorting key if TAB = GLOSSARY_DATE_VIEW
10  
-    optional_variable($sortorder,"asc");           // Sorting order if TAB = GLOSSARY_DATE_VIEW
11  
-    optional_variable($hook,"ALL");          
12  
-    optional_variable($eid);          
13  
-    optional_variable($search);
  7
+    require_variable($mode,"letter");              // mode to show the entries
  8
+    optional_variable($hook,"ALL");                // what to show
  9
+    optional_variable($sortkey,"UPDATE");          // Sorting key 
  10
+    optional_variable($sortorder,"asc");           // Sorting order 
  11
+    optional_variable($offset);                    // number of entries to bypass
14 12
 
15 13
     if (! $cm = get_record("course_modules", "id", $id)) {
16 14
         error("Course Module ID was incorrect");
@@ -24,6 +22,11 @@
24 22
         error("Course module is incorrect");
25 23
     } 
26 24
     
  25
+    global $CFG;
  26
+    if ( !$entriesbypage = $glossary->entbypage ) {
  27
+        $entriesbypage = $CFG->glossary_entbypage;
  28
+    }
  29
+
27 30
     if ($course->category) {
28 31
         require_login($course->id);    
29 32
         if (isguest()) {
@@ -31,141 +34,184 @@
31 34
         } 
32 35
     }
33 36
 
34  
-    if ( $eid ) {
35  
-        $mode = 'entry';
  37
+/// stablishing flag variables
  38
+    if ( $sortorder = strtolower($sortorder) ) {
  39
+        if ($sortorder != 'asc' and $sortorder != 'desc') {
  40
+            $sortorder = '';
  41
+        }
36 42
     }
37  
-/// Generating the SQL based on the format to show
38  
-    switch ($mode) {
39  
-    case "cat":
40  
-        $where = '';
41  
-        if ($hook) {
42  
-            if ( $hook != GLOSSARY_SHOW_ALL_CATEGORIES and $hook != GLOSSARY_SHOW_NOT_CATEGORISED ) {
43  
-                    $where = 'and c.id = ' . $hook;
44  
-            }
  43
+    if ( $sortkey = strtoupper($sortkey) ) {
  44
+        if ($sortkey != 'CREATION' and 
  45
+            $sortkey != 'UPDATE' and 
  46
+            $sortkey != 'FIRSTNAME' and 
  47
+            $sortkey != 'LASTNAME'
  48
+            ) {
  49
+            $sortkey = '';
45 50
         }
46  
-        $entries = get_records_sql("SELECT ec.id, c.name pivot, e.*
47  
-                                    FROM {$CFG->prefix}glossary_entries e,
48  
-                                         {$CFG->prefix}glossary_entries_categories ec,
49  
-                                         {$CFG->prefix}glossary_categories as c
50  
-                                    WHERE e.id = ec.entryid AND ec.categoryid = c.id AND
51  
-                                          (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id)
52  
-                                          AND e.approved != 0 $where
53  
-                                    ORDER BY c.name, e.concept");
  51
+    }
54 52
 
  53
+    switch ( $mode = strtolower($mode) ) {
  54
+    case 'entry':  /// Looking for a certain entry id
  55
+        $tab = GLOSSARY_STANDARD_VIEW;
55 56
     break;
56  
-
57  
-    case "date":
58  
-    //// Valid sorting values
59  
-        switch ($sortkey) {
60  
-        case 'CREATION':
61  
-            $sortkey = 'timecreated';
62  
-        break;
63  
-
64  
-        case 'UPDATE':
65  
-        default:
66  
-            $sortkey = 'timemodified';
67  
-        break;
68  
-        }
69  
-        if ($sortorder != 'asc' and $sortorder != 'desc') {
70  
-            $sortorder = 'asc';
  57
+    
  58
+    case 'cat':    /// Looking for a certain cat
  59
+        $tab = GLOSSARY_CATEGORY_VIEW;
  60
+        if ( $hook > 0 ) {
  61
+            $category = get_record("glossary_categories","id",$hook);
71 62
         }
  63
+    break;
72 64
 
73  
-        $entries = get_records_sql("SELECT e.timemodified pivot, e.*
74  
-                                    FROM {$CFG->prefix}glossary_entries e
75  
-                                    WHERE (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id)
76  
-                                          AND e.approved != 0
77  
-                                    ORDER BY e.$sortkey $sortorder");
  65
+    case 'approval':    /// Looking for entries waiting for approval
  66
+        $tab = GLOSSARY_APPROVAL_VIEW;
  67
+        if ( !$hook and !$sortkey and !$sortorder) {
  68
+            $hook = 'ALL';
  69
+        }
  70
+    break;
78 71
 
  72
+    case 'term':   /// Looking for entries that include certain term in its concept, definition or aliases
  73
+        $tab = GLOSSARY_STANDARD_VIEW;
79 74
     break;
80  
-    case "letter":
81  
-    default:
82  
-        switch ($CFG->dbtype) {
83  
-        case "postgres7":
84  
-            $pivot = "substring(e.concept, 1,1)";
85  
-        break;
86  
-
87  
-        case "mysql":
88  
-            $pivot = "left(e.concept,1)";
89  
-        break;
90  
-        default:
91  
-            $pivot = "e.concept";
92  
-        break;
93  
-        }
94 75
 
95  
-        if ( $hook ) {
96  
-            if ($hook != 'ALL' and $hook != 'SPECIAL') {
97  
-                switch ($CFG->dbtype) {
98  
-                case 'postgres7':
99  
-                    $where = 'and substr(ucase(concept),1,' .  strlen($hook) . ') = \'' . strtoupper($hook) . '\'';
100  
-                break;
101  
-                case 'mysql':
102  
-                    $where = 'and left(ucase(concept),' .  strlen($hook) . ") = '" . strtoupper($hook) . "'";
103  
-                break;
104  
-                default:
105  
-                    $where = '';
106  
-                }
107  
-            }
108  
-        } elseif ($eid) {
109  
-            $where = " and e.id = $eid";
  76
+    case 'date':
  77
+        $tab = GLOSSARY_DATE_VIEW;
  78
+        if ( !$sortkey ) {
  79
+            $sortkey = 'UPDATE';
  80
+        } 
  81
+        if ( !$sortorder ) {
  82
+            $sortorder = 'desc';
  83
+        }
  84
+    break;
  85
+    
  86
+    case 'author':  /// Looking for entries, browsed by author
  87
+        $tab = GLOSSARY_AUTHOR_VIEW;
  88
+        if ( !$hook ) {
  89
+            $hook = 'ALL';
  90
+        } 
  91
+        if ( !$sortkey ) {
  92
+            $sortkey = 'FIRSTNAME';
  93
+        } 
  94
+        if ( !$sortorder ) {
  95
+            $sortorder = 'asc';
110 96
         }
111  
-
112  
-        $entries = get_records_sql("SELECT e.id, $pivot pivot, e.*
113  
-                                    FROM {$CFG->prefix}glossary_entries e
114  
-                                    WHERE (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id)
115  
-                                          AND e.approved != 0 $where
116  
-                                    ORDER BY e.concept $sortorder");
117 97
     break;
118  
-    } 
119 98
 
120  
-    echo '<p><STRONG>' . get_string("course") . ': <i>' . $course->fullname . '</i><br />';
121  
-    echo get_string("modulename","glossary") . ': <i>' . $glossary->name . '</i></STRONG></p>';
  99
+    case 'letter':  /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
  100
+    default:
  101
+        $tab = GLOSSARY_STANDARD_VIEW;
  102
+        if ( !$hook ) {
  103
+            $hook = 'ALL';  
  104
+        } 
  105
+    break;
  106
+    }  
122 107
 
123  
-    if ( !$entries ) {
124  
-        echo get_string("noentries","glossary");
125  
-        exit;
  108
+    include_once("sql.php");
  109
+    
  110
+    $entriesshown = 0;
  111
+    $currentpivot = '';
  112
+    if ( $hook == 'SPECIAL' ) {
  113
+        $alphabet = explode(",", get_string("alphabet"));
126 114
     }
127  
-                                    
128  
-    $groupheader = '';
129 115
     $tableisopen = 0;
130  
-    foreach ($entries as $entry) {
  116
+
  117
+    $site = get_record("course","id",1);
  118
+    echo '<p align="right"><font size=-1>' . userdate(time()) . '</font></p>';
  119
+    echo '<strong>' . $site->fullname . '</strong><br>';
  120
+    echo get_string("course") . ': <strong>' . $course->fullname . '</strong><br \>';
  121
+    echo get_string("modulename","glossary") . ': <strong>' . $glossary->name . '</strong><p>';
  122
+    
  123
+    foreach ($allentries as $entry) {
  124
+    /// Setting the pivot for the current entry
131 125
         $pivot = $entry->pivot;
132  
-        if ( $CFG->dbtype != "postgres7" and $CFG->dbtype != "mysql" and $mode != "cat") {
  126
+        if ( !$fullpivot ) {
133 127
             $pivot = $pivot[0];
134  
-        }
  128
+        }            
  129
+        
  130
+    /// 
  131
+    /// Validating special cases not covered by the SQL statement
  132
+    /// 
  133
+
  134
+    /// if we're browsing by alphabet and the current concept does not begin with
  135
+    ///     the letter we are look for.
  136
+        $showentry = 1;
  137
+        if ( $mode == 'letter' and $hook != 'SPECIAL' and $hook != 'ALL' ) {
  138
+            if ( substr($entry->concept, 0, strlen($hook)) != $hook ) {
  139
+                $showentry = 0;
  140
+            }
  141
+        } 
135 142
         
136  
-        if ($mode != "date") {
137  
-            if (strtoupper($groupheader) != strtoupper($pivot)) {
138  
-            /// Printing th eheader of the group
139  
-
140  
-                if ($tableisopen) {
141  
-                    echo '</table>';
142  
-                    echo '</center>';
143  
-                    $tableisopen = 0;
  143
+    /// if we're browsing for letter, looking for special characters not covered
  144
+    ///     in the alphabet 
  145
+        if ( $showentry and $hook == 'SPECIAL' ) {
  146
+            $initial = $entry->concept[0];
  147
+            for ($i = 0; $i < count($alphabet); $i++) {
  148
+                $curletter = $alphabet[$i];
  149
+                if ( $curletter == $initial ) {
  150
+
  151
+                    $showentry = 0;
  152
+                    break;
144 153
                 }
145  
-                $groupheader = $pivot;
146  
-                echo '<p align="center"><STRONG><font size="4" color="#0000FF">' . $groupheader . '</font></STRONG></p>';
147 154
             }
148  
-        }
149  
-        if ( !$tableisopen ) {
150  
-            echo '<center>';
151  
-            echo '<table border="1" cellpadding="5" cellspacing="0" width="95%">';
152  
-            $tableisopen = 1;
153  
-        }
  155
+        } 
154 156
 
155  
-        echo '<tr>';
156  
-        echo '<td width="25%" align="right" valign="top"><b>'. $entry->concept . ': </b></td>';
157  
-        echo '<td width="75%">';
  157
+    /// if we're browsing categories, looking for entries not categorised.
  158
+        if ( $showentry and $mode == 'cat' and $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {
  159
+            if ( record_exists("glossary_entries_categories", "entryid", $entry->id)) {
  160
+                $showentry = 0;
  161
+            } 
  162
+        }
158 163
 
159  
-        if ( $entry->attachment) {
160  
-            glossary_print_entry_attachment($entry);
  164
+    /// if the entry is not approved, deal with it based on the current view and
  165
+    ///     user.
  166
+        if ( $showentry and $mode != 'approval' ) {
  167
+            if ( !$entry->approved and isteacher($course->id, $entry->userid) ) {
  168
+                $showentry = 0;
  169
+            }            
161 170
         }
162 171
 
163  
-        echo format_text("<nolink>$entry->definition</nolink>",$entry->format);
  172
+        /// ok, if it's a valid entry.. Print it.
  173
+        if ( $showentry ) {
  174
+
  175
+            if ( $currentpivot != strtoupper($pivot) ) {  
  176
+
  177
+                // print the group break if apply
  178
+                if ( $printpivot )  {
  179
+                    $currentpivot = strtoupper($pivot);
  180
+                    if ( !$tableisopen ) {
  181
+                        echo '<table align="center" width="95%" bgcolor="#FFFFFF" style="border-style: solid; border-width: 1px;">';
  182
+                        $tableisopen = 1;
  183
+                    }
  184
+
  185
+                    echo '<tr>';
  186
+                    $pivottoshow = $currentpivot;
  187
+                    if ( isset($entry->uid) ) {
  188
+                    // printing the user icon if defined (only when browsing authors)
  189
+                        echo '<td colspan="2" align="left" style="border-style: solid; border-width: 1px;">';
  190
+                        $pivottoshow = $entry->uname;
  191
+                    } else {
  192
+                        echo '<td colspan="2" align="center" style="border-style: solid; border-width: 1px;">';
  193
+                    }
  194
+
  195
+                    echo "<strong><i>$pivottoshow</i></strong>" ;
  196
+                    echo '</td>';
  197
+                    echo '</tr>';
  198
+                }
  199
+            }
164 200
 
165  
-        echo '</tr>';
  201
+            echo '<tr>';
  202
+            echo '<td width="25%" align="right" valign="top"><b>'. $entry->concept . ': </b></td>';
  203
+            echo '<td width="75%" style="border-style: solid; border-width: 1px;">';
  204
+    
  205
+            if ( $entry->attachment) {
  206
+                glossary_print_entry_attachment($entry);
  207
+            }
  208
+            echo strip_tags($entry->definition);
  209
+    
  210
+            echo '<br><br></tr>';
  211
+        }
166 212
     }
167 213
     if ($tableisopen) {
168 214
         echo '</table>';
169  
-        echo '</center>';
170 215
     }
  216
+    echo '<center><font size=-1>' . userdate(time()) . '</font></center>'
171 217
 ?>
202  mod/glossary/sql.php
... ...
@@ -0,0 +1,202 @@
  1
+<?php
  2
+
  3
+/**
  4
+ * SQL.PHP
  5
+ *    This file is include from view.php and print.php
  6
+ * @version $Id$
  7
+ * @copyright 2003 
  8
+ **/
  9
+
  10
+/// Creating the SQL statements
  11
+
  12
+/// Pivot is the field that set the break by groups (category, initial, author name, etc)
  13
+
  14
+/// fullpivot indicate if the whole pivot should be compared agasint the db or just the first letter
  15
+/// printpivot indicate if the pivot should be printed or not
  16
+    $fullpivot = 1;
  17
+    $printpivot = 1;
  18
+
  19
+    $userid = '';
  20
+    if ( $USER->id ) {
  21
+        $userid = "OR ge.userid = $USER->id";
  22
+    }
  23
+    switch ($tab) {
  24
+    case GLOSSARY_CATEGORY_VIEW:
  25
+        if ($hook == GLOSSARY_SHOW_ALL_CATEGORIES  ) { 
  26
+
  27
+            $sqlselect = "SELECT gec.id, gc.name pivot, ge.*";
  28
+            $sqlfrom   = "FROM {$CFG->prefix}glossary_entries ge,
  29
+                         {$CFG->prefix}glossary_entries_categories gec,
  30
+                         {$CFG->prefix}glossary_categories gc";
  31
+            $sqlwhere  = "WHERE (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND
  32
+                          ge.id = gec.entryid AND gc.id = gec.categoryid AND
  33
+                          (ge.approved != 0 $userid)";
  34
+
  35
+            if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
  36
+                $sqlorderby = ' ORDER BY gc.name, ge.timecreated';
  37
+            } else {
  38
+                $sqlorderby = ' ORDER BY gc.name, ge.concept';
  39
+            }
  40
+
  41
+        } elseif ($hook == GLOSSARY_SHOW_NOT_CATEGORISED ) { 
  42
+
  43
+            $printpivot = 0;
  44
+            $sqlselect = "SELECT concept pivot, ge.*";
  45
+            $sqlfrom   = "FROM {$CFG->prefix}glossary_entries ge";
  46
+            $sqlwhere  = "WHERE (glossaryid = '$glossary->id' OR sourceglossaryid = '$glossary->id') AND
  47
+                          (ge.approved != 0 $userid)";
  48
+
  49
+
  50
+            $sqlorderby = ' ORDER BY concept';
  51
+
  52
+        } else {
  53
+
  54
+            $printpivot = 0;
  55
+            $sqlselect  = "SELECT ce.id, c.name pivot, ge.*";
  56
+            $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories ce, {$CFG->prefix}glossary_categories c";
  57
+            $sqlwhere   = "WHERE ge.id = ce.entryid AND ce.categoryid = $hook AND
  58
+                                 ce.categoryid = c.id AND ge.approved != 0 AND
  59
+                                 (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id) AND
  60
+                          (ge.approved != 0 $userid)";
  61
+
  62
+            $sqlorderby = ' ORDER BY c.name, ge.concept';
  63
+
  64
+        }
  65
+    break;
  66
+    case GLOSSARY_AUTHOR_VIEW:
  67
+
  68
+        $where = '';
  69
+        switch ($CFG->dbtype) {
  70
+        case 'postgres7':
  71
+            $usernametoshow = "u.firstname || ' ' || u.lastname";
  72
+            if ( $sortkey == 'FIRSTNAME' ) {
  73
+                $usernamefield = "u.firstname || ' ' || u.lastname";
  74
+            } else {
  75
+                $usernamefield = "u.lastname || ' ' || u.firstname";
  76
+            }
  77
+            $where = "AND substr(ucase($usernamefield),1," .  strlen($hook) . ") = '" . strtoupper($hook) . "'";
  78
+        break;
  79
+        case 'mysql':
  80
+            $usernametoshow = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
  81
+            if ( $sortkey == 'FIRSTNAME' ) {
  82
+                $usernamefield = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
  83
+            } else {
  84
+                $usernamefield = "CONCAT(CONCAT(u.lastname,' '), u.firstname)";
  85
+            }
  86
+            $where = "AND left(ucase($usernamefield)," .  strlen($hook) . ") = '$hook'";
  87
+        break;
  88
+        }
  89
+        if ( $hook == 'ALL' ) {
  90
+            $where = '';
  91
+        }
  92
+
  93
+        $sqlselect  = "SELECT ge.id, $usernamefield pivot, $usernametoshow uname, u.id uid, ge.*";
  94
+        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}user u";
  95
+        $sqlwhere   = "WHERE ge.userid = u.id  AND
  96
+                             (ge.approved != 0 $userid)
  97
+                             $where AND 
  98
+                             (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id)";
  99
+        $sqlorderby = "ORDER BY $usernamefield $sortorder, ge.concept";
  100
+    break;
  101
+    case GLOSSARY_APPROVAL_VIEW:
  102
+        $fullpivot = 0;
  103
+        $printpivot = 0;
  104
+
  105
+        $where = '';
  106
+        if ($hook != 'ALL' and $hook != 'SPECIAL') {
  107
+            switch ($CFG->dbtype) {
  108
+            case 'postgres7':
  109
+                $where = 'AND substr(ucase(concept),1,' .  strlen($hook) . ') = \'' . strtoupper($hook) . '\'';
  110
+            break;
  111
+            case 'mysql':
  112
+                $where = 'AND left(ucase(concept),' .  strlen($hook) . ") = '$hook'";
  113
+            break;
  114
+            }
  115
+        }
  116
+
  117
+        $sqlselect  = "SELECT ge.concept pivot, ge.*";
  118
+        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
  119
+        $sqlwhere   = "WHERE (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id) AND
  120
+                             ge.approved = 0 $where";
  121
+                             
  122
+        if ( $sortkey ) {
  123
+            $sqlorderby = "ORDER BY $sortkey $sortorder";
  124
+        } else {
  125
+            $sqlorderby = "ORDER BY ge.concept";
  126
+        }
  127
+    break;
  128
+    case GLOSSARY_DATE_VIEW:
  129
+    case GLOSSARY_STANDARD_VIEW:
  130
+    default:
  131
+        $sqlselect  = "SELECT ge.concept pivot, ge.*";
  132
+        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
  133
+
  134
+        $where = '';
  135
+        $fullpivot = 0;
  136
+        if ($CFG->dbtype == "postgres7") {
  137
+            $LIKE = "ILIKE";   // case-insensitive
  138
+        } else {
  139
+            $LIKE = "LIKE";
  140
+        }
  141
+
  142
+        switch ( $mode ) {
  143
+        case 'search': 
  144
+            $printpivot = 0;
  145
+            $where = "AND ( ge.concept $LIKE '%$hook%'";
  146
+            if ( $fullsearch ) {
  147
+                $where .= "OR ge.definition $LIKE '%$hook%')";
  148
+            } else {
  149
+                $where .= ")";
  150
+            }
  151
+        break;
  152
+        
  153
+        case 'term': 
  154
+            $printpivot = 0;
  155
+            $sqlfrom .= ", {$CFG->prefix}glossary_alias ga";
  156
+            $where = "AND ge.id = ga.entryid AND                            
  157
+                          (ge.concept = '$hook' OR ga.alias = '$hook' )
  158
+                     ";
  159
+        break;
  160
+
  161
+        case 'entry': 
  162
+            $printpivot = 0;
  163
+            $where = "AND ge.id = $hook";
  164
+        break;
  165
+
  166
+        case 'letter': 
  167
+            if ($hook != 'ALL' and $hook != 'SPECIAL') {
  168
+                switch ($CFG->dbtype) {
  169
+                case 'postgres7':
  170
+                    $where = 'AND substr(ucase(concept),1,' .  strlen($hook) . ') = \'' . strtoupper($hook) . '\'';
  171
+                break;
  172
+                case 'mysql':
  173
+                    $where = 'AND left(ucase(concept),' .  strlen($hook) . ") = '$hook'";
  174
+                break;
  175
+                }
  176
+            }
  177
+        break;
  178
+        }
  179
+        
  180
+        $sqlwhere   = "WHERE (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) AND
  181
+                             (ge.approved != 0 $userid)
  182
+                              $where";
  183
+        switch ( $tab ) {
  184
+        case GLOSSARY_DATE_VIEW: 
  185
+            $sqlorderby = "ORDER BY $sortkey $sortorder";
  186
+        break;
  187
+        
  188
+        case GLOSSARY_STANDARD_VIEW: 
  189
+            $sqlorderby = "ORDER BY ge.concept";
  190
+        default:
  191
+        break;
  192
+        }
  193
+    break;
  194
+    } 
  195
+    $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
  196
+    $sqllimit = '';
  197
+    if ( $offset >= 0 ) {
  198
+        $sqllimit = " LIMIT $offset, $entriesbypage";
  199
+    }
  200
+    $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
  201
+
  202
+?>
239  mod/glossary/view.php
@@ -48,7 +48,7 @@
48 48
     global $CFG, $THEME, $USER;
49 49
     
50 50
     if ( !$entriesbypage = $glossary->entbypage ) {
51  
-        $entriesbypage = 10;
  51
+        $entriesbypage = $CFG->glossary_entbypage;
52 52
     }
53 53
 
54 54
 /// setting the right fram for a "Continuous" glossary
@@ -178,24 +178,25 @@
178 178
         navmenu($course, $cm));
179 179
     
180 180
     echo '<p align="center"><font size="3"><b>' . stripslashes_safe($glossary->name);
181  
-    if ($isuserframe ) {
  181
+    if ( $isuserframe and $mode != 'search') {
182 182
     /// the "Print" icon
183  
-        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\">";
  183
+        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\">";
184 184
         echo '<img border=0 src="print.gif"/></a>';
185 185
     }
186 186
     echo '</b></font></p>';
187 187
 
188 188
 /// Info box
189 189
     if ( $glossary->intro ) {
190  
-        print_simple_box_start('center','70%');
  190
+        echo '<table align="center" width="70%" bgcolor="#FFFFFF" class="generaltab"><tr><td>';
191 191
         echo format_text($glossary->intro);
192 192
         print_simple_box_end();
193 193
     }
194 194
 
195 195
 /// Search box
196  
-    echo '<p>';
197  
-    print_simple_box_start("center", "", $THEME->cellheading);
198  
-    echo '<p>';
  196
+//    echo '<p>';
  197
+    echo '<table align="center" width="70%" bgcolor="' . $THEME->cellheading .'" class="generalbox"><tr><td align=center>';
  198
+    
  199
+    echo '<p align="center>"';
199 200
     echo '<form method="POST" action="view.php">';
200 201
     echo '<input type="submit" value="'.$strsearch.'" name="searchbutton"> ';
201 202
     echo '<input type="text" name="hook" size="20" value=""> ';
@@ -220,213 +221,7 @@
220 221
     break;
221 222
     }
222 223
     
223  
-/// Creating the SQL statements
224  
-
225  
-/// Pivot is the field that set the break by groups (category, initial, author name, etc)
226  
-
227  
-/// fullpivot indicate if the whole pivot should be compared agasint the db or just the first letter
228  
-/// printpivot indicate if the pivot should be printed or not
229  
-    $fullpivot = 1;
230  
-    $printpivot = 1;
231  
-
232  
-//    global $db;
233  
-//    $db->debug = true;
234  
-    $userid = '';
235  
-    if ( $USER->id ) {
236  
-        $userid = "OR ge.userid = $USER->id";
237  
-    }
238  
-    switch ($tab) {
239  
-    case GLOSSARY_CATEGORY_VIEW:
240  
-        if ($hook == GLOSSARY_SHOW_ALL_CATEGORIES  ) { 
241  
-
242  
-            $sqlselect = "SELECT gec.id, gc.name pivot, ge.*";
243  
-            $sqlfrom   = "FROM {$CFG->prefix}glossary_entries ge,
244  
-                         {$CFG->prefix}glossary_entries_categories gec,
245  
-                         {$CFG->prefix}glossary_categories gc";
246  
-            $sqlwhere  = "WHERE (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND
247  
-                          ge.id = gec.entryid AND gc.id = gec.categoryid AND
248  
-                          (ge.approved != 0 $userid)";
249  
-
250  
-            if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
251  
-                $sqlorderby = ' ORDER BY gc.name, ge.timecreated';
252  
-            } else {
253  
-                $sqlorderby = ' ORDER BY gc.name, ge.concept';
254  
-            }
255  
-
256  
-        } elseif ($hook == GLOSSARY_SHOW_NOT_CATEGORISED ) { 
257  
-
258  
-            $printpivot = 0;
259  
-            $sqlselect = "SELECT concept pivot, ge.*";
260  
-            $sqlfrom   = "FROM {$CFG->prefix}glossary_entries ge";
261  
-            $sqlwhere  = "WHERE (glossaryid = '$glossary->id' OR sourceglossaryid = '$glossary->id') AND
262  
-                          (ge.approved != 0 $userid)";
263  
-
264  
-
265  
-            $sqlorderby = ' ORDER BY concept';
266  
-
267  
-        } else {
268  
-
269  
-            $printpivot = 0;
270  
-            $sqlselect  = "SELECT ce.id, c.name pivot, ge.*";
271  
-            $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories ce, {$CFG->prefix}glossary_categories c";
272  
-            $sqlwhere   = "WHERE ge.id = ce.entryid AND ce.categoryid = $hook AND
273  
-                                 ce.categoryid = c.id AND ge.approved != 0 AND
274  
-                                 (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id) AND
275  
-                          (ge.approved != 0 $userid)";
276  
-
277  
-            $sqlorderby = ' ORDER BY c.name, ge.concept';
278  
-
279  
-        }
280  
-        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
281  
-        $sqllimit = " LIMIT $offset, $entriesbypage";
282  
-        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
283  
-    break;
284  
-    case GLOSSARY_AUTHOR_VIEW:
285  
-
286  
-        $where = '';
287  
-        switch ($CFG->dbtype) {
288  
-        case 'postgres7':
289  
-            $usernametoshow = "u.firstname || ' ' || u.lastname";
290  
-            if ( $sortkey == 'FIRSTNAME' ) {
291  
-                $usernamefield = "u.firstname || ' ' || u.lastname";
292  
-            } else {
293  
-                $usernamefield = "u.lastname || ' ' || u.firstname";
294  
-            }
295  
-            $where = "AND substr(ucase($usernamefield),1," .  strlen($hook) . ") = '" . strtoupper($hook) . "'";
296  
-        break;
297  
-        case 'mysql':
298  
-            $usernametoshow = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
299  
-            if ( $sortkey == 'FIRSTNAME' ) {
300  
-                $usernamefield = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
301  
-            } else {
302  
-                $usernamefield = "CONCAT(CONCAT(u.lastname,' '), u.firstname)";
303  
-            }
304  
-            $where = "AND left(ucase($usernamefield)," .  strlen($hook) . ") = '$hook'";
305  
-        break;
306  
-        }
307  
-        if ( $hook == 'ALL' ) {
308  
-            $where = '';
309  
-        }
310  
-
311  
-        $sqlselect  = "SELECT ge.id, $usernamefield pivot, $usernametoshow uname, u.id uid, ge.*";
312  
-        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}user u";
313  
-        $sqlwhere   = "WHERE ge.userid = u.id  AND
314  
-                             (ge.approved != 0 $userid)
315  
-                             $where AND 
316  
-                             (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id)";
317  
-        $sqlorderby = "ORDER BY $usernamefield $sortorder, ge.concept";
318  
-
319  
-        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
320  
-        $sqllimit = " LIMIT $offset, $entriesbypage";
321  
-        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
322  
-    break;
323  
-    case GLOSSARY_APPROVAL_VIEW:
324  
-        $fullpivot = 0;
325  
-        $printpivot = 0;
326  
-
327  
-        $where = '';
328  
-        if ($hook != 'ALL' and $hook != 'SPECIAL') {
329  
-            switch ($CFG->dbtype) {
330  
-            case 'postgres7':
331  
-                $where = 'AND substr(ucase(concept),1,' .  strlen($hook) . ') = \'' . strtoupper($hook) . '\'';
332  
-            break;
333  
-            case 'mysql':
334  
-                $where = 'AND left(ucase(concept),' .  strlen($hook) . ") = '$hook'";
335  
-            break;
336  
-            }
337  
-        }
338  
-
339  
-        $sqlselect  = "SELECT ge.concept pivot, ge.*";
340  
-        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
341  
-        $sqlwhere   = "WHERE (ge.glossaryid = $glossary->id OR ge.sourceglossaryid = $glossary->id) AND
342  
-                             ge.approved = 0 $where";
343  
-                             
344  
-        if ( $sortkey ) {
345  
-            $sqlorderby = "ORDER BY $sortkey $sortorder";
346  
-        } else {
347  
-            $sqlorderby = "ORDER BY ge.concept";
348  
-        }
349  
-        
350  
-        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
351  
-        $sqllimit   = " LIMIT $offset, $entriesbypage";
352  
-        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
353  
-    break;
354  
-    case GLOSSARY_DATE_VIEW:
355  
-    case GLOSSARY_STANDARD_VIEW:
356  
-    default:
357  
-        $sqlselect  = "SELECT ge.concept pivot, ge.*";
358  
-        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
359  
-
360  
-        $where = '';
361  
-        $fullpivot = 0;
362  
-        if ($CFG->dbtype == "postgres7") {
363  
-            $LIKE = "ILIKE";   // case-insensitive
364  
-        } else {
365  
-            $LIKE = "LIKE";
366  
-        }
367  
-
368  
-        switch ( $mode ) {
369  
-        case 'search': 
370  
-            $printpivot = 0;
371  
-            $where = "AND ( ge.concept $LIKE '%$hook%'";
372  
-            if ( $fullsearch ) {
373  
-                $where .= "OR ge.definition $LIKE '%$hook%')";
374  
-            } else {
375  
-                $where .= ")";
376  
-            }
377  
-        break;
378  
-        
379  
-        case 'term': 
380  
-            $printpivot = 0;
381  
-            $sqlfrom .= ", {$CFG->prefix}glossary_alias ga";
382  
-            $where = "AND ge.id = ga.entryid AND                            
383  
-                          (ge.concept = '$hook' OR ga.alias = '$hook' )
384  
-                     ";
385  
-//            $where = "AND ge.id = ga.entryid AND (
386  
-//                           (ge.casesensitive != 0 and ( ge.concept LIKE BINARY '$hook' OR ga.alias LIKE BINARY '$hook' ) ) or
387  
-//                           (ge.casesensitive = 0 and ( ucase(ge.concept) = ucase('$hook') OR ucase(ga.alias) = ucase('$hook') ) )
388  
-//                       )";
389  
-        break;
390  
-
391  
-        case 'entry': 
392  
-            $printpivot = 0;
393  
-            $where = "AND ge.id = $hook";
394  
-        break;
395  
-
396  
-        case 'letter': 
397  
-            if ($hook != 'ALL' and $hook != 'SPECIAL') {
398  
-                switch ($CFG->dbtype) {
399  
-                case 'postgres7':
400  
-                    $where = 'AND substr(ucase(concept),1,' .  strlen($hook) . ') = \'' . strtoupper($hook) . '\'';
401  
-                break;
402  
-                case 'mysql':
403  
-                    $where = 'AND left(ucase(concept),' .  strlen($hook) . ") = '$hook'";
404  
-                break;
405  
-                }
406  
-            }
407  
-        break;
408  
-        }
409  
-        
410  
-        $sqlwhere   = "WHERE (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) AND
411  
-                             (ge.approved != 0 $userid)
412  
-                              $where";
413  
-        switch ( $tab ) {
414  
-        case GLOSSARY_DATE_VIEW: 
415  
-            $sqlorderby = "ORDER BY $sortkey $sortorder";
416  
-        break;
417  
-        
418  
-        case GLOSSARY_STANDARD_VIEW: 
419  
-            $sqlorderby = "ORDER BY ge.concept";
420  
-        default:
421  
-        break;
422  
-        }
423  
-
424  
-        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
425  
-        $sqllimit   = " LIMIT $offset, $entriesbypage";
426  
-        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
427  
-
428  
-    break;
429  
-    } 
  224
+    include_once("sql.php");
430 225
 
431 226
 /// printing the entries
432 227
     $entriesshown = 0;
@@ -436,23 +231,31 @@
436 231
     }
437 232
     if ($allentries) {
438 233
         /// printing the paging links
439  
-        $paging = '';
  234
+        $paging = get_string("allentries","glossary");
  235
+        if ( $offset < 0 ) {
  236
+            $paging = '<strong>' . $paging . '</strong>';
  237
+        } else {
  238
+            $paging = "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=-1\">" . $paging . '</a>';
  239
+        }
440 240
         if ($count > $entriesbypage ) {
441 241
             for ($i = 0; ($i*$entriesbypage) < $count  ; $i++   ) {
442 242
                 if ( $paging != '' ) {
443  
-                    if ($i % 20 == 0) {
  243
+                    if ($i % 20 == 0 and $i) {
444 244
                         $paging .= '<br>';
445 245
                     } else {
446 246
                         $paging .= ' | ';
447 247
                     }
448 248
                 }
  249
+                $pagenumber = (string) ($i + 1 );
449 250
                 if ($offset / $entriesbypage == $i) {
450  
-                    $paging .= '<strong>' . ($i + 1 ) . '</strong>';
  251
+                    $paging .= '<strong>' . $pagenumber . '</strong>';
451 252
                 } else {
452  
-                    $paging .= "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=" . ($i*$entriesbypage) . "\">" . ($i+1) . '</a>';
  253
+                    $paging .= "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=" . ($i*$entriesbypage) . "\">" . $pagenumber . '</a>';
453 254
                 }
454 255
             }
455 256
             $paging  = "<font size=1><center>" . get_string ("jumpto") . " $paging</center></font>";
  257
+        } else {
  258
+            $paging = '';
456 259
         }
457 260
         echo $paging;
458 261
 

0 notes on commit 4f3e59c

Please sign in to comment.
Something went wrong with that request. Please try again.