From c7a711278194419615997d3a1c535c378e3179e0 Mon Sep 17 00:00:00 2001
From: dongsheng <dongsheng>
Date: Thu, 20 Mar 2008 07:20:00 +0000
Subject: [PATCH] MDL-12263, under certain conditions, $catctxids is NULL, so
 an if statement should be here.

---
 lib/datalib.php | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/datalib.php b/lib/datalib.php
index 8492806c6d..4105429e83 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -685,7 +685,8 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a
             }
             $ctxids = array_unique($ctxids);
             $catctxids = implode( ',' , $ctxids);
-            unset($catpaths);unset($cpath);
+            unset($catpaths);
+            unset($cpath);
         } else {
             // take the ctx path from the first course
             // as all categories will be the same...
@@ -718,12 +719,17 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a
                   ON ra.roleid = r.id
                 LEFT OUTER JOIN {$CFG->prefix}course c
                   ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
-                WHERE (  c.id IS NOT NULL
-                         OR ra.contextid  IN ($catctxids) )
-                      AND ra.roleid IN ({$CFG->coursemanager})
+                WHERE ( c.id IS NOT NULL";
+        // under certain conditions, $catctxids is NULL
+        if($catctxids == NULL){
+            $sql .= ") ";
+        }else{
+            $sql .= " OR ra.contextid  IN ($catctxids) )";
+        }
+
+        $sql .= "AND ra.roleid IN ({$CFG->coursemanager})
                       $categoryclause
                 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
-
         $rs = get_recordset_sql($sql);
 
         // This loop is fairly stupid as it stands - might get better
-- 
2.39.5