2 /// This page prints a particular instance of glossary
3 require_once("../../config.php");
4 require_once("lib.php");
5 require_once("$CFG->libdir/rsslib.php");
7 $id = optional_param('id', 0, PARAM_INT
); // Course Module ID
8 $g = optional_param('g', 0, PARAM_INT
); // Glossary ID
10 $tab = optional_param('tab', GLOSSARY_NO_VIEW
, PARAM_ALPHA
); // browsing entries by categories?
11 $displayformat = optional_param('displayformat',-1, PARAM_INT
); // override of the glossary display format
13 $mode = optional_param('mode', '', PARAM_ALPHA
); // term entry cat date letter search author approval
14 $hook = optional_param('hook', '', PARAM_CLEAN
); // the term, entry, cat, etc... to look for based on mode
15 $fullsearch = optional_param('fullsearch', 0,PARAM_INT
); // full search (concept and definition) when searching?
16 $sortkey = optional_param('sortkey', '', PARAM_ALPHA
);// Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME...
17 $sortorder = optional_param('sortorder', 'ASC', PARAM_ALPHA
); // it defines the order of the sorting (ASC or DESC)
18 $offset = optional_param('offset', 0,PARAM_INT
); // entries to bypass (for paging purposes)
19 $page = optional_param('page', 0,PARAM_INT
); // Page to show (for paging purposes)
20 $show = optional_param('show', '', PARAM_ALPHA
); // [ concept | alias ] => mode=term hook=$show
23 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
24 error("Course Module ID was incorrect");
26 if (! $course = get_record("course", "id", $cm->course
)) {
27 error("Course is misconfigured");
29 if (! $glossary = get_record("glossary", "id", $cm->instance
)) {
30 error("Course module is incorrect");
32 } else if (!empty($g)) {
33 if (! $glossary = get_record("glossary", "id", $g)) {
34 error("Course module is incorrect");
36 if (! $course = get_record("course", "id", $glossary->course
)) {
37 error("Could not determine which course this belonged to!");
39 if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id
, $course->id
)) {
40 error("Could not determine which course module this belonged to!");
44 error("Must specify glossary ID or course module ID");
47 require_course_login($course->id
, true, $cm);
48 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
50 /// Loading the textlib singleton instance. We are going to need it.
51 $textlib = textlib_get_instance();
53 /// redirecting if adding a new entry
54 if ($tab == GLOSSARY_ADDENTRY_VIEW
) {
55 redirect("edit.php?id=$cm->id&mode=$mode");
58 /// setting the defaut number of entries per page if not set
60 if ( !$entriesbypage = $glossary->entbypage
) {
61 $entriesbypage = $CFG->glossary_entbypage
;
64 /// If we have received a page, recalculate offset
65 if ($page != 0 && $offset == 0) {
66 $offset = $page * $entriesbypage;
69 /// setting the default values for the display mode of the current glossary
70 /// only if the glossary is viewed by the first time
71 if ( $dp = get_record('glossary_formats','name', addslashes($glossary->displayformat
)) ) {
72 /// Based on format->defaultmode, we build the defaulttab to be showed sometimes
73 switch ($dp->defaultmode
) {
75 $defaulttab = GLOSSARY_CATEGORY_VIEW
;
78 $defaulttab = GLOSSARY_DATE_VIEW
;
81 $defaulttab = GLOSSARY_AUTHOR_VIEW
;
84 $defaulttab = GLOSSARY_STANDARD_VIEW
;
86 /// Fetch the rest of variables
87 $printpivot = $dp->showgroup
;
88 if ( $mode == '' and $hook == '' and $show == '') {
89 $mode = $dp->defaultmode
;
90 $hook = $dp->defaulthook
;
91 $sortkey = $dp->sortkey
;
92 $sortorder = $dp->sortorder
;
95 $defaulttab = GLOSSARY_STANDARD_VIEW
;
97 if ( $mode == '' and $hook == '' and $show == '') {
103 if ( $displayformat == -1 ) {
104 $displayformat = $glossary->displayformat
;
112 /// Processing standard security processes
113 if ($course->id
!= SITEID
) {
114 require_login($course->id
);
116 if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $context)) {
118 notice(get_string("activityiscurrentlyhidden"));
120 add_to_log($course->id
, "glossary", "view", "view.php?id=$cm->id&tab=$tab", $glossary->id
, $cm->id
);
122 /// stablishing flag variables
123 if ( $sortorder = strtolower($sortorder) ) {
124 if ($sortorder != 'asc' and $sortorder != 'desc') {
128 if ( $sortkey = strtoupper($sortkey) ) {
129 if ($sortkey != 'CREATION' and
130 $sortkey != 'UPDATE' and
131 $sortkey != 'FIRSTNAME' and
132 $sortkey != 'LASTNAME'
138 switch ( $mode = strtolower($mode) ) {
139 case 'search': /// looking for terms containing certain word(s)
140 $tab = GLOSSARY_STANDARD_VIEW
;
142 //Clean a bit the search string
143 $hook = trim(strip_tags($hook));
147 case 'entry': /// Looking for a certain entry id
148 $tab = GLOSSARY_STANDARD_VIEW
;
149 if ( $dp = get_record("glossary_formats","name", $glossary->displayformat
) ) {
150 $displayformat = $dp->popupformatname
;
154 case 'cat': /// Looking for a certain cat
155 $tab = GLOSSARY_CATEGORY_VIEW
;
157 $category = get_record("glossary_categories","id",$hook);
161 case 'approval': /// Looking for entries waiting for approval
162 $tab = GLOSSARY_APPROVAL_VIEW
;
163 if ( !$hook and !$sortkey and !$sortorder) {
168 case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
169 $tab = GLOSSARY_STANDARD_VIEW
;
173 $tab = GLOSSARY_DATE_VIEW
;
182 case 'author': /// Looking for entries, browsed by author
183 $tab = GLOSSARY_AUTHOR_VIEW
;
188 $sortkey = 'FIRSTNAME';
195 case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
197 $tab = GLOSSARY_STANDARD_VIEW
;
205 case GLOSSARY_IMPORT_VIEW
:
206 case GLOSSARY_EXPORT_VIEW
:
207 case GLOSSARY_APPROVAL_VIEW
:
208 $showcommonelements = 0;
212 $showcommonelements = 1;
216 /// Printing the heading
217 $strglossaries = get_string("modulenameplural", "glossary");
218 $strglossary = get_string("modulename", "glossary");
219 $strallcategories = get_string("allcategories", "glossary");
220 $straddentry = get_string("addentry", "glossary");
221 $strnoentries = get_string("noentries", "glossary");
222 $strsearchconcept = get_string("searchconcept", "glossary");
223 $strsearchindefinition = get_string("searchindefinition", "glossary");
224 $strsearch = get_string("search");
225 $strwaitingapproval = get_string('waitingapproval', 'glossary');
228 $navlinks[] = array('name' => $strglossaries, 'link' => "index.php?id=$course->id", 'type' => 'activity');
229 $navlinks[] = array('name' => format_string($glossary->name
), 'link' => "view.php?id=$id", 'type' => 'activityinstance');
231 /// If we are in approval mode, prit special header
232 if ($tab == GLOSSARY_APPROVAL_VIEW
) {
233 require_capability('mod/glossary:approve', $context);
235 $navlinks[] = array('name' => $strwaitingapproval, 'link' => '', 'type' => 'title');
236 $navigation = build_navigation($navlinks);
238 print_header_simple(format_string($glossary->name
), "", $navigation, "", "", true,
239 update_module_button($cm->id
, $course->id
, $strglossary), navmenu($course, $cm));
241 print_heading($strwaitingapproval);
242 } else { /// Print standard header
243 $navigation = build_navigation($navlinks);
244 print_header_simple(format_string($glossary->name
), "", $navigation, "", "", true,
245 update_module_button($cm->id
, $course->id
, $strglossary), navmenu($course, $cm));
248 /// All this depends if whe have $showcommonelements
249 if ($showcommonelements) {
250 /// To calculate available options
251 $availableoptions = '';
253 /// Decide about to print the import link
254 if (has_capability('mod/glossary:import', $context)) {
255 $availableoptions = '<span class="helplink">' .
256 '<a href="' . $CFG->wwwroot
. '/mod/glossary/import.php?id=' . $cm->id
. '"' .
257 ' title="' . s(get_string('importentries', 'glossary')) . '">' .
258 get_string('importentries', 'glossary') . '</a>' .
261 /// Decide about to print the export link
262 if (has_capability('mod/glossary:export', $context)) {
263 if ($availableoptions) {
264 $availableoptions .= ' / ';
266 $availableoptions .='<span class="helplink">' .
267 '<a href="' . $CFG->wwwroot
. '/mod/glossary/export.php?id=' . $cm->id
.
268 '&mode='.$mode . '&hook=' . urlencode($hook) . '"' .
269 ' title="' . s(get_string('exportentries', 'glossary')) . '">' .
270 get_string('exportentries', 'glossary') . '</a>' .
274 /// Decide about to print the approval link
275 if (has_capability('mod/glossary:approve', $context)) {
276 /// Check we have pending entries
277 if ($hiddenentries = count_records_select('glossary_entries',"glossaryid = $glossary->id and approved = 0")) {
278 if ($availableoptions) {
279 $availableoptions .= '<br />';
281 $availableoptions .='<span class="helplink">' .
282 '<a href="' . $CFG->wwwroot
. '/mod/glossary/view.php?id=' . $cm->id
.
283 '&mode=approval' . '"' .
284 ' title="' . s(get_string('waitingapproval', 'glossary')) . '">' .
285 get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' .
290 /// Start to print glossary controls
291 print_box_start('glossarycontrol');
292 echo $availableoptions;
294 /// If rss are activated at site and glossary level and this glossary has rss defined, show link
295 if (isset($CFG->enablerssfeeds
) && isset($CFG->glossary_enablerssfeeds
) &&
296 $CFG->enablerssfeeds
&& $CFG->glossary_enablerssfeeds
&& $glossary->rsstype
&& $glossary->rssarticles
) {
298 $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name
,true));
299 if (empty($USER->id
)) {
304 print_box_start('rsslink');
305 rss_print_link($course->id
, $userid, "glossary", $glossary->id
, $tooltiptext);
310 if ( $showcommonelements and $mode != 'search') {
311 if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview
) {
312 print_box_start('printicon');
313 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=\"print.gif\" alt=\"". get_string("printerfriendly","glossary") . "\" /></a>";
317 /// End glossary controls
318 print_box_end(); /// glossarycontrol
320 print_box(' ', 'clearer');
324 if ( $glossary->intro
&& $showcommonelements ) {
325 print_box(format_text($glossary->intro
), 'generalbox', 'intro');
329 if ($showcommonelements ) {
330 echo '<form method="post" action="view.php">';
332 echo '<table class="boxaligncenter" width="70%" border="0">';
333 echo '<tr><td align="center" class="glossarysearchbox">';
335 echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" /> ';
336 if ($mode == 'search') {
337 echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" /> ';
339 echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" /> ';
341 if ($fullsearch ||
$mode != 'search') {
342 $fullsearchchecked = 'checked="checked"';
344 $fullsearchchecked = '';
346 echo '<input type="checkbox" name="fullsearch" value="1" '.$fullsearchchecked.' alt="'.$strsearchindefinition.'" />';
347 echo '<input type="hidden" name="mode" value="search" />';
348 echo '<input type="hidden" name="id" value="'.$cm->id
.'" />';
349 echo $strsearchindefinition;
350 echo '</td></tr></table>';
357 /// Show the add entry button if allowed
358 if (has_capability('mod/glossary:write', $context) && $showcommonelements ) {
359 echo '<div class="singlebutton glossaryaddentry">';
360 echo "<form id=\"newentryform\" method=\"get\" action=\"$CFG->wwwroot/mod/glossary/edit.php\">";
362 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
363 echo '<input type="submit" value="';
364 print_string('addentry', 'glossary');
375 include_once("sql.php");
377 /// printing the entries
380 $ratingsmenuused = NULL;
385 //Decide if we must show the ALL link in the pagebar
387 if ($glossary->showall
) {
388 $specialtext = get_string("allentries","glossary");
392 $paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&mode=$mode&hook=$hook&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch&",9999,10,' ', $specialtext, -1);
394 echo '<div class="paging">';
399 $ratingsmenuused = false;
400 if ($glossary->assessed
and isloggedin() and !isguestuser()) {
401 $ratings = new object();
402 if ($ratings->scale
= make_grades_menu($glossary->scale
)) {
403 $ratings->assesstimestart
= $glossary->assesstimestart
;
404 $ratings->assesstimefinish
= $glossary->assesstimefinish
;
406 if ($glossary->assessed
== 2 and !has_capability('mod/glossary:rate', $context)) {
407 $ratings->allow
= false;
409 $ratings->allow
= true;
413 echo "<form method=\"post\" action=\"rate.php\">";
415 echo "<input type=\"hidden\" name=\"glossaryid\" value=\"$glossary->id\" />";
418 foreach ($allentries as $entry) {
420 // Setting the pivot for the current entry
421 $pivot = $entry->glossarypivot
;
422 $upperpivot = $textlib->strtoupper($pivot);
423 // Reduce pivot to 1cc if necessary
425 $upperpivot = $textlib->substr($upperpivot, 0, 1);
428 // if there's a group break
429 if ( $currentpivot != $upperpivot ) {
431 // print the group break if apply
433 $currentpivot = $upperpivot;
436 echo '<table cellspacing="0" class="glossarycategoryheader">';
439 $pivottoshow = $currentpivot;
440 if ( isset($entry->userispivot
) ) {
441 // printing the user icon if defined (only when browsing authors)
442 echo '<td align="left">';
444 $user = get_record("user","id",$entry->userid
);
445 print_user_picture($user->id
, $course->id
, $user->picture
);
446 $pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE
, $course->id
)));
448 echo '<td align="center">';
451 echo "<strong> $pivottoshow</strong>" ;
452 echo '</td></tr></table></div>';
457 $concept = $entry->concept
;
458 $definition = $entry->definition
;
460 /// highlight the term if necessary
461 if ($mode == 'search') {
462 //We have to strip any word starting by + and take out words starting by -
463 //to make highlight works properly
464 $searchterms = explode(' ', $hook); // Search for words independently
465 foreach ($searchterms as $key => $searchterm) {
466 if (preg_match('/^\-/',$searchterm)) {
467 unset($searchterms[$key]);
469 $searchterms[$key] = preg_replace('/^\+/','',$searchterm);
471 //Avoid highlight of <2 len strings. It's a well known hilight limitation.
472 if (strlen($searchterm) < 2) {
473 unset($searchterms[$key]);
476 $strippedsearch = implode(' ', $searchterms); // Rebuild the string
477 $entry->highlight
= $strippedsearch;
480 /// and finally print the entry.
482 if ( glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,$ratings) ) {
483 $ratingsmenuused = true;
489 if ( !$entriesshown ) {
490 print_simple_box('<div style="text-align:center">' . get_string("noentries","glossary") . '</div>',"center","95%");
494 if ($ratingsmenuused) {
496 echo "<div class=\"boxaligncenter\"><input type=\"submit\" value=\"".get_string("sendinratings", "glossary")."\" />";
497 if ($glossary->scale
< 0) {
498 if ($scale = get_record("scale", "id", abs($glossary->scale
))) {
499 print_scale_menu_helpbutton($course->id
, $scale );
505 if (!empty($formsent)) {
506 // close the form properly if used
513 echo '<div class="paging">';
518 glossary_print_tabbed_table_end();
522 print_footer($course);