mirrored from git://git.moodle.org/moodle.git
/
view.php
283 lines (246 loc) · 10.9 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?PHP // $Id$
/// This page prints a particular instance of glossary
require_once("../../config.php");
require_once("lib.php");
require_once("dynalink.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 (! $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);
if (!$cm->visible and !isteacher($course->id)) {
notice(get_string("activityiscurrentlyhidden"));
}
add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id");
$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));
$currentview = "";
} elseif ( $eid ) {
$search = "";
}
if ($l == "" and $search == "" and ($eid == "" or $eid == 0) ) {
$l = "A";
} elseif ( $eid ) {
$l = "";
}
if ( $currentview ) {
$l = "";
$currentview = strtolower($currentview);
if ( $currentview ) {
if ( $cat > 0 ) {
$category = get_record("glossary_categories","id",$cat);
if ( !$category ) {
$cat = "";
}
}
}
}
/// Printing 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");
$strallcategories= get_string("allcategories", "glossary");
$straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
print_header(strip_tags("$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));
/// Printing the header of the glossary
echo "<p><center><b>$glossary->name<p>" ;
print_simple_box_start("center", "70%");
echo "<table width=100% border=0><tr><td width=50% align=right>";
?>
<form method="POST" action="view.php">
<?php p(get_string("searchconcept","glossary")) ?> <input type="text" name="search" size="20" value=""> <br><?php p(get_string("searchindefinition","glossary")) ?> <input type="checkbox" name="includedefinition" value="1">
<input type="submit" value="<?php p(get_string("search")) ?>" name="searchbutton">
<input type="hidden" name="id" value="<?php p($cm->id) ?>">
</form>
<?php
echo "</td><td valign=top align=right width=50%>";
if (isteacher($course->id) or ($glossary->studentcanpost) and !isguest($course->id)) {
$options = array ("id" => "$cm->id");
print_single_button("edit.php", $options, $straddentry );
}
echo "</td></tr></table>";
print_simple_box_end();
echo "<p align=center>";
$data[0]->link = "view.php?id=$id";
$data[0]->caption = get_string("standardview","glossary");
$data[1]->link = "view.php?id=$id¤tview=categories";
$data[1]->caption = get_string("categoryview","glossary");
if ( $currentview ) {
$CurrentTab = 1;
} else {
$CurrentTab = 0;
}
glossary_print_tabbed_table_start($data, $CurrentTab, $tCFG);
echo "<center>";
if ( $currentview ) {
glossary_print_categories_menu($course, $cm, $glossary, $cat, $category);
$currentcategory = "";
} else {
glossary_print_alphabet_menu($cm, $glossary, $l);
if ($l) {
$CurrentLetter = "";
} elseif( $search ) {
echo "<h3>" . get_string("search") . ": $search</h3>";
}
echo "<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);
} elseif ( $currentview and $cat == -1 ) { // Browsing all categories
$sql = "SELECT gec.id gecid, gc.name, gc.id CID, ge.*
FROM {$CFG->prefix}glossary_entries ge,
{$CFG->prefix}glossary_entries_categories gec,
{$CFG->prefix}glossary_categories gc
WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND
gec.entryid = ge.id AND
gc.id = gec.categoryid
ORDER BY gc.name, ge.concept";
$allentries = get_records_sql( $sql );
} else { // looking for terms that begin with a specify letter or entries with no category associated
$ownentries = get_records("glossary_entries", "glossaryid", $glossary->id,"concept ASC");
$importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id,"concept ASC");
if ( $ownentries and $importedentries ) {
$allentries = array_merge($ownentries, $importedentries);
usort($allentries, glossary_sort_entries);
} elseif ( $importedentries ) {
$allentries = $importedentries;
} elseif ( $ownentries ) {
$allentries = $ownentries;
}
}
if ( $allentries ) {
$DumpedDefinitions= 0;
foreach ($allentries as $entry) {
$DumpToScreen = 0;
$FirstLetter = strtoupper( substr(ltrim($entry->concept),0,strlen($l) ) );
if ( $l ) {
if ( $l == "ALL" or $FirstLetter == $l) {
if ( $CurrentLetter != $FirstLetter[0] ) {
$CurrentLetter = $FirstLetter[0];
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\">";
}
if ( $l == "ALL" ) {
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("Ñ") and (ord($FirstLetter)<ord("A") or ord($FirstLetter)>ord("Z")) ) {
$DumpToScreen = 1;
}
} else {
if ( $currentview ) {
if ( $category ) {
if ( record_exists("glossary_entries_categories","entryid",$entry->id, "categoryid",$category->id) ) {
$DumpToScreen = 1;
}
} else {
if ( $cat < 0 ) { // No categorized
if ( ! record_exists("glossary_entries_categories","entryid",$entry->id) ) {
$DumpToScreen = 1;
}
} else { // All categories
if ( $currentcategory != $entry->CID ) {
$currentcategory = $entry->CID;
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>$entry->name</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;
}
}
} 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);
}
if ( !$glossary->mainglossary ) {
$entry->definition = glossary_dynamic_link($course->id,$definition);
}
glossary_print_entry($course, $cm, $glossary, $entry,$currentview,$cat);
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>";
glossary_print_tabbed_table_end();
/// Finish the page
print_footer($course);
?>