MDL-28048 glossary - add multilang support to categories
[moodle.git] / mod / glossary / print.php
CommitLineData
5fa0208e 1<?php
2
3global $CFG;
4
5require_once("../../config.php");
6require_once("lib.php");
7
8$id = required_param('id', PARAM_INT); // Course Module ID
9$sortorder = optional_param('sortorder', 'asc', PARAM_ALPHA); // Sorting order
10$offset = optional_param('offset', 0, PARAM_INT); // number of entries to bypass
11$displayformat = optional_param('displayformat',-1, PARAM_INT);
12
13$mode = required_param('mode', PARAM_ALPHA); // mode to show the entries
14$hook = optional_param('hook','ALL', PARAM_ALPHANUM); // what to show
15$sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key
16
a6855934 17$url = new moodle_url('/mod/glossary/print.php', array('id'=>$id));
5fa0208e 18if ($sortorder !== 'asc') {
19 $url->param('sortorder', $sortorder);
20}
21if ($offset !== 0) {
22 $url->param('offset', $offset);
23}
24if ($displayformat !== -1) {
25 $url->param('displayformat', $displayformat);
26}
27if ($sortkey !== 'UPDATE') {
28 $url->param('sortkey', $sortkey);
29}
30if ($mode !== 'letter') {
31 $url->param('mode', $mode);
32}
33if ($hook !== 'ALL') {
34 $url->param('hook', $hook);
35}
36$PAGE->set_url($url);
37
38if (! $cm = get_coursemodule_from_id('glossary', $id)) {
39 print_error('invalidcoursemodule');
40}
41
42if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
43 print_error('coursemisconf');
44}
45
46if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
47 print_error('invalidid', 'glossary');
48}
49
50if ( !$entriesbypage = $glossary->entbypage ) {
51 $entriesbypage = $CFG->glossary_entbypage;
52}
53
5fa0208e 54require_course_login($course, true, $cm);
55$context = get_context_instance(CONTEXT_MODULE, $cm->id);
4f4ca7b5 56
bce3e3dc
EL
57// Prepare format_string/text options
58$fmtoptions = array(
59 'context' => $context);
60
ed5d13c0 61$PAGE->set_pagelayout('print');
2e4fd166
RW
62$PAGE->set_title(get_string("modulenameplural", "glossary"));
63$PAGE->set_heading($course->fullname);
1f1cae83
EL
64echo $OUTPUT->header();
65
5fa0208e 66/// Loading the textlib singleton instance. We are going to need it.
67$textlib = textlib_get_instance();
a359c29b 68
5fa0208e 69if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) {
70 notice(get_string('printviewnotallowed', 'glossary'));
71}
ec81373f 72
5fa0208e 73/// setting the default values for the display mode of the current glossary
74/// only if the glossary is viewed by the first time
75if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
76 $printpivot = $dp->showgroup;
77 if ( $mode == '' and $hook == '' and $show == '') {
78 $mode = $dp->defaultmode;
79 $hook = $dp->defaulthook;
80 $sortkey = $dp->sortkey;
81 $sortorder = $dp->sortorder;
82 }
83} else {
84 $printpivot = 1;
85 if ( $mode == '' and $hook == '' and $show == '') {
86 $mode = 'letter';
87 $hook = 'ALL';
88 }
89}
4f4ca7b5 90
5fa0208e 91if ( $displayformat == -1 ) {
92 $displayformat = $glossary->displayformat;
93}
2a252525 94
5fa0208e 95/// stablishing flag variables
96if ( $sortorder = strtolower($sortorder) ) {
97 if ($sortorder != 'asc' and $sortorder != 'desc') {
98 $sortorder = '';
ec81373f 99 }
5fa0208e 100}
101if ( $sortkey = strtoupper($sortkey) ) {
102 if ($sortkey != 'CREATION' and
103 $sortkey != 'UPDATE' and
104 $sortkey != 'FIRSTNAME' and
105 $sortkey != 'LASTNAME'
106 ) {
107 $sortkey = '';
ec81373f 108 }
5fa0208e 109}
ec81373f 110
5fa0208e 111switch ( $mode = strtolower($mode) ) {
112case 'entry': /// Looking for a certain entry id
113 $tab = GLOSSARY_STANDARD_VIEW;
114break;
ec81373f 115
5fa0208e 116case 'cat': /// Looking for a certain cat
117 $tab = GLOSSARY_CATEGORY_VIEW;
118 if ( $hook > 0 ) {
119 $category = $DB->get_record("glossary_categories", array("id"=>$hook));
4f3e59c3 120 }
5fa0208e 121break;
4f3e59c3 122
5fa0208e 123case 'approval': /// Looking for entries waiting for approval
124 $tab = GLOSSARY_APPROVAL_VIEW;
125 if ( !$hook and !$sortkey and !$sortorder) {
126 $hook = 'ALL';
127 }
128break;
2b99ea9e 129
5fa0208e 130case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
131 $tab = GLOSSARY_STANDARD_VIEW;
132break;
71235154 133
5fa0208e 134case 'date':
135 $tab = GLOSSARY_DATE_VIEW;
136 if ( !$sortkey ) {
137 $sortkey = 'UPDATE';
41c98028 138 }
5fa0208e 139 if ( !$sortorder ) {
140 $sortorder = 'desc';
a359c29b 141 }
5fa0208e 142break;
a359c29b 143
5fa0208e 144case 'author': /// Looking for entries, browsed by author
145 $tab = GLOSSARY_AUTHOR_VIEW;
146 if ( !$hook ) {
147 $hook = 'ALL';
a359c29b 148 }
5fa0208e 149 if ( !$sortkey ) {
150 $sortkey = 'FIRSTNAME';
ea14e783 151 }
5fa0208e 152 if ( !$sortorder ) {
153 $sortorder = 'asc';
4f3e59c3 154 }
5fa0208e 155break;
4f4ca7b5 156
5fa0208e 157case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
158default:
159 $tab = GLOSSARY_STANDARD_VIEW;
160 if ( !$hook ) {
161 $hook = 'ALL';
162 }
163break;
164}
165
166include_once("sql.php");
167
168$entriesshown = 0;
169$currentpivot = '';
170if ( $hook == 'SPECIAL' ) {
171 $alphabet = explode(",", get_string("alphabet"));
172}
173
174$site = $DB->get_record("course", array("id"=>1));
175echo '<p style="text-align:right"><span style="font-size:0.75em">' . userdate(time()) . '</span></p>';
176echo get_string("site") . ': <strong>' . format_string($site->fullname) . '</strong><br />';
177echo get_string("course") . ': <strong>' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</strong><br />';
178echo get_string("modulename","glossary") . ': <strong>' . format_string($glossary->name, true) . '</strong>';
179if ( $allentries ) {
180 foreach ($allentries as $entry) {
181
182 // Setting the pivot for the current entry
183 $pivot = $entry->glossarypivot;
184 $upperpivot = $textlib->strtoupper($pivot);
bce3e3dc 185 $pivottoshow = $textlib->strtoupper(format_string($pivot, true, $fmtoptions));
5fa0208e 186 // Reduce pivot to 1cc if necessary
187 if ( !$fullpivot ) {
188 $upperpivot = $textlib->substr($upperpivot, 0, 1);
bce3e3dc 189 $pivottoshow = $textlib->substr($pivottoshow, 0, 1);
ea14e783 190 }
4f4ca7b5 191
5fa0208e 192 // If there's group break
193 if ( $currentpivot != $upperpivot ) {
4f4ca7b5 194
5fa0208e 195 // print the group break if apply
196 if ( $printpivot ) {
197 $currentpivot = $upperpivot;
ec81373f 198
5fa0208e 199 if ( isset($entry->userispivot) ) {
200 // printing the user icon if defined (only when browsing authors)
201 $user = $DB->get_record("user", array("id"=>$entry->userid));
202 $pivottoshow = fullname($user);
4f3e59c3 203 }
539f698d 204
5fa0208e 205 echo "<p class='mdl-align'><strong>".clean_text($pivottoshow)."</strong></p>" ;
206 }
4f3e59c3 207 }
5fa0208e 208
209 glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,false,true);
4f4ca7b5 210 }
5fa0208e 211}
2a252525 212
5fa0208e 213echo $OUTPUT->footer();