3 /// This page prints a particular instance of glossary
4 require_once("../../config.php");
5 require_once("lib.php");
6 require_once($CFG->libdir
. '/completionlib.php');
7 require_once("$CFG->libdir/rsslib.php");
9 $id = optional_param('id', 0, PARAM_INT
); // Course Module ID
10 $g = optional_param('g', 0, PARAM_INT
); // Glossary ID
12 $tab = optional_param('tab', GLOSSARY_NO_VIEW
, PARAM_ALPHA
); // browsing entries by categories?
13 $displayformat = optional_param('displayformat',-1, PARAM_INT
); // override of the glossary display format
15 $mode = optional_param('mode', '', PARAM_ALPHA
); // term entry cat date letter search author approval
16 $hook = optional_param('hook', '', PARAM_CLEAN
); // the term, entry, cat, etc... to look for based on mode
17 $fullsearch = optional_param('fullsearch', 0,PARAM_INT
); // full search (concept and definition) when searching?
18 $sortkey = optional_param('sortkey', '', PARAM_ALPHA
);// Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME...
19 $sortorder = optional_param('sortorder', 'ASC', PARAM_ALPHA
); // it defines the order of the sorting (ASC or DESC)
20 $offset = optional_param('offset', 0,PARAM_INT
); // entries to bypass (for paging purposes)
21 $page = optional_param('page', 0,PARAM_INT
); // Page to show (for paging purposes)
22 $show = optional_param('show', '', PARAM_ALPHA
); // [ concept | alias ] => mode=term hook=$show
25 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
26 print_error('invalidcoursemodule');
28 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
29 print_error('coursemisconf');
31 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance
))) {
32 print_error('invalidid', 'glossary');
35 } else if (!empty($g)) {
36 if (! $glossary = $DB->get_record("glossary", array("id"=>$g))) {
37 print_error('invalidid', 'glossary');
39 if (! $course = $DB->get_record("course", array("id"=>$glossary->course
))) {
40 print_error('invalidcourseid');
42 if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id
, $course->id
)) {
43 print_error('invalidcoursemodule');
47 print_error('invalidid', 'glossary');
50 require_course_login($course->id
, true, $cm);
51 $context = context_module
::instance($cm->id
);
52 require_capability('mod/glossary:view', $context);
54 // Prepare format_string/text options
56 'context' => $context);
58 require_once($CFG->dirroot
. '/comment/lib.php');
61 /// redirecting if adding a new entry
62 if ($tab == GLOSSARY_ADDENTRY_VIEW
) {
63 redirect("edit.php?cmid=$cm->id&mode=$mode");
66 /// setting the defaut number of entries per page if not set
67 if ( !$entriesbypage = $glossary->entbypage
) {
68 $entriesbypage = $CFG->glossary_entbypage
;
71 /// If we have received a page, recalculate offset
72 if ($page != 0 && $offset == 0) {
73 $offset = $page * $entriesbypage;
76 /// setting the default values for the display mode of the current glossary
77 /// only if the glossary is viewed by the first time
78 if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat
)) ) {
79 /// Based on format->defaultmode, we build the defaulttab to be showed sometimes
80 switch ($dp->defaultmode
) {
82 $defaulttab = GLOSSARY_CATEGORY_VIEW
;
85 $defaulttab = GLOSSARY_DATE_VIEW
;
88 $defaulttab = GLOSSARY_AUTHOR_VIEW
;
91 $defaulttab = GLOSSARY_STANDARD_VIEW
;
93 /// Fetch the rest of variables
94 $printpivot = $dp->showgroup
;
95 if ( $mode == '' and $hook == '' and $show == '') {
96 $mode = $dp->defaultmode
;
97 $hook = $dp->defaulthook
;
98 $sortkey = $dp->sortkey
;
99 $sortorder = $dp->sortorder
;
102 $defaulttab = GLOSSARY_STANDARD_VIEW
;
104 if ( $mode == '' and $hook == '' and $show == '') {
110 if ( $displayformat == -1 ) {
111 $displayformat = $glossary->displayformat
;
119 /// Processing standard security processes
120 if ($course->id
!= SITEID
) {
121 require_login($course);
123 if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $context)) {
124 echo $OUTPUT->header();
125 notice(get_string("activityiscurrentlyhidden"));
128 /// stablishing flag variables
129 if ( $sortorder = strtolower($sortorder) ) {
130 if ($sortorder != 'asc' and $sortorder != 'desc') {
134 if ( $sortkey = strtoupper($sortkey) ) {
135 if ($sortkey != 'CREATION' and
136 $sortkey != 'UPDATE' and
137 $sortkey != 'FIRSTNAME' and
138 $sortkey != 'LASTNAME'
144 switch ( $mode = strtolower($mode) ) {
145 case 'search': /// looking for terms containing certain word(s)
146 $tab = GLOSSARY_STANDARD_VIEW
;
148 //Clean a bit the search string
149 $hook = trim(strip_tags($hook));
153 case 'entry': /// Looking for a certain entry id
154 $tab = GLOSSARY_STANDARD_VIEW
;
155 if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat
)) ) {
156 $displayformat = $dp->popupformatname
;
160 case 'cat': /// Looking for a certain cat
161 $tab = GLOSSARY_CATEGORY_VIEW
;
163 $category = $DB->get_record("glossary_categories", array("id"=>$hook));
167 case 'approval': /// Looking for entries waiting for approval
168 $tab = GLOSSARY_APPROVAL_VIEW
;
169 // Override the display format with the approvaldisplayformat
170 if ($glossary->approvaldisplayformat
!== 'default' && ($df = $DB->get_record("glossary_formats",
171 array("name" => $glossary->approvaldisplayformat
)))) {
172 $displayformat = $df->popupformatname
;
174 if ( !$hook and !$sortkey and !$sortorder) {
179 case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
180 $tab = GLOSSARY_STANDARD_VIEW
;
184 $tab = GLOSSARY_DATE_VIEW
;
193 case 'author': /// Looking for entries, browsed by author
194 $tab = GLOSSARY_AUTHOR_VIEW
;
199 $sortkey = 'FIRSTNAME';
206 case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
208 $tab = GLOSSARY_STANDARD_VIEW
;
216 case GLOSSARY_IMPORT_VIEW
:
217 case GLOSSARY_EXPORT_VIEW
:
218 case GLOSSARY_APPROVAL_VIEW
:
219 $showcommonelements = 0;
223 $showcommonelements = 1;
227 // Trigger module viewed event.
228 $event = \mod_glossary\event\course_module_viewed
::create(array(
229 'objectid' => $glossary->id
,
230 'context' => $context,
231 'other' => array('mode' => $mode)
233 $event->add_record_snapshot('course', $course);
234 $event->add_record_snapshot('course_modules', $cm);
235 $event->add_record_snapshot('glossary', $glossary);
239 $completion = new completion_info($course);
240 $completion->set_module_viewed($cm);
242 /// Printing the heading
243 $strglossaries = get_string("modulenameplural", "glossary");
244 $strglossary = get_string("modulename", "glossary");
245 $strallcategories = get_string("allcategories", "glossary");
246 $straddentry = get_string("addentry", "glossary");
247 $strnoentries = get_string("noentries", "glossary");
248 $strsearchindefinition = get_string("searchindefinition", "glossary");
249 $strsearch = get_string("search");
250 $strwaitingapproval = get_string('waitingapproval', 'glossary');
252 /// If we are in approval mode, prit special header
253 $PAGE->set_title($glossary->name
);
254 $PAGE->set_heading($course->fullname
);
255 $url = new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id
));
257 $url->param('mode', $mode);
259 $PAGE->set_url($url);
261 if (!empty($CFG->enablerssfeeds
) && !empty($CFG->glossary_enablerssfeeds
)
262 && $glossary->rsstype
&& $glossary->rssarticles
) {
264 $rsstitle = format_string($course->shortname
, true, array('context' => context_course
::instance($course->id
))) . ': '. format_string($glossary->name
);
265 rss_add_http_header($context, 'mod_glossary', $glossary, $rsstitle);
268 if ($tab == GLOSSARY_APPROVAL_VIEW
) {
269 require_capability('mod/glossary:approve', $context);
270 $PAGE->navbar
->add($strwaitingapproval);
271 echo $OUTPUT->header();
272 echo $OUTPUT->heading($strwaitingapproval);
273 } else { /// Print standard header
274 echo $OUTPUT->header();
276 echo $OUTPUT->heading(format_string($glossary->name
), 2);
278 /// All this depends if whe have $showcommonelements
279 if ($showcommonelements) {
280 /// To calculate available options
281 $availableoptions = '';
283 /// Decide about to print the import link
284 /*if (has_capability('mod/glossary:import', $context)) {
285 $availableoptions = '<span class="helplink">' .
286 '<a href="' . $CFG->wwwroot . '/mod/glossary/import.php?id=' . $cm->id . '"' .
287 ' title="' . s(get_string('importentries', 'glossary')) . '">' .
288 get_string('importentries', 'glossary') . '</a>' .
291 /// Decide about to print the export link
292 if (has_capability('mod/glossary:export', $context)) {
293 if ($availableoptions) {
294 $availableoptions .= ' / ';
296 $availableoptions .='<span class="helplink">' .
297 '<a href="' . $CFG->wwwroot . '/mod/glossary/export.php?id=' . $cm->id .
298 '&mode='.$mode . '&hook=' . urlencode($hook) . '"' .
299 ' title="' . s(get_string('exportentries', 'glossary')) . '">' .
300 get_string('exportentries', 'glossary') . '</a>' .
304 /// Decide about to print the approval link
305 if (has_capability('mod/glossary:approve', $context)) {
306 /// Check we have pending entries
307 if ($hiddenentries = $DB->count_records('glossary_entries', array('glossaryid'=>$glossary->id
, 'approved'=>0))) {
308 if ($availableoptions) {
309 $availableoptions .= '<br />';
311 $availableoptions .='<span class="helplink">' .
312 '<a href="' . $CFG->wwwroot
. '/mod/glossary/view.php?id=' . $cm->id
.
313 '&mode=approval' . '"' .
314 ' title="' . s(get_string('waitingapproval', 'glossary')) . '">' .
315 get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' .
320 /// Start to print glossary controls
321 // print_box_start('glossarycontrol clearfix');
322 echo '<div class="glossarycontrol" style="text-align: right">';
323 echo $availableoptions;
326 if ( $showcommonelements and $mode != 'search') {
327 if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview
) {
328 echo " <a class='printicon' title =\"". get_string("printerfriendly","glossary") ."\" href=\"print.php?id=$cm->id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\">" . get_string("printerfriendly","glossary")."</a>";
331 /// End glossary controls
332 // print_box_end(); /// glossarycontrol
335 // print_box(' ', 'clearer');
339 if ($glossary->intro
&& $showcommonelements) {
340 echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id
), 'generalbox', 'intro');
344 if ($showcommonelements ) {
345 echo '<form method="post" action="view.php">';
347 echo '<table class="boxaligncenter" width="70%" border="0">';
348 echo '<tr><td align="center" class="glossarysearchbox">';
350 echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" /> ';
351 if ($mode == 'search') {
352 echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" /> ';
354 echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" /> ';
356 if ($fullsearch ||
$mode != 'search') {
357 $fullsearchchecked = 'checked="checked"';
359 $fullsearchchecked = '';
361 echo '<input type="checkbox" name="fullsearch" id="fullsearch" value="1" '.$fullsearchchecked.' />';
362 echo '<input type="hidden" name="mode" value="search" />';
363 echo '<input type="hidden" name="id" value="'.$cm->id
.'" />';
364 echo '<label for="fullsearch">'.$strsearchindefinition.'</label>';
365 echo '</td></tr></table>';
372 /// Show the add entry button if allowed
373 if (has_capability('mod/glossary:write', $context) && $showcommonelements ) {
374 echo '<div class="singlebutton glossaryaddentry">';
375 echo "<form id=\"newentryform\" method=\"get\" action=\"$CFG->wwwroot/mod/glossary/edit.php\">";
377 echo "<input type=\"hidden\" name=\"cmid\" value=\"$cm->id\" />";
378 echo '<input type="submit" value="'.get_string('addentry', 'glossary').'" />';
390 /// printing the entries
397 //Decide if we must show the ALL link in the pagebar
399 if ($glossary->showall
) {
400 $specialtext = get_string("allentries","glossary");
404 $paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch&",9999,10,' ', $specialtext, -1);
406 echo '<div class="paging">';
411 require_once($CFG->dirroot
.'/rating/lib.php');
412 if ($glossary->assessed
!= RATING_AGGREGATE_NONE
) {
413 $ratingoptions = new stdClass
;
414 $ratingoptions->context
= $context;
415 $ratingoptions->component
= 'mod_glossary';
416 $ratingoptions->ratingarea
= 'entry';
417 $ratingoptions->items
= $allentries;
418 $ratingoptions->aggregate
= $glossary->assessed
;//the aggregation method
419 $ratingoptions->scaleid
= $glossary->scale
;
420 $ratingoptions->userid
= $USER->id
;
421 $ratingoptions->returnurl
= $CFG->wwwroot
.'/mod/glossary/view.php?id='.$cm->id
;
422 $ratingoptions->assesstimestart
= $glossary->assesstimestart
;
423 $ratingoptions->assesstimefinish
= $glossary->assesstimefinish
;
425 $rm = new rating_manager();
426 $allentries = $rm->get_ratings($ratingoptions);
429 foreach ($allentries as $entry) {
431 // Setting the pivot for the current entry
432 $pivot = $entry->glossarypivot
;
433 $upperpivot = core_text
::strtoupper($pivot);
434 $pivottoshow = core_text
::strtoupper(format_string($pivot, true, $fmtoptions));
435 // Reduce pivot to 1cc if necessary
437 $upperpivot = core_text
::substr($upperpivot, 0, 1);
438 $pivottoshow = core_text
::substr($pivottoshow, 0, 1);
441 // if there's a group break
442 if ( $currentpivot != $upperpivot ) {
444 // print the group break if apply
446 $currentpivot = $upperpivot;
449 echo '<table cellspacing="0" class="glossarycategoryheader">';
452 if ( isset($entry->userispivot
) ) {
453 // printing the user icon if defined (only when browsing authors)
454 echo '<th align="left">';
456 $user = $DB->get_record("user", array("id"=>$entry->userid
));
457 echo $OUTPUT->user_picture($user, array('courseid'=>$course->id
));
458 $pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', context_course
::instance($course->id
)));
463 echo $OUTPUT->heading($pivottoshow, 3);
464 echo "</th></tr></table></div>\n";
469 /// highlight the term if necessary
470 if ($mode == 'search') {
471 //We have to strip any word starting by + and take out words starting by -
472 //to make highlight works properly
473 $searchterms = explode(' ', $hook); // Search for words independently
474 foreach ($searchterms as $key => $searchterm) {
475 if (preg_match('/^\-/',$searchterm)) {
476 unset($searchterms[$key]);
478 $searchterms[$key] = preg_replace('/^\+/','',$searchterm);
480 //Avoid highlight of <2 len strings. It's a well known hilight limitation.
481 if (strlen($searchterm) < 2) {
482 unset($searchterms[$key]);
485 $strippedsearch = implode(' ', $searchterms); // Rebuild the string
486 $entry->highlight
= $strippedsearch;
489 /// and finally print the entry.
490 glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat);
494 if ( !$entriesshown ) {
495 echo $OUTPUT->box(get_string("noentries","glossary"), "generalbox boxaligncenter boxwidthwide");
498 if (!empty($formsent)) {
499 // close the form properly if used
506 echo '<div class="paging">';
511 glossary_print_tabbed_table_end();
514 echo $OUTPUT->footer();