Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / glossary / index.php
blob6b53b9e2669082fb956fc5f34a8f5e0c00d7fa8a
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");
9 require_once("$CFG->dirroot/course/lib.php");
11 $id = required_param('id', PARAM_INT); // course
13 if (! $course = get_record("course", "id", $id)) {
14 error("Course ID is incorrect");
17 require_course_login($course);
18 $context = get_context_instance(CONTEXT_COURSE, $course->id);
20 add_to_log($course->id, "glossary", "view all", "index.php?id=$course->id", "");
23 /// Get all required strings
25 $strglossarys = get_string("modulenameplural", "glossary");
26 $strglossary = get_string("modulename", "glossary");
27 $strrss = get_string("rss");
30 /// Print the header
31 $navlinks = array();
32 $navlinks[] = array('name' => $strglossarys, 'link' => "index.php?id=$course->id", 'type' => 'activity');
33 $navigation = build_navigation($navlinks);
35 print_header_simple("$strglossarys", "", $navigation, "", "", true, "", navmenu($course));
37 /// Get all the appropriate data
39 if (! $glossarys = get_all_instances_in_course("glossary", $course)) {
40 notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id=$course->id");
41 die;
44 /// Print the list of instances (your module will probably extend this)
46 $timenow = time();
47 $strname = get_string("name");
48 $strweek = get_string("week");
49 $strtopic = get_string("topic");
50 $strentries = get_string("entries", "glossary");
52 if ($course->format == "weeks") {
53 $table->head = array ($strweek, $strname, $strentries);
54 $table->align = array ("CENTER", "LEFT", "CENTER");
55 } else if ($course->format == "topics") {
56 $table->head = array ($strtopic, $strname, $strentries);
57 $table->align = array ("CENTER", "LEFT", "CENTER");
58 } else {
59 $table->head = array ($strname, $strentries);
60 $table->align = array ("LEFT", "CENTER");
63 if ($show_rss = (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
64 $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds)) {
65 $table->head[] = $strrss;
66 $table->align[] = "CENTER";
69 $currentsection = "";
71 foreach ($glossarys as $glossary) {
72 if (!$glossary->visible && has_capability('moodle/course:viewhiddenactivities', $context)) {
73 // Show dimmed if the mod is hidden.
74 $link = "<a class=\"dimmed\" href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
75 } else if ($glossary->visible) {
76 // Show normal if the mod is visible.
77 $link = "<a href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
78 } else {
79 // Don't show the glossary.
80 continue;
82 $printsection = "";
83 if ($glossary->section !== $currentsection) {
84 if ($glossary->section) {
85 $printsection = $glossary->section;
87 if ($currentsection !== "") {
88 $table->data[] = 'hr';
90 $currentsection = $glossary->section;
93 // TODO: count only approved if not allowed to see them
95 $count = count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}glossary_entries where (glossaryid = $glossary->id or sourceglossaryid = $glossary->id)");
97 //If this glossary has RSS activated, calculate it
98 if ($show_rss) {
99 $rsslink = '';
100 if ($glossary->rsstype and $glossary->rssarticles) {
101 //Calculate the tolltip text
102 $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name));
103 if (empty($USER->id)) {
104 $userid = 0;
105 } else {
106 $userid = $USER->id;
108 //Get html code for RSS link
109 $rsslink = rss_get_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext);
113 if ($course->format == "weeks" or $course->format == "topics") {
114 $linedata = array ($printsection, $link, $count);
115 } else {
116 $linedata = array ($link, $count);
119 if ($show_rss) {
120 $linedata[] = $rsslink;
123 $table->data[] = $linedata;
126 echo "<br />";
128 print_table($table);
130 /// Finish the page
132 print_footer($course);