MDL-30431 behat: Fixed wiki behat
[moodle.git] / mod / glossary / print.php
blobe6f4b9d4b84a86692c3bb9b91056409c7a1dd898
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 $displayformat = optional_param('displayformat',-1, PARAM_INT);
13 $mode = required_param('mode', PARAM_ALPHA); // mode to show the entries
14 $hook = optional_param('hook','ALL', PARAM_CLEAN); // what to show
15 $sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key
17 $url = new moodle_url('/mod/glossary/print.php', array('id'=>$id));
18 if ($sortorder !== 'asc') {
19 $url->param('sortorder', $sortorder);
21 if ($offset !== 0) {
22 $url->param('offset', $offset);
24 if ($displayformat !== -1) {
25 $url->param('displayformat', $displayformat);
27 if ($sortkey !== 'UPDATE') {
28 $url->param('sortkey', $sortkey);
30 if ($mode !== 'letter') {
31 $url->param('mode', $mode);
33 if ($hook !== 'ALL') {
34 $url->param('hook', $hook);
36 $PAGE->set_url($url);
38 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
39 print_error('invalidcoursemodule');
42 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
43 print_error('coursemisconf');
46 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
47 print_error('invalidid', 'glossary');
50 if ( !$entriesbypage = $glossary->entbypage ) {
51 $entriesbypage = $CFG->glossary_entbypage;
54 require_course_login($course, true, $cm);
55 $context = context_module::instance($cm->id);
57 // Prepare format_string/text options
58 $fmtoptions = array(
59 'context' => $context);
61 $PAGE->set_pagelayout('print');
62 $PAGE->set_title(get_string("modulenameplural", "glossary"));
63 $PAGE->set_heading($course->fullname);
64 echo $OUTPUT->header();
66 if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) {
67 notice(get_string('printviewnotallowed', 'glossary'));
70 /// setting the default values for the display mode of the current glossary
71 /// only if the glossary is viewed by the first time
72 if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
73 $printpivot = $dp->showgroup;
74 if ( $mode == '' and $hook == '' and $show == '') {
75 $mode = $dp->defaultmode;
76 $hook = $dp->defaulthook;
77 $sortkey = $dp->sortkey;
78 $sortorder = $dp->sortorder;
80 } else {
81 $printpivot = 1;
82 if ( $mode == '' and $hook == '' and $show == '') {
83 $mode = 'letter';
84 $hook = 'ALL';
88 if ( $displayformat == -1 ) {
89 $displayformat = $glossary->displayformat;
92 /// stablishing flag variables
93 if ( $sortorder = strtolower($sortorder) ) {
94 if ($sortorder != 'asc' and $sortorder != 'desc') {
95 $sortorder = '';
98 if ( $sortkey = strtoupper($sortkey) ) {
99 if ($sortkey != 'CREATION' and
100 $sortkey != 'UPDATE' and
101 $sortkey != 'FIRSTNAME' and
102 $sortkey != 'LASTNAME'
104 $sortkey = '';
108 switch ( $mode = strtolower($mode) ) {
109 case 'entry': /// Looking for a certain entry id
110 $tab = GLOSSARY_STANDARD_VIEW;
111 break;
113 case 'cat': /// Looking for a certain cat
114 $tab = GLOSSARY_CATEGORY_VIEW;
115 if ( $hook > 0 ) {
116 $category = $DB->get_record("glossary_categories", array("id"=>$hook));
118 break;
120 case 'approval': /// Looking for entries waiting for approval
121 $tab = GLOSSARY_APPROVAL_VIEW;
122 if ( !$hook and !$sortkey and !$sortorder) {
123 $hook = 'ALL';
125 break;
127 case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
128 $tab = GLOSSARY_STANDARD_VIEW;
129 break;
131 case 'date':
132 $tab = GLOSSARY_DATE_VIEW;
133 if ( !$sortkey ) {
134 $sortkey = 'UPDATE';
136 if ( !$sortorder ) {
137 $sortorder = 'desc';
139 break;
141 case 'author': /// Looking for entries, browsed by author
142 $tab = GLOSSARY_AUTHOR_VIEW;
143 if ( !$hook ) {
144 $hook = 'ALL';
146 if ( !$sortkey ) {
147 $sortkey = 'FIRSTNAME';
149 if ( !$sortorder ) {
150 $sortorder = 'asc';
152 break;
154 case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
155 default:
156 $tab = GLOSSARY_STANDARD_VIEW;
157 if ( !$hook ) {
158 $hook = 'ALL';
160 break;
163 include_once("sql.php");
165 $entriesshown = 0;
166 $currentpivot = '';
168 $site = $DB->get_record("course", array("id"=>1));
170 // Print dialog link.
171 $printtext = get_string('print', 'glossary');
172 $printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'glossary_no_print printicon');
173 $printiconlink = html_writer::link('#', $printtext, $printlinkatt);
174 echo html_writer::tag('div', $printiconlink, array('class' => 'displayprinticon'));
176 echo html_writer::tag('div', userdate(time()), array('class' => 'displaydate'));
178 $sitename = get_string("site") . ': <span class="strong">' . format_string($site->fullname) . '</span>';
179 echo html_writer::tag('div', $sitename, array('class' => 'sitename'));
181 $coursename = get_string("course") . ': <span class="strong">' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</span>';
182 echo html_writer::tag('div', $coursename, array('class' => 'coursename'));
184 $modname = get_string("modulename","glossary") . ': <span class="strong">' . format_string($glossary->name, true) . '</span>';
185 echo html_writer::tag('div', $modname, array('class' => 'modname'));
187 if ( $allentries ) {
188 foreach ($allentries as $entry) {
190 // Setting the pivot for the current entry
191 $pivot = $entry->glossarypivot;
192 $upperpivot = core_text::strtoupper($pivot);
193 $pivottoshow = core_text::strtoupper(format_string($pivot, true, $fmtoptions));
194 // Reduce pivot to 1cc if necessary
195 if ( !$fullpivot ) {
196 $upperpivot = core_text::substr($upperpivot, 0, 1);
197 $pivottoshow = core_text::substr($pivottoshow, 0, 1);
200 // If there's group break
201 if ( $currentpivot != $upperpivot ) {
203 // print the group break if apply
204 if ( $printpivot ) {
205 $currentpivot = $upperpivot;
207 if ( isset($entry->userispivot) ) {
208 // printing the user icon if defined (only when browsing authors)
209 $user = $DB->get_record("user", array("id"=>$entry->userid));
210 $pivottoshow = fullname($user);
212 echo html_writer::tag('div', clean_text($pivottoshow), array('class' => 'mdl-align strong'));
216 glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook, 1, $displayformat, true);
220 echo $OUTPUT->footer();