diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index <HASH>..<HASH> 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -1317,6 +1317,8 @@ function isteacher($courseid, $userid=0, $includeadmin=true) {
  * @todo Finish documenting this function
  */
 function isteacherinanycourse($userid = 0, $includeadmin = true) {
+    global $USER;
+
     if(empty($userid)) {
         if(empty($USER) || empty($USER->id)) {
             return false;
@@ -1324,6 +1326,10 @@ function isteacherinanycourse($userid = 0, $includeadmin = true) {
         $userid = $USER->id;
     }
 
+    if (isadmin($userid) && $includeadmin) {  // admins can do anything
+        return true;
+    }
+
     return record_exists('user_teachers', 'userid', $userid);
 }
Fixing my buggy implementation of isteacherinanycourse().
This fixes bugs <I>, <I> and maybe some others Eagle Eyes didn't have
the time to find. ;-)