MDL-73912 templates: Proper type value for back to user menu button
[moodle.git] / mod / glossary / print.php
blob292d892c5c87ba00d8ac059f4dea14cec9d49f36
1 <?php
3 global $CFG;
5 require_once("../../config.php");
6 require_once("lib.php");
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 $pagelimit = optional_param('pagelimit', 0, PARAM_INT); // Number of entries per page, 0 if unlimited.
12 $displayformat = optional_param('displayformat',-1, PARAM_INT);
14 $mode = required_param('mode', PARAM_ALPHA); // mode to show the entries
15 $hook = optional_param('hook','ALL', PARAM_CLEAN); // what to show
16 $sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key
18 $url = new moodle_url('/mod/glossary/print.php', array('id'=>$id));
19 if ($sortorder !== 'asc') {
20 $url->param('sortorder', $sortorder);
22 if ($offset !== 0) {
23 $url->param('offset', $offset);
25 if ($displayformat !== -1) {
26 $url->param('displayformat', $displayformat);
28 if ($sortkey !== 'UPDATE') {
29 $url->param('sortkey', $sortkey);
31 if ($mode !== 'letter') {
32 $url->param('mode', $mode);
34 if ($hook !== 'ALL') {
35 $url->param('hook', $hook);
37 $PAGE->set_url($url);
39 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
40 print_error('invalidcoursemodule');
43 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
44 print_error('coursemisconf');
47 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
48 print_error('invalidid', 'glossary');
51 if ($pagelimit < 0) {
52 $pagelimit = 0;
55 require_course_login($course, true, $cm);
56 $context = context_module::instance($cm->id);
58 // Prepare format_string/text options
59 $fmtoptions = array(
60 'context' => $context);
62 $PAGE->set_pagelayout('print');
63 $PAGE->set_title(get_string("modulenameplural", "glossary"));
64 $PAGE->set_heading($course->fullname);
65 echo $OUTPUT->header();
67 if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) {
68 notice(get_string('printviewnotallowed', 'glossary'));
71 /// setting the default values for the display mode of the current glossary
72 /// only if the glossary is viewed by the first time
73 if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
74 $printpivot = $dp->showgroup;
75 if ( $mode == '' and $hook == '' and $show == '') {
76 $mode = $dp->defaultmode;
77 $hook = $dp->defaulthook;
78 $sortkey = $dp->sortkey;
79 $sortorder = $dp->sortorder;
81 } else {
82 $printpivot = 1;
83 if ( $mode == '' and $hook == '' and $show == '') {
84 $mode = 'letter';
85 $hook = 'ALL';
89 if ( $displayformat == -1 ) {
90 $displayformat = $glossary->displayformat;
93 /// stablishing flag variables
94 if ( $sortorder = strtolower($sortorder) ) {
95 if ($sortorder != 'asc' and $sortorder != 'desc') {
96 $sortorder = '';
99 if ( $sortkey = strtoupper($sortkey) ) {
100 if ($sortkey != 'CREATION' and
101 $sortkey != 'UPDATE' and
102 $sortkey != 'FIRSTNAME' and
103 $sortkey != 'LASTNAME'
105 $sortkey = '';
109 switch ( $mode = strtolower($mode) ) {
110 case 'entry': /// Looking for a certain entry id
111 $tab = GLOSSARY_STANDARD_VIEW;
112 break;
114 case 'cat': /// Looking for a certain cat
115 $tab = GLOSSARY_CATEGORY_VIEW;
116 if ( $hook > 0 ) {
117 $category = $DB->get_record("glossary_categories", array("id"=>$hook));
119 break;
121 case 'approval': /// Looking for entries waiting for approval
122 $tab = GLOSSARY_APPROVAL_VIEW;
123 if ( !$hook and !$sortkey and !$sortorder) {
124 $hook = 'ALL';
126 break;
128 case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
129 $tab = GLOSSARY_STANDARD_VIEW;
130 break;
132 case 'date':
133 $tab = GLOSSARY_DATE_VIEW;
134 if ( !$sortkey ) {
135 $sortkey = 'UPDATE';
137 if ( !$sortorder ) {
138 $sortorder = 'desc';
140 break;
142 case 'author': /// Looking for entries, browsed by author
143 $tab = GLOSSARY_AUTHOR_VIEW;
144 if ( !$hook ) {
145 $hook = 'ALL';
147 if ( !$sortkey ) {
148 $sortkey = 'FIRSTNAME';
150 if ( !$sortorder ) {
151 $sortorder = 'asc';
153 break;
155 case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
156 default:
157 $tab = GLOSSARY_STANDARD_VIEW;
158 if ( !$hook ) {
159 $hook = 'ALL';
161 break;
164 include_once("sql.php");
166 $entriesshown = 0;
167 $currentpivot = '';
169 $site = $DB->get_record("course", array("id"=>1));
171 // Print dialog link.
172 $printtext = get_string('print', 'glossary');
173 $printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'glossary_no_print printicon');
174 $printiconlink = html_writer::link('#', $printtext, $printlinkatt);
175 echo html_writer::tag('div', $printiconlink, array('class' => 'displayprinticon'));
177 echo html_writer::tag('div', userdate(time()), array('class' => 'displaydate'));
179 $sitename = get_string("site") . ': <span class="strong">' . format_string($site->fullname) . '</span>';
180 echo html_writer::tag('div', $sitename, array('class' => 'sitename'));
182 $coursename = get_string("course") . ': <span class="strong">' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</span>';
183 echo html_writer::tag('div', $coursename, array('class' => 'coursename'));
185 $modname = get_string("modulename","glossary") . ': <span class="strong">' . format_string($glossary->name, true) . '</span>';
186 echo html_writer::tag('div', $modname, array('class' => 'modname'));
188 if ( $allentries ) {
189 foreach ($allentries as $entry) {
191 // Setting the pivot for the current entry.
192 if ($printpivot) {
194 $pivot = $entry->{$pivotkey};
195 $upperpivot = core_text::strtoupper($pivot);
196 $pivottoshow = core_text::strtoupper(format_string($pivot, true, $fmtoptions));
198 // Reduce pivot to 1cc if necessary.
199 if (!$fullpivot) {
200 $upperpivot = core_text::substr($upperpivot, 0, 1);
201 $pivottoshow = core_text::substr($pivottoshow, 0, 1);
204 // If there's a group break.
205 if ($currentpivot != $upperpivot) {
206 $currentpivot = $upperpivot;
208 if ($userispivot) {
209 // Printing the user icon if defined (only when browsing authors).
210 $user = mod_glossary_entry_query_builder::get_user_from_record($entry);
211 $pivottoshow = fullname($user);
213 echo html_writer::tag('div', clean_text($pivottoshow), array('class' => 'mdl-align strong'));
217 glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook, 1, $displayformat, true);
219 // The all entries value may be a recordset or an array.
220 if ($allentries instanceof moodle_recordset) {
221 $allentries->close();
225 echo $OUTPUT->footer();