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 = get_context_instance(CONTEXT_MODULE
, $cm->id
);
53 // Prepare format_string/text options
55 'context' => $context);
57 require_once($CFG->dirroot
. '/comment/lib.php');
60 /// Loading the textlib singleton instance. We are going to need it.
61 $textlib = textlib_get_instance();
63 /// redirecting if adding a new entry
64 if ($tab == GLOSSARY_ADDENTRY_VIEW
) {
65 redirect("edit.php?cmid=$cm->id&mode=$mode");
68 /// setting the defaut number of entries per page if not set
69 if ( !$entriesbypage = $glossary->entbypage
) {
70 $entriesbypage = $CFG->glossary_entbypage
;
73 /// If we have received a page, recalculate offset
74 if ($page != 0 && $offset == 0) {
75 $offset = $page * $entriesbypage;
78 /// setting the default values for the display mode of the current glossary
79 /// only if the glossary is viewed by the first time
80 if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat
)) ) {
81 /// Based on format->defaultmode, we build the defaulttab to be showed sometimes
82 switch ($dp->defaultmode
) {
84 $defaulttab = GLOSSARY_CATEGORY_VIEW
;
87 $defaulttab = GLOSSARY_DATE_VIEW
;
90 $defaulttab = GLOSSARY_AUTHOR_VIEW
;
93 $defaulttab = GLOSSARY_STANDARD_VIEW
;
95 /// Fetch the rest of variables
96 $printpivot = $dp->showgroup
;
97 if ( $mode == '' and $hook == '' and $show == '') {
98 $mode = $dp->defaultmode
;
99 $hook = $dp->defaulthook
;
100 $sortkey = $dp->sortkey
;
101 $sortorder = $dp->sortorder
;
104 $defaulttab = GLOSSARY_STANDARD_VIEW
;
106 if ( $mode == '' and $hook == '' and $show == '') {
112 if ( $displayformat == -1 ) {
113 $displayformat = $glossary->displayformat
;
121 /// Processing standard security processes
122 if ($course->id
!= SITEID
) {
123 require_login($course->id
);
125 if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $context)) {
126 echo $OUTPUT->header();
127 notice(get_string("activityiscurrentlyhidden"));
129 add_to_log($course->id
, "glossary", "view", "view.php?id=$cm->id&tab=$tab", $glossary->id
, $cm->id
);
132 $completion = new completion_info($course);
133 $completion->set_module_viewed($cm);
135 /// stablishing flag variables
136 if ( $sortorder = strtolower($sortorder) ) {
137 if ($sortorder != 'asc' and $sortorder != 'desc') {
141 if ( $sortkey = strtoupper($sortkey) ) {
142 if ($sortkey != 'CREATION' and
143 $sortkey != 'UPDATE' and
144 $sortkey != 'FIRSTNAME' and
145 $sortkey != 'LASTNAME'
151 switch ( $mode = strtolower($mode) ) {
152 case 'search': /// looking for terms containing certain word(s)
153 $tab = GLOSSARY_STANDARD_VIEW
;
155 //Clean a bit the search string
156 $hook = trim(strip_tags($hook));
160 case 'entry': /// Looking for a certain entry id
161 $tab = GLOSSARY_STANDARD_VIEW
;
162 if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat
)) ) {
163 $displayformat = $dp->popupformatname
;
167 case 'cat': /// Looking for a certain cat
168 $tab = GLOSSARY_CATEGORY_VIEW
;
170 $category = $DB->get_record("glossary_categories", array("id"=>$hook));
174 case 'approval': /// Looking for entries waiting for approval
175 $tab = GLOSSARY_APPROVAL_VIEW
;
176 if ( !$hook and !$sortkey and !$sortorder) {
181 case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
182 $tab = GLOSSARY_STANDARD_VIEW
;
186 $tab = GLOSSARY_DATE_VIEW
;
195 case 'author': /// Looking for entries, browsed by author
196 $tab = GLOSSARY_AUTHOR_VIEW
;
201 $sortkey = 'FIRSTNAME';
208 case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
210 $tab = GLOSSARY_STANDARD_VIEW
;
218 case GLOSSARY_IMPORT_VIEW
:
219 case GLOSSARY_EXPORT_VIEW
:
220 case GLOSSARY_APPROVAL_VIEW
:
221 $showcommonelements = 0;
225 $showcommonelements = 1;
229 /// Printing the heading
230 $strglossaries = get_string("modulenameplural", "glossary");
231 $strglossary = get_string("modulename", "glossary");
232 $strallcategories = get_string("allcategories", "glossary");
233 $straddentry = get_string("addentry", "glossary");
234 $strnoentries = get_string("noentries", "glossary");
235 $strsearchindefinition = get_string("searchindefinition", "glossary");
236 $strsearch = get_string("search");
237 $strwaitingapproval = get_string('waitingapproval', 'glossary');
239 /// If we are in approval mode, prit special header
240 $PAGE->set_title(format_string($glossary->name
));
241 $PAGE->set_heading($course->fullname
);
242 $url = new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id
));
244 $url->param('mode', $mode);
246 $PAGE->set_url($url);
248 if (!empty($CFG->enablerssfeeds
) && !empty($CFG->glossary_enablerssfeeds
)
249 && $glossary->rsstype
&& $glossary->rssarticles
) {
251 $rsstitle = format_string($course->shortname
, true, array('context' => get_context_instance(CONTEXT_COURSE
, $course->id
))) . ': %fullname%';
252 rss_add_http_header($context, 'mod_glossary', $glossary, $rsstitle);
255 if ($tab == GLOSSARY_APPROVAL_VIEW
) {
256 require_capability('mod/glossary:approve', $context);
257 $PAGE->navbar
->add($strwaitingapproval);
258 echo $OUTPUT->header();
259 echo $OUTPUT->heading($strwaitingapproval);
260 } else { /// Print standard header
261 echo $OUTPUT->header();
264 /// All this depends if whe have $showcommonelements
265 if ($showcommonelements) {
266 /// To calculate available options
267 $availableoptions = '';
269 /// Decide about to print the import link
270 /*if (has_capability('mod/glossary:import', $context)) {
271 $availableoptions = '<span class="helplink">' .
272 '<a href="' . $CFG->wwwroot . '/mod/glossary/import.php?id=' . $cm->id . '"' .
273 ' title="' . s(get_string('importentries', 'glossary')) . '">' .
274 get_string('importentries', 'glossary') . '</a>' .
277 /// Decide about to print the export link
278 if (has_capability('mod/glossary:export', $context)) {
279 if ($availableoptions) {
280 $availableoptions .= ' / ';
282 $availableoptions .='<span class="helplink">' .
283 '<a href="' . $CFG->wwwroot . '/mod/glossary/export.php?id=' . $cm->id .
284 '&mode='.$mode . '&hook=' . urlencode($hook) . '"' .
285 ' title="' . s(get_string('exportentries', 'glossary')) . '">' .
286 get_string('exportentries', 'glossary') . '</a>' .
290 /// Decide about to print the approval link
291 if (has_capability('mod/glossary:approve', $context)) {
292 /// Check we have pending entries
293 if ($hiddenentries = $DB->count_records('glossary_entries', array('glossaryid'=>$glossary->id
, 'approved'=>0))) {
294 if ($availableoptions) {
295 $availableoptions .= '<br />';
297 $availableoptions .='<span class="helplink">' .
298 '<a href="' . $CFG->wwwroot
. '/mod/glossary/view.php?id=' . $cm->id
.
299 '&mode=approval' . '"' .
300 ' title="' . s(get_string('waitingapproval', 'glossary')) . '">' .
301 get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' .
306 /// Start to print glossary controls
307 // print_box_start('glossarycontrol clearfix');
308 echo '<div class="glossarycontrol" style="text-align: right">';
309 echo $availableoptions;
312 if ( $showcommonelements and $mode != 'search') {
313 if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview
) {
314 // print_box_start('printicon');
315 echo '<span class="wrap printicon">';
316 echo " <a title =\"". get_string("printerfriendly","glossary") ."\" href=\"print.php?id=$cm->id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\"><img class=\"icon\" src=\"".$OUTPUT->pix_url('print', 'glossary')."\" alt=\"". get_string("printerfriendly","glossary") . "\" /></a>";
321 /// End glossary controls
322 // print_box_end(); /// glossarycontrol
325 // print_box(' ', 'clearer');
329 if ($glossary->intro
&& $showcommonelements) {
330 echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id
), 'generalbox', 'intro');
334 if ($showcommonelements ) {
335 echo '<form method="post" action="view.php">';
337 echo '<table class="boxaligncenter" width="70%" border="0">';
338 echo '<tr><td align="center" class="glossarysearchbox">';
340 echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" /> ';
341 if ($mode == 'search') {
342 echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" /> ';
344 echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" /> ';
346 if ($fullsearch ||
$mode != 'search') {
347 $fullsearchchecked = 'checked="checked"';
349 $fullsearchchecked = '';
351 echo '<input type="checkbox" name="fullsearch" id="fullsearch" value="1" '.$fullsearchchecked.' />';
352 echo '<input type="hidden" name="mode" value="search" />';
353 echo '<input type="hidden" name="id" value="'.$cm->id
.'" />';
354 echo '<label for="fullsearch">'.$strsearchindefinition.'</label>';
355 echo '</td></tr></table>';
362 /// Show the add entry button if allowed
363 if (has_capability('mod/glossary:write', $context) && $showcommonelements ) {
364 echo '<div class="singlebutton glossaryaddentry">';
365 echo "<form id=\"newentryform\" method=\"get\" action=\"$CFG->wwwroot/mod/glossary/edit.php\">";
367 echo "<input type=\"hidden\" name=\"cmid\" value=\"$cm->id\" />";
368 echo '<input type="submit" value="'.get_string('addentry', 'glossary').'" />';
380 /// printing the entries
387 //Decide if we must show the ALL link in the pagebar
389 if ($glossary->showall
) {
390 $specialtext = get_string("allentries","glossary");
394 $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);
396 echo '<div class="paging">';
401 require_once($CFG->dirroot
.'/rating/lib.php');
402 if ($glossary->assessed
!= RATING_AGGREGATE_NONE
) {
403 $ratingoptions = new stdClass
;
404 $ratingoptions->context
= $context;
405 $ratingoptions->component
= 'mod_glossary';
406 $ratingoptions->ratingarea
= 'entry';
407 $ratingoptions->items
= $allentries;
408 $ratingoptions->aggregate
= $glossary->assessed
;//the aggregation method
409 $ratingoptions->scaleid
= $glossary->scale
;
410 $ratingoptions->userid
= $USER->id
;
411 $ratingoptions->returnurl
= $CFG->wwwroot
.'/mod/glossary/view.php?id='.$cm->id
;
412 $ratingoptions->assesstimestart
= $glossary->assesstimestart
;
413 $ratingoptions->assesstimefinish
= $glossary->assesstimefinish
;
415 $rm = new rating_manager();
416 $allentries = $rm->get_ratings($ratingoptions);
419 foreach ($allentries as $entry) {
421 // Setting the pivot for the current entry
422 $pivot = $entry->glossarypivot
;
423 $upperpivot = $textlib->strtoupper($pivot);
424 $pivottoshow = $textlib->strtoupper(format_string($pivot, true, $fmtoptions));
425 // Reduce pivot to 1cc if necessary
427 $upperpivot = $textlib->substr($upperpivot, 0, 1);
428 $pivottoshow = $textlib->substr($pivottoshow, 0, 1);
431 // if there's a group break
432 if ( $currentpivot != $upperpivot ) {
434 // print the group break if apply
436 $currentpivot = $upperpivot;
439 echo '<table cellspacing="0" class="glossarycategoryheader">';
442 if ( isset($entry->userispivot
) ) {
443 // printing the user icon if defined (only when browsing authors)
444 echo '<th align="left">';
446 $user = $DB->get_record("user", array("id"=>$entry->userid
));
447 echo $OUTPUT->user_picture($user, array('courseid'=>$course->id
));
448 $pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE
, $course->id
)));
453 echo $OUTPUT->heading($pivottoshow);
454 echo "</th></tr></table></div>\n";
459 /// highlight the term if necessary
460 if ($mode == 'search') {
461 //We have to strip any word starting by + and take out words starting by -
462 //to make highlight works properly
463 $searchterms = explode(' ', $hook); // Search for words independently
464 foreach ($searchterms as $key => $searchterm) {
465 if (preg_match('/^\-/',$searchterm)) {
466 unset($searchterms[$key]);
468 $searchterms[$key] = preg_replace('/^\+/','',$searchterm);
470 //Avoid highlight of <2 len strings. It's a well known hilight limitation.
471 if (strlen($searchterm) < 2) {
472 unset($searchterms[$key]);
475 $strippedsearch = implode(' ', $searchterms); // Rebuild the string
476 $entry->highlight
= $strippedsearch;
479 /// and finally print the entry.
480 glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat);
484 if ( !$entriesshown ) {
485 echo $OUTPUT->box(get_string("noentries","glossary"), "generalbox boxaligncenter boxwidthwide");
488 if (!empty($formsent)) {
489 // close the form properly if used
496 echo '<div class="paging">';
501 glossary_print_tabbed_table_end();
504 echo $OUTPUT->footer();