### Eclipse Workspace Patch 1.0
#P 19stable
Index: blocks/glossary_random/block_glossary_random.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blocks/glossary_random/block_glossary_random.php,v
retrieving revision 1.20.6.6
diff -u -r1.20.6.6 block_glossary_random.php
--- blocks/glossary_random/block_glossary_random.php	27 Apr 2008 01:55:49 -0000	1.20.6.6
+++ blocks/glossary_random/block_glossary_random.php	19 Aug 2009 18:29:43 -0000
@@ -123,8 +123,8 @@
         }
 
         // select glossaries to put in dropdown box ...
-        $glossaries = get_records_select_menu('glossary', 'course='.$this->course->id,'name','id,name');
-
+        $glossaries = get_records_select_menu('glossary', 'globalglossary=1 OR course='.$this->course->id,'name','id,name');
+        
         //format menu texts to avoid html and to filter multilang values
         if(!empty($glossaries)) {
             foreach($glossaries as $key => $value) {
@@ -162,30 +162,31 @@
         }
 
         $glossaryid = $this->config->glossary;
-
-        if ($this->course->id == $COURSE->id) {
-            $course = $COURSE;
-        } else {
-            $course = get_record('course', 'id', $this->course->id); 
+        // lookup course info for the chosen glossary by glossary - do not assume it is the same course 
+        if ($glossaryid) {
+            $glossary = get_record('glossary','id',$glossaryid);
+            if ($glossary) {
+                $course = get_record('course','id',$glossary->course);
+            }
         }
-
+        
         require_once($CFG->dirroot.'/course/lib.php');
-        $modinfo = get_fast_modinfo($course);
-
-        if (!isset($modinfo->instances['glossary'][$glossaryid])) {
-            // we can get here if the glossary has been deleted, so
-            // unconfigure the glossary from the block..
-            $this->config->glossary = 0;
-            $this->config->cache = '';
-            $this->instance_config_commit();
-
-            $this->content->text   = get_string('notyetconfigured','block_glossary_random');
-            $this->content->footer = '';
-            return $this->content;
+        if (isset($course)) {
+            $modinfo = get_fast_modinfo($course);
+            if (!isset($modinfo->instances['glossary'][$glossaryid])) {
+                // we can get here if the glossary has been deleted, so
+                // unconfigure the glossary from the block..
+                $this->config->glossary = 0;
+                $this->config->cache = '';
+                $this->instance_config_commit();
+    
+                $this->content->text   = get_string('notyetconfigured','block_glossary_random');
+                $this->content->footer = '';
+                return $this->content;
+            }
+    
+            $cm = $modinfo->instances['glossary'][$glossaryid];
         }
-
-        $cm = $modinfo->instances['glossary'][$glossaryid];
-
         if (empty($this->config->cache)) {
             $this->config->cache = '';
         }
@@ -200,7 +201,7 @@
         // place link to glossary in the footer if the glossary is visible
 
         //Obtain the visible property from the instance
-        if ($cm->uservisible) {
+        if (isset($cm->uservisible) && $cm->uservisible) {
             if (has_capability('mod/glossary:write', get_context_instance(CONTEXT_MODULE, $cm->id))) {
                 $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/glossary/edit.php?id='.$cm->id
                 .'" title="'.$this->config->addentry.'">'.$this->config->addentry.'</a><br />';
@@ -215,8 +216,8 @@
         } else {
             $this->content->footer = $this->config->invisible;
         }
-
         return $this->content;
+        
     }
 
     function hide_header() {
