mirrored from git://git.moodle.org/moodle.git
/
print.php
230 lines (192 loc) · 7.52 KB
/
print.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
<?php // $Id$
global $CFG;
require_once("../../config.php");
require_once("lib.php");
require_variable($id); // Course Module ID
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
optional_variable($displayformat,-1);
$mode = strip_tags(urldecode($mode)); //XSS
$hook = strip_tags(urldecode($hook)); //XSS
$sortkey = strip_tags(urldecode($sortkey)); //XSS
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");
}
if ( !$entriesbypage = $glossary->entbypage ) {
$entriesbypage = $CFG->glossary_entbypage;
}
print_header_simple(strip_tags("$glossary->name"));
if ($CFG->forcelogin) {
require_login();
}
require_course_login($course);
/// setting the default values for the display mode of the current glossary
/// only if the glossary is viewed by the first time
if ( $dp = get_record('glossary_formats','name', $glossary->displayformat) ) {
$printpivot = $dp->showgroup;
if ( $mode == '' and $hook == '' and $show == '') {
$mode = $dp->defaultmode;
$hook = $dp->defaulthook;
$sortkey = $dp->sortkey;
$sortorder = $dp->sortorder;
}
} else {
$printpivot = 1;
if ( $mode == '' and $hook == '' and $show == '') {
$mode = 'letter';
$hook = 'ALL';
}
}
if ( $displayformat == -1 ) {
$displayformat = $glossary->displayformat;
}
/// stablishing flag variables
if ( $sortorder = strtolower($sortorder) ) {
if ($sortorder != 'asc' and $sortorder != 'desc') {
$sortorder = '';
}
}
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 '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 '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';
}
break;
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;
}
include_once("sql.php");
$entriesshown = 0;
$currentpivot = '';
if ( $hook == 'SPECIAL' ) {
$alphabet = explode(",", get_string("alphabet"));
}
$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 . ' ('. $course->shortname . ')</strong><br />';
echo get_string("modulename","glossary") . ': <strong>' . $glossary->name . '</strong><p>';
if ( $allentries ) {
foreach ($allentries as $entry) {
/// Setting the pivot for the current entry
$pivot = $entry->pivot;
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 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;
}
}
}
/// 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 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;
}
}
/// 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);
$pivottoshow = $currentpivot;
if ( isset($entry->uid) ) {
$user = get_record("user","id",$entry->uid);
$pivottoshow = fullname($user, isteacher($course->id));
}
echo "<p align=\"center\"><strong><i>$pivottoshow</i></strong></p>" ;
}
}
echo '<b>'. strip_tags($entry->concept) . ': </b>';
$options->para = false;
$definition = format_text('<nolink>' . strip_tags($entry->definition) . '</nolink>', $entry->format,$options);
echo ($definition);
echo '<br><br>';
}
}
}
echo '</body></html>';
?>