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_ALPHANUM
); // what to show
15 $sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA
); // Sorting key
17 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
18 error("Course Module ID was incorrect");
21 if (! $course = get_record("course", "id", $cm->course
)) {
22 error("Course is misconfigured");
25 if (! $glossary = get_record("glossary", "id", $cm->instance
)) {
26 error("Course module is incorrect");
29 if ( !$entriesbypage = $glossary->entbypage
) {
30 $entriesbypage = $CFG->glossary_entbypage
;
35 require_course_login($course, true, $cm);
36 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
38 /// Loading the textlib singleton instance. We are going to need it.
39 $textlib = textlib_get_instance();
41 if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview
) {
42 notice(get_string('printviewnotallowed', 'glossary'));
45 /// setting the default values for the display mode of the current glossary
46 /// only if the glossary is viewed by the first time
47 if ( $dp = get_record('glossary_formats','name', addslashes($glossary->displayformat
)) ) {
48 $printpivot = $dp->showgroup
;
49 if ( $mode == '' and $hook == '' and $show == '') {
50 $mode = $dp->defaultmode
;
51 $hook = $dp->defaulthook
;
52 $sortkey = $dp->sortkey
;
53 $sortorder = $dp->sortorder
;
57 if ( $mode == '' and $hook == '' and $show == '') {
63 if ( $displayformat == -1 ) {
64 $displayformat = $glossary->displayformat
;
67 /// stablishing flag variables
68 if ( $sortorder = strtolower($sortorder) ) {
69 if ($sortorder != 'asc' and $sortorder != 'desc') {
73 if ( $sortkey = strtoupper($sortkey) ) {
74 if ($sortkey != 'CREATION' and
75 $sortkey != 'UPDATE' and
76 $sortkey != 'FIRSTNAME' and
77 $sortkey != 'LASTNAME'
83 switch ( $mode = strtolower($mode) ) {
84 case 'entry': /// Looking for a certain entry id
85 $tab = GLOSSARY_STANDARD_VIEW
;
88 case 'cat': /// Looking for a certain cat
89 $tab = GLOSSARY_CATEGORY_VIEW
;
91 $category = get_record("glossary_categories","id",$hook);
95 case 'approval': /// Looking for entries waiting for approval
96 $tab = GLOSSARY_APPROVAL_VIEW
;
97 if ( !$hook and !$sortkey and !$sortorder) {
102 case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
103 $tab = GLOSSARY_STANDARD_VIEW
;
107 $tab = GLOSSARY_DATE_VIEW
;
116 case 'author': /// Looking for entries, browsed by author
117 $tab = GLOSSARY_AUTHOR_VIEW
;
122 $sortkey = 'FIRSTNAME';
129 case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
131 $tab = GLOSSARY_STANDARD_VIEW
;
138 include_once("sql.php");
142 if ( $hook == 'SPECIAL' ) {
143 $alphabet = explode(",", get_string("alphabet"));
146 $site = get_record("course","id",1);
147 echo '<p style="text-align:right"><span style="font-size:0.75em">' . userdate(time()) . '</span></p>';
148 echo get_string("site") . ': <strong>' . format_string($site->fullname
) . '</strong><br />';
149 echo get_string("course") . ': <strong>' . format_string($course->fullname
) . ' ('. format_string($course->shortname
) . ')</strong><br />';
150 echo get_string("modulename","glossary") . ': <strong>' . format_string($glossary->name
, true) . '</strong>';
152 foreach ($allentries as $entry) {
154 // Setting the pivot for the current entry
155 $pivot = $entry->glossarypivot
;
156 $upperpivot = $textlib->strtoupper($pivot);
157 // Reduce pivot to 1cc if necessary
159 $upperpivot = $textlib->substr($upperpivot, 0, 1);
162 // If there's group break
163 if ( $currentpivot != $upperpivot ) {
165 // print the group break if apply
167 $currentpivot = $upperpivot;
169 $pivottoshow = $currentpivot;
170 if ( isset($entry->userispivot
) ) {
171 // printing the user icon if defined (only when browsing authors)
172 $user = get_record("user","id",$entry->userid
);
173 $pivottoshow = fullname($user);
176 echo "<p align=\"center\"><strong>".clean_text($pivottoshow)."</strong></p>" ;
180 glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,false,true);
184 print_footer('empty');