MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / glossary / index.php
blobb3209f24583d28325cadce4f4c02856b5e9e6393
1 <?php // $Id$
3 /// This page lists all the instances of glossary in a particular course
4 /// Replace glossary with the name of your module
6 require_once("../../config.php");
7 require_once("lib.php");
8 require_once("$CFG->libdir/rsslib.php");
10 $id = required_param('id', PARAM_INT); // course
12 if (! $course = get_record("course", "id", $id)) {
13 error("Course ID is incorrect");
16 require_course_login($course);
17 $context = get_context_instance(CONTEXT_COURSE, $course->id);
19 add_to_log($course->id, "glossary", "view all", "index.php?id=$course->id", "");
22 /// Get all required strings
24 $strglossarys = get_string("modulenameplural", "glossary");
25 $strglossary = get_string("modulename", "glossary");
26 $strrss = get_string("rss");
29 /// Print the header
30 $navlinks = array();
31 $navlinks[] = array('name' => $strglossarys, 'link' => "index.php?id=$course->id", 'type' => 'activity');
32 $navigation = build_navigation($navlinks);
34 print_header_simple("$strglossarys", "", $navigation, "", "", true, "", navmenu($course));
36 /// Get all the appropriate data
38 if (! $glossarys = get_all_instances_in_course("glossary", $course)) {
39 notice("There are no glossaries", "../../course/view.php?id=$course->id");
40 die;
43 /// Print the list of instances (your module will probably extend this)
45 $timenow = time();
46 $strname = get_string("name");
47 $strweek = get_string("week");
48 $strtopic = get_string("topic");
49 $strentries = get_string("entries", "glossary");
51 if ($course->format == "weeks") {
52 $table->head = array ($strweek, $strname, $strentries);
53 $table->align = array ("CENTER", "LEFT", "CENTER");
54 } else if ($course->format == "topics") {
55 $table->head = array ($strtopic, $strname, $strentries);
56 $table->align = array ("CENTER", "LEFT", "CENTER");
57 } else {
58 $table->head = array ($strname, $strentries);
59 $table->align = array ("LEFT", "CENTER");
62 if ($show_rss = (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
63 $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds)) {
64 $table->head[] = $strrss;
65 $table->align[] = "CENTER";
68 $currentsection = "";
70 foreach ($glossarys as $glossary) {
71 if (!$glossary->visible && has_capability('moodle/course:viewhiddenactivities', $context)) {
72 // Show dimmed if the mod is hidden.
73 $link = "<a class=\"dimmed\" href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
74 } else if ($glossary->visible) {
75 // Show normal if the mod is visible.
76 $link = "<a href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
77 } else {
78 // Don't show the glossary.
79 continue;
81 $printsection = "";
82 if ($glossary->section !== $currentsection) {
83 if ($glossary->section) {
84 $printsection = $glossary->section;
86 if ($currentsection !== "") {
87 $table->data[] = 'hr';
89 $currentsection = $glossary->section;
92 $count = count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}glossary_entries where (glossaryid = $glossary->id or sourceglossaryid = $glossary->id)");
94 //If this glossary has RSS activated, calculate it
95 if ($show_rss) {
96 $rsslink = '';
97 if ($glossary->rsstype and $glossary->rssarticles) {
98 //Calculate the tolltip text
99 $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name));
100 if (empty($USER->id)) {
101 $userid = 0;
102 } else {
103 $userid = $USER->id;
105 //Get html code for RSS link
106 $rsslink = rss_get_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext);
110 if ($course->format == "weeks" or $course->format == "topics") {
111 $linedata = array ($printsection, $link, $count);
112 } else {
113 $linedata = array ($link, $count);
116 if ($show_rss) {
117 $linedata[] = $rsslink;
120 $table->data[] = $linedata;
123 echo "<br />";
125 print_table($table);
127 /// Finish the page
129 print_footer($course);